CmpSplitLeaf

__int64 __fastcall CmpSplitLeaf(__int64 Hive, __int64 Cell, unsigned int a3, _HSTORAGE_TYPE a4){
  VOID *v4; 
  ULONG_PTR v5; 
  __int64(__fastcall *v7)(__int64, __int64, _HV_GET_CELL_CONTEXT *); 
  __int64 v8; 
  _WORD *v9; 
  __int64 v10; 
  _WORD *v11; 
  unsigned __int16 v12; 
  unsigned __int16 v13; 
  unsigned __int16 v14; 
  char *v15; 
  int v16; 
  int v17; 
  ULONG_PTR v18; 
  _WORD *v19; 
  _WORD *v20; 
  int v21; 
  unsigned int CellIndex; 
  ULONG_PTR CellIndexa; 
  VOID *CellAddress; 
  _HV_GET_CELL_CONTEXT v26; 
  _HV_GET_CELL_CONTEXT CellAddressContext; 
  VOID *v28; 
  int v29[2]; 
  __int64 v30; 
  unsigned __int16 v31; 

  v26.Cell = -1;
  v29[0] = -1;
  v4 = 0i64;
  CellAddressContext.Cell = -1;
  v5 = Cell;
  *(_DWORD *)&v26.BinContext._bf_0 = 0;
  v29[1] = 0;
  *(_DWORD *)&CellAddressContext.BinContext._bf_0 = 0;
  v7 = *(__int64(__fastcall **)(__int64, __int64, _HV_GET_CELL_CONTEXT *))(Hive + 8);
  v8 = a3;
  CellAddress = 0i64;
  v9 = (_WORD *)v7(Hive, Cell, &v26);
  if( !v9 )
    return 0xFFFFFFFFi64;
  if( v9[1] == 0xFFFF
    || (CellIndex = *(_DWORD *)&v9[2 * v8 + 2],
        v10 = (*(__int64(__fastcall **)(__int64, _QWORD, int *))(Hive + 8))(Hive, CellIndex, v29),
        (v11 = (_WORD *)v10) == 0i64) )
  {
LABEL_24:
    if( v9 )
      (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &v26);
    return 0xFFFFFFFFi64;
  }
  v12 = *(_WORD *)(v10 + 2);
  v13 = v12 >> 1;
  v14 = v12 - (v12 >> 1);
  v31 = v13;
  if( ((*v11 - 26220) & 0xFDFF) != 0 )
  {
    LODWORD(v28) = 4;
    v30 = 4i64;
  }
  else
  {
    v28 = (VOID *)8;
    v30 = 8i64;
  }
  if( !HvMarkCellDirty((PVOID)Hive, (PVOID)CellIndex, 0) )
  {
LABEL_22:
    (*(void(__fastcall **)(__int64, int *))(Hive + 16))(Hive, v29);
    if( v4 )
      (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &CellAddressContext);
    goto LABEL_24;
  }
  CellIndexa = HvAllocateCell(Hive, (unsigned int)v28 * v14 + 5, a4, &CellAddress, &CellAddressContext);
  if( CellIndexa == -1 )
  {
    v4 = CellAddress;
    goto LABEL_22;
  }
  v15 = (char *)CellAddress;
  *(_WORD *)CellAddress = *v11;
  v16 = *((_DWORD *)v9 - 1);
  if( ((-8 - 4 * (unsigned __int16)v9[1] - v16) & 0xFFFFFFFC) < 4 )
  {
    v17 = -4 - v16;
    (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &v26);
    v28 = 0i64;
    v18 = HvReallocateCell((PVOID)Hive, (PVOID)v5, (unsigned int)(v17 + 4), 0, &v28, &v26);
    if( v18 == -1 )
    {
      (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &CellAddressContext);
      v4 = 0i64;
      HvFreeCell(Hive, CellIndexa);
      v9 = v28;
      goto LABEL_22;
    }
    if( v5 != v18 )
    {
      HvFreeCell(Hive, v5);
      v5 = v18;
    }
    v15 = (char *)CellAddress;
    v9 = v28;
  }
  if( ((*v11 - 26220) & 0xFDFF) != 0 )
    v19 = &v11[2 * v31 + 2];
  else
    v19 = &v11[4 * v31 + 2];
  memmove(v15 + 4, v19, v30 * v14);
  v20 = CellAddress;
  v11[1] = v31;
  v20[1] = v14;
  (*(void(__fastcall **)(__int64, int *))(Hive + 16))(Hive, v29);
  (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &CellAddressContext);
  v21 = (unsigned __int16)v9[1];
  if( (unsigned int)v8 < v21 - 1 )
  {
    memmove(&v9[2 * (unsigned int)(v8 + 2) + 2], &v9[2 * (unsigned int)(v8 + 1) + 2], 4 * (v21 - v8 - 1));
    LOWORD(v21) = v9[1];
  }
  v9[1] = v21 + 1;
  *(_DWORD *)&v9[2 * (unsigned int)(v8 + 1) + 2] = CellIndexa;
  (*(void(__fastcall **)(__int64, _HV_GET_CELL_CONTEXT *))(Hive + 16))(Hive, &v26);
  return v5;
}

Referenced by:

CmpSelectLeaf