CmpSetValueKeyExisting

__int64 __fastcall CmpSetValueKeyExisting(
        __int64 Hive,
        void *a2,
        __int64 a3,
        int a4,
        VOID *Src,
        size_t Size,
        _HSTORAGE_TYPE Type){
  __int16 v7; 
  int v9; 
  unsigned int v11; 
  unsigned int v12; 
  __int16 v13; 
  unsigned int Cell; 
  __int64 v15; 
  VOID *v16; 
  int v17; 
  int v19; 
  __int16 v20; 
  _HV_GET_CELL_CONTEXT CellAddressContext; 
  int v22; 
  VOID *CellAddress[2]; 

  *(_DWORD *)&CellAddressContext.BinContext._bf_0 = -1;
  v7 = 0;
  CellAddress[0] = 0i64;
  CellAddressContext.Cell = 0;
  v22 = 0;
  v9 = 0;
  if( !HvMarkCellDirty((PVOID)Hive, a2, 0) )
    return 3221225853i64;
  v11 = *(_DWORD *)(a3 + 4);
  v12 = v11 + 0x80000000;
  if( v11 < 0x80000000 )
    v12 = *(_DWORD *)(a3 + 4);
  if( v11 >= 0x80000000 )
  {
    v13 = 0;
  }
  else if( *(_DWORD *)(Hive + 212) >= 4u && v12 - 16345 <= 0x7FFFC026 )
  {
    v13 = 2;
  }
  else
  {
    v13 = 1;
  }
  if( Size <= 4 )
    goto LABEL_12;
  if( *(_DWORD *)(Hive + 212) < 4u || Size - 16345 > 0x7FFFC026 )
  {
    v7 = 1;
LABEL_12:
    v20 = v7;
    goto LABEL_13;
  }
  v7 = 2;
  v20 = 2;
LABEL_13:
  if( !CmpMarkValueDataDirty((PVOID)Hive, a3) )
    return 3221225853i64;
  if( v7 )
  {
    Cell = *(_DWORD *)(a3 + 8);
    if( v20 != 1 )
    {
      if( v20 != 2 )
        return(unsigned int)v9;
      if( v13 == 2 )
      {
        v9 = CmpSetValueDataExisting((_HHIVE *)Hive, Src, Size, Type, *(_DWORD *)(a3 + 8));
        if( v9 < 0 )
          return(unsigned int)v9;
      }
      else
      {
        v9 = CmpSetValueDataNew(Hive, Src, Size, Type, (__int64)&CellAddressContext);
        if( v9 < 0 )
          return(unsigned int)v9;
        if( v13 && v12 )
          HvFreeCell(Hive, *(_DWORD *)(a3 + 8));
        Cell = CellAddressContext.Cell;
      }
      *(_DWORD *)(a3 + 12) = a4;
      *(_WORD *)(a3 + 16) &= ~2u;
      *(_DWORD *)(a3 + 4) = Size;
      *(_DWORD *)(a3 + 8) = Cell;
      return 0;
    }
    if( v13 == 1 && v12 )
    {
      v15 = (*(__int64(__fastcall **)(__int64, _QWORD, _HV_GET_BIN_CONTEXT *))(Hive + 8))(
              Hive,
              Cell,
              &CellAddressContext.BinContext);
      v16 = (VOID *)v15;
      if( v15 )
      {
        if( Size <= -4 - *(_DWORD *)(v15 - 4) )
        {
          v17 = Cell;
          goto LABEL_21;
        }
        (*(void(__fastcall **)(__int64, _HV_GET_BIN_CONTEXT *))(Hive + 16))(Hive, &CellAddressContext.BinContext);
        CellAddress[0] = 0i64;
        v19 = HvReallocateCell(
                (PVOID)Hive,
                (PVOID)Cell,
                Size,
                1u,
                CellAddress,
                (_HV_GET_CELL_CONTEXT *)&CellAddressContext.BinContext);
        v17 = v19;
        if( v19 != -1 )
        {
          *(_DWORD *)(a3 + 8) = v19;
LABEL_31:
          v16 = CellAddress[0];
LABEL_21:
          memmove(v16, Src, Size);
          (*(void(__fastcall **)(__int64, _HV_GET_BIN_CONTEXT *))(Hive + 16))(Hive, &CellAddressContext.BinContext);
          *(_DWORD *)(a3 + 12) = a4;
          *(_WORD *)(a3 + 16) &= ~2u;
          *(_DWORD *)(a3 + 8) = v17;
          *(_DWORD *)(a3 + 4) = Size;
          if( v13 == 2 )
            CmpFreeValueData(Hive, Cell, v12);
          return 0;
        }
      }
    }
    else
    {
      v17 = HvAllocateCell(Hive, Size, Type, CellAddress, (_HV_GET_CELL_CONTEXT *)&CellAddressContext.BinContext);
      if( v17 != -1 )
        goto LABEL_31;
    }
    return(unsigned int)-1073741670;
  }
  if( v13 == 1 && v12 || v13 == 2 )
    CmpFreeValueData(Hive, *(unsigned int *)(a3 + 8), v12);
  *(_DWORD *)(a3 + 8) = 0;
  *(_DWORD *)(a3 + 4) = Size + 0x80000000;
  memmove((VOID *)(a3 + 8), Src, Size);
  *(_DWORD *)(a3 + 12) = a4;
  *(_WORD *)(a3 + 16) &= ~2u;
  return 0i64;
}

Referenced by:

CmSetValueKey
CmpCommitSetValueKeyUoW
CmpPreserveSystemHiveData