CmpAddSecurityCellToCache

NTSTATUS __stdcall CmpAddSecurityCellToCache(
        _CMHIVE *CmHive,
        UINT64 SecurityCell,
        UINT8 BuildUp,
        _CM_KEY_SECURITY_CACHE *SecurityCached){
  unsigned int v5; 
  int v7; 
  __int64 v8; 
  __int64 v9; 
  __int64 v10; 
  __int64 v11; 
  __int64 v12; 
  int v13; 
  int v14; 
  __int64 v15; 
  char *v16; 
  char *v17; 
  char **v18; 
  __int64 v19; 
  unsigned int v20; 
  __int64 v21; 
  UINT8 *v23; 
  unsigned int v24; 
  int v25; 
  int v26; 
  __int64(__fastcall *v27)(_QWORD, _QWORD, __int64); 
  UINT8 *v28; 
  unsigned int v29; 
  _DWORD v30[10]; 
  unsigned int v31; 
  int v32; 
  v32 = HIDWORD(SecurityCached);
  v30[0] = -1;
  v31 = 0;
  v5 = SecurityCell;
  v30[1] = 0;
  if( CmpFindSecurityCellCacheIndex((__int64)CmHive, SecurityCell, &v31) == 1 )
    return 0;
  v7 = *((_DWORD *)CmHive + 467);
  if( *((_DWORD *)CmHive + 466) == v7 )
  {
    v23 = (UINT8 *)*((_QWORD *)CmHive + 235);
    v24 = 16 * v7;
    v25 = 256;
    if( BuildUp != 1 )
      v25 = 16;
    v26 = v7 + v25;
    v27 = (__int64(__fastcall *)(_QWORD, _QWORD, __int64))*((_QWORD *)CmHive + 3);
    *((_DWORD *)CmHive + 467) = v26;
    v28 = (UINT8 *)v27((unsigned int)(16 * v26), 0i64, 1666403651i64);
    v29 = *((_DWORD *)CmHive + 466);
    *((_QWORD *)CmHive + 235) = v28;
    if( !v28 )
    {
      *((_QWORD *)CmHive + 235) = v23;
      *((_DWORD *)CmHive + 467) = v29;
      return -1073741670;
    }
    memmove(v28, v23, 16i64 * v29);
    if( v23 )
      (*((void(__fastcall **)(UINT8 *, _QWORD))CmHive + 4))(v23, v24);
  }
  v8 = (*((__int64(__fastcall **)(_CMHIVE *, _QWORD, _DWORD *))CmHive + 1))(CmHive, v5, v30);
  v9 = v8;
  if( v8 )
  {
    v10 = (unsigned int)(*(_DWORD *)(v8 + 16) + 32);
    if( *(_DWORD *)(v8 + 16) < 0xFFFFFFE0 && (_DWORD)v10 != 32 )
    {
      v11 = (*((__int64(__fastcall **)(__int64, _QWORD, __int64))CmHive + 3))(v10, 0i64, 1666403651i64);
      v12 = v11;
      if( v11 )
      {
        memmove((UINT8 *)(v11 + 32), (UINT8 *)(v9 + 20), *(unsigned int *)(v9 + 16));
        *(_DWORD *)v12 = v5;
        v13 = *(_DWORD *)(v9 + 16);
        *(_DWORD *)(v12 + 28) = 0;
        *(_DWORD *)(v12 + 24) = v13;
        v14 = CmpSecConvKey(*(unsigned int *)(v9 + 16), (UINT64 *)(v9 + 20));
        *(_DWORD *)(v12 + 4) = v14;
        v15 = v14 & 0x3F;
        v16 = (char *)(v12 + 8);
        v17 = (char *)CmHive + 16 * v15 + 1888;
        v18 = (char **)*((_QWORD *)v17 + 1);
        if( *v18 != v17 )
          __fastfail(3u);
        v19 = v31;
        *(_QWORD *)v16 = v17;
        *(_QWORD *)(v12 + 16) = v18;
        *v18 = v16;
        *((_QWORD *)v17 + 1) = v16;
        v20 = *((_DWORD *)CmHive + 466);
        if( (unsigned int)v19 < v20 )
          memmove(
            (UINT8 *)(*((_QWORD *)CmHive + 235) + 16i64 * (unsigned int)(v19 + 1)),
            (UINT8 *)(*((_QWORD *)CmHive + 235) + 16i64 * (unsigned int)v19),
            16i64 * (v20 - (unsigned int)v19));
        v21 = 2 * v19;
        *(_DWORD *)(*((_QWORD *)CmHive + 235) + 8 * v21) = v5;
        *(_QWORD *)(*((_QWORD *)CmHive + 235) + 8 * v21 + 8) = v12;
        ++*((_DWORD *)CmHive + 466);
        (*((void(__fastcall **)(_CMHIVE *, _DWORD *))CmHive + 2))(CmHive, v30);
        return 0;
      }
    }
    (*((void(__fastcall **)(_CMHIVE *, _DWORD *))CmHive + 2))(CmHive, v30);
  }
  return -1073741670;
}

Referenced by:

CmpInsertSecurityCellList
CmpSetSecurityDescriptorInfo
CmpValidateHiveSecurityDescriptors