CmpCopyKeyPartial

INT64 __fastcall CmpCopyKeyPartial(UINT64 a1, INT64 a2, UINT64 a3, UINT64 a4, INT16 a5, CHAR a6, UINT64 a7){
  unsigned int v7; 
  int v10; 
  ULONG_PTR v11; 
  INT64 v12; 
  __int64 v13; 
  __int64 v14; 
  int v15; 
  int v16; 
  char v17; 
  __int16 v18; 
  ULONG_PTR v19; 
  int v20; 
  unsigned int v21; 
  char v22; 
  unsigned int *v24; 
  unsigned int v25; 
  unsigned int v26; 
  __int64 v27; 
  INT64 v28; 
  unsigned int v29; 
  unsigned int v30; 
  int v31; 
  UINT64 Index; 
  INT64 v33; 
  int v34[2]; 
  int v35[2]; 
  int v36[2]; 
  int v37[2]; 
  int v38[2]; 
  unsigned int *v39; 
  __int64 v40; 
  ULONG_PTR Cell; 
  unsigned int v42; 
  ULONG_PTR v43; 

  v42 = a2;
  v7 = a7;
  v36[1] = 0;
  v37[1] = 0;
  Cell = -1;
  v36[0] = -1;
  v10 = a4;
  LODWORD(Index) = 0;
  v11 = -1;
  v37[0] = -1;
  v12 = 0i64;
  v39 = 0i64;
  v38[0] = -1;
  v38[1] = 0;
  v35[0] = -1;
  v35[1] = 0;
  v34[0] = -1;
  v34[1] = 0;
  if( (_DWORD)a7 == 2 )
  {
    if( (_DWORD)a4 == -1 )
      v7 = 0;
    else
      v7 = (unsigned int)a4 >> 31;
  }
  v13 = (*(__int64(__fastcall **)(UINT64, INT64, int *))(a1 + 8))(a1, a2, v36);
  v40 = v13;
  v14 = v13;
  if( !v13 )
    return 0xFFFFFFFFi64;
  v15 = *(unsigned __int16 *)(v13 + 74);
  v29 = *(_DWORD *)(v13 + 44);
  v16 = *(_DWORD *)(v13 + 48);
  if( (a5 & 2) == 0 )
    v16 = -1;
  LODWORD(v33) = v16;
  v31 = (a5 & 2) != 0 ? v15 : 0;
  v43 = CmpCopyCell(a1, v42, a3, v7);
  if( v43 == -1 )
  {
    v19 = -1;
    goto LABEL_56;
  }
  if( v31 )
  {
    Cell = CmpCopyCell(a1, (unsigned int)v33, a3, v7);
    if( Cell == -1 )
    {
      v19 = v43;
LABEL_56:
      v22 = 0;
      goto LABEL_24;
    }
  }
  v12 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a3 + 8))(a3, v43, v37);
  if( !v12 )
    goto LABEL_39;
  *(_DWORD *)(v12 + 20) = 0;
  *(_DWORD *)(v12 + 24) = 0;
  v17 = a5;
  *(_DWORD *)(v12 + 48) = Cell;
  *(_WORD *)(v12 + 74) = v31;
  *(_DWORD *)(v12 + 44) = -1;
  *(_DWORD *)(v12 + 28) = -1;
  *(_DWORD *)(v12 + 32) = -1;
  *(_DWORD *)(v12 + 16) = v10;
  *(_BYTE *)(v12 + 12) = 0;
  if( (a5 & 0x100) != 0 )
    *(_BYTE *)(v12 + 13) &= 0xFCu;
  if( (a5 & 0x80u) != 0 )
    *(_BYTE *)(v12 + 13) |= 0x80u;
  v18 = *(_WORD *)(v14 + 2) & 0x30;
  *(_WORD *)(v12 + 2) = v18;
  if( (a5 & 0x20) != 0 )
  {
    v18 = *(_WORD *)(v14 + 2) & 0xFFBF;
    *(_WORD *)(v12 + 2) = v18;
  }
  if( v10 == -1 )
    *(_WORD *)(v12 + 2) = v18 | 0xC;
  if( (a5 & 0x10) != 0 )
    goto LABEL_20;
  CmpLockTwoSecurityCachesExclusiveShared((_CMHIVE *)a3, (_CMHIVE *)a1);
  if( !CmpFindSecurityCellCacheIndex((CMHIVE *)a1, v29, &Index) )
  {
    CmpUnlockTwoSecurityCaches((_CMHIVE *)a3, (_CMHIVE *)a1);
LABEL_39:
    v19 = v43;
    goto LABEL_31;
  }
  v19 = v43;
  v20 = CmpAssignSecurityDescriptor(
          a3,
          v43,
          v12,
          (VOID *)(*(_QWORD *)(*(_QWORD *)(a1 + 1880) + 16i64 * (unsigned int)Index + 8) + 32i64),
          0);
  CmpUnlockTwoSecurityCaches((_CMHIVE *)a3, (_CMHIVE *)a1);
  if( v20 < 0 )
  {
LABEL_31:
    v22 = 0;
    goto LABEL_24;
  }
  v14 = v40;
  v17 = a5;
