CmpAddSubKeyEx

CHAR __fastcall CmpAddSubKeyEx(UINT64 a1, INT64 a2, UINT64 a3, UINT64 a4){
  unsigned int v5; 
  __int64(__fastcall *v6)(UINT64, INT64, int *); 
  unsigned int v7; 
  unsigned int v8; 
  int v9; 
  __int64 v10; 
  CHAR v11; 
  __int64 v12; 
  __int64 v13; 
  int v14; 
  unsigned int v15; 
  __int16 v16; 
  unsigned int v17; 
  unsigned int v18; 
  _DWORD *v19; 
  _WORD *v20; 
  unsigned int i; 
  __int64 v22; 
  unsigned int v23; 
  int v24; 
  UINT64 Type; 
  VOID *CellAddress; 
  _HV_GET_CELL_CONTEXT CellAddressContext; 
  int v29[2]; 
  int v30; 
  unsigned int v31; 
  v31 = a3;
  v29[1] = 0;
  v29[0] = -1;
  v5 = a3;
  CellAddressContext.Cell = -1;
  *(_DWORD *)&CellAddressContext.BinContext = 0;
  v6 = *(__int64(__fastcall **)(UINT64, INT64, int *))(a1 + 8);
  v7 = -1;
  CellAddress = 0i64;
  v8 = a4;
  v30 = 0;
  v9 = 0;
  v10 = v6(a1, a2, v29);
  if( !v10 )
    return 0;
  v12 = v5 >> 31;
  LODWORD(Type) = v5 >> 31;
  v13 = v12;
  if( *(_DWORD *)(v10 + 4 * v12 + 20) )
  {
    v20 = (_WORD *)(*(__int64(__fastcall **)(UINT64, _QWORD, _HV_GET_CELL_CONTEXT *))(a1 + 8))(
                     a1,
                     *(unsigned int *)(v10 + 4 * v12 + 28),
                     &CellAddressContext);
    v19 = v20;
    if( !v20 )
    {
LABEL_15:
      v11 = 0;
      goto LABEL_32;
    }
    v11 = 1;
    if( *v20 == 26220 && v20[1] >= 0x1FBu )
    {
      if( !HvMarkCellDirty(a1, *(unsigned int *)(v10 + 4 * v13 + 28), 0) )
        goto LABEL_15;
      for( i = 0; i < *((unsigned __int16 *)v19 + 1); v19[v22 + 1] = v19[2 * v22 + 1] )
        v22 = i++;
      *(_WORD *)v19 = 26988;
    }
    if( ((*(_WORD *)v19 - 26732) & 0xFEFF) != 0 || *((_WORD *)v19 + 1) < 0x3F5u )
    {
      v9 = 0;
    }
    else
    {
      (*(void(__fastcall **)(UINT64, _HV_GET_CELL_CONTEXT *, _QWORD))(a1 + 16))(a1, &CellAddressContext, 0i64);
      v9 = 0;
      CellAddress = 0i64;
      v23 = HvAllocateCell((_HHIVE *)a1, 0xCui64, (HSTORAGE_TYPE)Type, &CellAddress, &CellAddressContext);
      v19 = CellAddress;
      v7 = v23;
      if( v23 == -1 )
      {
        v11 = 0;
        goto LABEL_32;
      }
      *(_DWORD *)CellAddress = 92530;
      v19[1] = *(_DWORD *)(v10 + 4 * v13 + 28);
      *(_DWORD *)(v10 + 4 * v13 + 28) = v23;
    }
    v18 = *(_DWORD *)(v10 + 4 * v13 + 28);
    v7 = -1;
LABEL_29:
    LODWORD(Type) = v18;
    if( CmpAddSubKeyToList(a1, &Type, v31) )
    {
      v24 = Type;
      ++*(_DWORD *)(v10 + 4 * v13 + 20);
      *(_DWORD *)(v10 + 4 * v13 + 28) = v24;
    }
    else
    {
      v11 = 0;
      v9 = v30;
    }
    goto LABEL_32;
  }
  v11 = 1;
  if( *(_DWORD *)(a1 + 212) < 5u )
  {
    v17 = 12;
    v16 = 26220;
  }
  else
  {
    v14 = 1012;
    v15 = 1;
    v16 = 26732;
    if( v8 )
      v15 = v8;
    if( v15 < 0x3F4 )
      v14 = v15;
    v17 = 8 * v14 + 4;
  }
  v18 = HvAllocateCell((_HHIVE *)a1, v17, (HSTORAGE_TYPE)v12, &CellAddress, &CellAddressContext);
  v19 = CellAddress;
  v7 = v18;
  if( v18 != -1 )
  {
    *(_WORD *)CellAddress = v16;
    v9 = 0;
    *((_WORD *)v19 + 1) = 0;
    v30 = 1;
    goto LABEL_29;
  }
  v11 = 0;
  v9 = 0;
LABEL_32:
  (*(void(__fastcall **)(UINT64, int *))(a1 + 16))(a1, v29);
  if( v19 )
    (*(void(__fastcall **)(UINT64, _HV_GET_CELL_CONTEXT *))(a1 + 16))(a1, &CellAddressContext);
  if( v9 )
    HvFreeCell(a1, v7);
  return v11;
}

Referenced by:

CmpAddSubKey
CmpCopySyncTree2
CmpPartialPromoteSingleKeyFromKeyNodeStacks