CmpSyncKeyValues

CHAR __fastcall CmpSyncKeyValues(UINT64 a1, INT64 a2, INT64 a3, UINT64 a4, UINT64 a5, INT64 a6, CHAR a7){
  __int64 v7; 
  unsigned int v8; 
  int v9; 
  INT64 v12; 
  unsigned int v14; 
  UINT64 v15; 
  CHAR v16; 
  _CMHIVE *v17; 
  unsigned int v18; 
  UINT64 v19; 
  __int64 v20; 
  bool v21; 
  unsigned int v22; 
  __int64 v23; 
  int *v24; 
  __int64 v25; 
  __int64 v26; 
  unsigned int v27; 
  unsigned int v28; 
  unsigned int *v29; 
  unsigned int v30; 
  __int64 v31; 
  unsigned int P3; 
  unsigned int P3a; 
  unsigned int P3_4; 
  _DWORD v35[2]; 
  int v36[2]; 
  int v37[2]; 
  int v38[2]; 
  int v39[2]; 
  int v40[2]; 
  __int64 v41; 
  __int64 v42; 
  __int64 v43; 
  unsigned int v45; 
  v7 = a1;
  v39[1] = 0;
  v39[0] = -1;
  v8 = -1;
  v38[0] = -1;
  v9 = -1;
  P3_4 = -1;
  v40[0] = -1;
  a7 = 0;
  v38[1] = 0;
  v45 = 0;
  v40[1] = 0;
  CmpLockTwoSecurityCachesExclusiveShared(a4, a1);
  v12 = a6;
  if( !CmpFreeKeyValues(a4, (unsigned int)a5, a6) )
  {
    CmpUnlockTwoSecurityCaches((_CMHIVE *)a4, (_CMHIVE *)v7);
    return 0;
  }
  v14 = (unsigned int)a5 >> 31;
  if( !*(_WORD *)(a3 + 74) || (v15 = *(unsigned int *)(a3 + 48), (_DWORD)v15 == -1) )
  {
LABEL_8:
    *(_DWORD *)(v12 + 48) = v9;
    if( !CmpFindSecurityCellCacheIndex(v7, *(_DWORD *)(a3 + 44), &v45) )
    {
LABEL_9:
      v17 = (_CMHIVE *)a4;
LABEL_10:
      CmpUnlockTwoSecurityCaches(v17, (_CMHIVE *)v7);
      v16 = a7;
      goto LABEL_46;
    }
    v18 = *(_DWORD *)(v12 + 44);
    v19 = (unsigned int)a5;
    v20 = *(_QWORD *)(*(_QWORD *)(v7 + 1880) + 16i64 * v45 + 8);
    *(_DWORD *)(v12 + 44) = -1;
    if( (int)CmpAssignSecurityDescriptor(a4, v19, v12, (VOID *)(v20 + 32), 0) < 0 )
    {
      *(_DWORD *)(v12 + 44) = v18;
      goto LABEL_9;
    }
    v21 = (*(_BYTE *)(v12 + 2) & 4) == 0;
    v22 = *(_DWORD *)(v12 + 44);
    v45 = v22;
    *(_DWORD *)(v12 + 44) = v18;
    if( v21 || v22 == v18 )
    {
      v27 = v22;
    }
    else
    {
      v35[0] = -1;
      v36[0] = -1;
      v37[0] = -1;
      v35[1] = 0;
      v36[1] = 0;
      v37[1] = 0;
      v41 = (*(__int64(__fastcall **)(UINT64, _QWORD, _DWORD *))(a4 + 8))(a4, v22, v35);
      v17 = (_CMHIVE *)a4;
      if( !v41 )
        goto LABEL_10;
      v23 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, v18, v36);
      v42 = v23;
      if( !v23 )
      {
        v24 = v35;
LABEL_18:
        (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v24);
        goto LABEL_9;
      }
      P3 = *(_DWORD *)(v23 + 8);
      v43 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, P3, v37);
      if( !v43 )
      {
        (*(void(__fastcall **)(UINT64, _DWORD *))(a4 + 16))(a4, v35);
        v24 = v36;
        goto LABEL_18;
      }
      if( !HvMarkCellDirty(a4, v18, 0) || !HvMarkCellDirty(a4, P3, 0) )
      {
        (*(void(__fastcall **)(UINT64, _DWORD *))(a4 + 16))(a4, v35);
        (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v36);
        v24 = v37;
        goto LABEL_18;
      }
      v25 = v41;
      *(_DWORD *)(v41 + 8) = P3;
      v26 = v42;
      *(_DWORD *)(v25 + 4) = v18;
      v27 = v45;
      *(_DWORD *)(v26 + 8) = v45;
      *(_DWORD *)(v43 + 4) = v27;
      (*(void(__fastcall **)(UINT64, _DWORD *))(a4 + 16))(a4, v35);
      (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v36);
      (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v37);
    }
    CmpFreeSecurityDescriptor(a4, (unsigned int)a5);
    *(_DWORD *)(v12 + 44) = v27;
    CmpUnlockTwoSecurityCaches((_CMHIVE *)a4, (_CMHIVE *)v7);
    v28 = *(_DWORD *)(a3 + 36);
    *(_DWORD *)(v12 + 40) = -1;
    *(_DWORD *)(v12 + 36) = 0;
    *(_DWORD *)(v12 + 60) = *(_DWORD *)(a3 + 60);
    *(_DWORD *)(v12 + 64) = *(_DWORD *)(a3 + 64);
    v45 = v28;
    if( !v28 )
      return 1;
    v29 = (unsigned int *)(*(__int64(__fastcall **)(__int64, _QWORD, int *))(v7 + 8))(
                            v7,
                            *(unsigned int *)(a3 + 40),
                            v39);
    if( v29 )
    {
      v30 = 0;
      if( v45 )
      {
        while( 1 )
        {
          P3a = CmpCopyValue(v7, *v29, a4, v14);
          if( P3a == -1 || !(*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, P3a, v40) )
          {
            v8 = *(_DWORD *)(v12 + 40);
            goto LABEL_35;
          }
          if( (int)CmpAddValueToList(a4, P3a, v30, v14, (UINT64 *)(v12 + 36)) < 0 )
            break;
          ++v30;
          ++v29;
          if( v30 >= v45 )
            goto LABEL_34;
        }
        v8 = *(_DWORD *)(v12 + 40);
        if( v8 != -1 )
        {
          v31 = (*(__int64(__fastcall **)(UINT64, _QWORD, int *))(a4 + 8))(a4, v8, v38);
          if( v31 )
          {
            if( v30 )
            {
              do
                HvFreeCell(a4, *(unsigned int *)(v31 + 4i64 * --v30));
              while( v30 );
              v7 = a1;
            }
            (*(void(__fastcall **)(UINT64, int *))(a4 + 16))(a4, v38);
          }
        }
      }
      else
      {
LABEL_34:
        a7 = 1;
      }
LABEL_35:
      (*(void(__fastcall **)(__int64, int *))(v7 + 16))(v7, v39);
      v16 = a7;
      if( a7 )
        return v16;
      if( v8 != -1 )
        HvFreeCell(a4, v8);
    }
    else
    {
      v16 = 0;
    }
LABEL_46:
    if( P3_4 != -1 )
      HvFreeCell(a4, P3_4);
    return v16;
  }
  P3_4 = CmpCopyCell((_HHIVE *)v7, v15, (_HHIVE *)a4, (HSTORAGE_TYPE)v14);
  if( P3_4 != -1 )
  {
    v9 = P3_4;
    *(_WORD *)(v12 + 74) = *(_WORD *)(a3 + 74);
    goto LABEL_8;
  }
  CmpUnlockTwoSecurityCaches((_CMHIVE *)a4, (_CMHIVE *)v7);
  return a7;
}

Referenced by:

CmpCopySyncTree2
CmpMergeKeyValues