LABEL_20:
  if( (*(_BYTE *)(v14 + 2) & 0x40) != 0 )
    v21 = 0;
  else
    v21 = *(_DWORD *)(v14 + 36);
  *(_DWORD *)(v12 + 36) = 0;
  *(_DWORD *)(v12 + 40) = -1;
  if( v21 && (v17 & 4) != 0 )
  {
    v24 = (unsigned int *)(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a1 + 8))(
                            a1,
                            *(unsigned int *)(v14 + 40),
                            v38);
    v39 = v24;
    if( v24 )
    {
      v25 = 0;
      v33 = (INT64)v24;
      while( 1 )
      {
        v26 = CmpCopyValue(a1, *v24, a3, v7);
        v30 = v26;
        if( v26 == -1 || !(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a3 + 8))(a3, v26, v34) )
        {
          v11 = *(_DWORD *)(v12 + 40);
          goto LABEL_39;
        }
        (*(void(__fastcall **)(UINT64, int *))(a3 + 16))(a3, v34);
        LODWORD(v28) = v21;
        if( (int)CmpAddValueToListEx(a3, v30, v25, v7, (UINT64 *)(v12 + 36), v28) < 0 )
          break;
        ++v25;
        v24 = (unsigned int *)(v33 + 4);
        v33 += 4i64;
        if( v25 >= v21 )
          goto LABEL_23;
      }
      v11 = *(_DWORD *)(v12 + 40);
      if( v11 == -1 )
      {
        v19 = v43;
        v22 = 0;
        goto LABEL_24;
      }
      v27 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a3 + 8))(a3, v11, v35);
      if( v27 )
      {
        while( v25 )
          HvFreeCell(a3, *(_DWORD *)(v27 + 4i64 * --v25));
        (*(void(__fastcall **)(UINT64, int *))(a3 + 16))(a3, v35);
      }
    }
    goto LABEL_39;
  }
LABEL_23:
  v19 = v43;
  v22 = 1;
LABEL_24:
  (*(void(__fastcall **)(UINT64, int *))(a1 + 16))(a1, v36);
  if( v12 )
    (*(void(__fastcall **)(UINT64, int *))(a3 + 16))(a3, v37);
  if( v39 )
    (*(void(__fastcall **)(UINT64, int *))(a1 + 16))(a1, v38);
  if( v22 )
    return v19;
  if( v11 != -1 )
    HvFreeCell(a3, v11);
  if( Cell != -1 )
    HvFreeCell(a3, Cell);
  if( v19 != -1 )
    HvFreeCell(a3, v19);
  return 0xFFFFFFFFi64;
}

Referenced by:

CmRestoreKey
CmSaveMergedKeys
CmpCommitAddKeyUoW
CmpCopySyncTree2
CmpLightWeightPrepareAddKeyUoW
CmpLoadHiveVolatile
CmpReorganizeHive