CmpLightWeightPrepareAddKeyUoW

INT64 __stdcall CmpLightWeightPrepareAddKeyUoW(PCM_KCB_UOW UoW){
  unsigned int v2; 
  _CM_KEY_CONTROL_BLOCK *KeyControlBlock; 
  HSTORAGE_TYPE StorageType; 
  VOID *v5; 
  UINT64 KeyHive; 
  _CM_KCB_UOW *ParentUoW; 
  _CM_UOW_KEY_STATE_MODIFICATION *ModifyKeysData; 
  int v9; 
  unsigned int v10; 
  _CM_KEY_CONTROL_BLOCK *ParentKcb; 
  __int64(__fastcall *v12)(UINT64, _QWORD, int *); 
  unsigned int *v13; 
  unsigned int v14; 
  unsigned int v15; 
  _WORD *v16; 
  unsigned int v17; 
  _CM_KEY_CONTROL_BLOCK *v18; 
  CHAR v20; 
  UINT64 v21; 
  int v22[2]; 
  _CM_KEY_CONTROL_BLOCK *v23; 
  _HSTORAGE_TYPE Type; 
  _HV_GET_CELL_CONTEXT CellAddressContext; 
  _CM_UOW_KEY_STATE_MODIFICATION *Data; 
  VOID *CellAddress; 

  v22[1] = 0;
  *(_DWORD *)&CellAddressContext.BinContext._bf_0 = 0;
  v2 = -1;
  v22[0] = -1;
  KeyControlBlock = UoW->KeyControlBlock;
  StorageType = UoW->StorageType;
  CellAddressContext.Cell = -1;
  Type = StorageType;
  v5 = 0i64;
  KeyHive = (UINT64)KeyControlBlock->KeyHash.KeyHive;
  ParentUoW = UoW->ParentUoW;
  CellAddress = 0i64;
  ModifyKeysData = ParentUoW->ModifyKeysData;
  Data = ModifyKeysData;
  if( ModifyKeysData )
  {
    ++ModifyKeysData->RefCount;
  }
  else
  {
    v9 = CmpLightWeightCreateModificationData(UoW, &Data);
    ModifyKeysData = Data;
    v10 = v9;
    if( v9 < 0 )
      goto LABEL_23;
    StorageType = Type;
  }
  ParentKcb = UoW->KeyControlBlock->ParentKcb;
  v12 = *(__int64(__fastcall **)(UINT64, _QWORD, int *))(KeyHive + 8);
  v23 = ParentKcb;
  Data = (_CM_UOW_KEY_STATE_MODIFICATION *)v12(KeyHive, ParentKcb->KeyHash.KeyCell, v22);
  if( !Data )
  {
    v10 = -1073741670;
    goto LABEL_23;
  }
  if( !HvMarkCellDirty((PVOID)KeyHive, (PVOID)UoW->KeyControlBlock->KeyHash.KeyCell, 1u)
    || !HvMarkCellDirty((PVOID)KeyHive, (PVOID)ParentKcb->KeyHash.KeyCell, 1u)
    || !HvMarkCellDirty((PVOID)KeyHive, (PVOID)Data[1].SubKeyListCount[StorageType + 1], 1u) )
  {
    v10 = -1073741443;
    goto LABEL_19;
  }
  v13 = &ModifyKeysData->RefCount + (int)StorageType;
  if( v13[3] != -1 )
  {
LABEL_14:
    LODWORD(v21) = Type;
    v17 = CmpCopyKeyPartial(KeyHive, UoW->KeyControlBlock->KeyHash.KeyCell, KeyHive, v23->KeyHash.KeyCell, 38, v20, v21);
    v2 = v17;
    if( v17 == -1 || !CmpAddSubKeyToList(KeyHive, (UINT64 *)(v13 + 3), v17) )
    {
      v10 = -1073741670;
    }
    else
    {
      ++ModifyKeysData->SubKeyListCount[StorageType];
      v10 = 0;
      v18 = UoW->KeyControlBlock;
      UoW->VolatileKeyCell = v18->KeyHash.KeyCell;
      v18->KeyHash.KeyCell = v2;
      v2 = -1;
      UoW->PrepareDataPointer = ModifyKeysData;
      ModifyKeysData = 0i64;
    }
    goto LABEL_19;
  }
  v14 = *(_DWORD *)(KeyHive + 212);
  v15 = HvAllocateCell(KeyHive, 0xCui64, Type, &CellAddress, &CellAddressContext);
  if( v15 != -1 )
  {
    v16 = CellAddress;
    *(_WORD *)CellAddress = v14 < 5 ? 26220 : 26732;
    v16[1] = 0;
    v13[3] = v15;
    ModifyKeysData->SubKeyListCount[StorageType] = 0;
    (*(void(__fastcall **)(UINT64, _HV_GET_CELL_CONTEXT *))(KeyHive + 16))(KeyHive, &CellAddressContext);
    v5 = 0i64;
    goto LABEL_14;
  }
  v5 = CellAddress;
  v10 = -1073741670;
LABEL_19:
  (*(void(__fastcall **)(UINT64, int *))(KeyHive + 16))(KeyHive, v22);
  if( v5 )
    (*(void(__fastcall **)(UINT64, _HV_GET_CELL_CONTEXT *))(KeyHive + 16))(KeyHive, &CellAddressContext);
  if( v2 != -1 )
    CmpFreeKeyByCell(KeyHive, v2, 0);
LABEL_23:
  if( ModifyKeysData )
  {
    CmpLightWeightCleanupModifyKeyDataUoW(KeyHive, (UINT64 *)&ModifyKeysData->RefCount);
    UoW->PrepareDataPointer = 0i64;
  }
  return v10;
}

Referenced by:

CmpProcessLightWeightUOW