SmcStorePlacementGet

NTSTATUS __stdcall SmcStorePlacementGet(_SMC_CACHE *Cache, UINT64 RequiredRegions, _SMC_STORE_ENTRY *TransitionEntry){
  NTSTATUS v3; 
  unsigned int v5; 
  unsigned __int64 v6; 
  _SMC_CACHE *v7; 
  _SMC_CACHE *v8; 
  _DWORD *v9; 
  _DWORD *v10; 
  unsigned __int64 v11; 
  unsigned __int64 v12; 
  NTSTATUS SetBits; 
  NTSTATUS v14; 
  UINT32 v15; 
  int v16; 
  NTSTATUS v17; 
  _RTL_BITMAP BitMapHeader; 

  v3 = 0;
  BitMapHeader.SizeOfBitMap = Cache[2];
  *(&BitMapHeader.SizeOfBitMap + 1) = 0;
  v5 = RequiredRegions;
  v6 = ((unsigned __int64)BitMapHeader.SizeOfBitMap + 31) >> 5;
  v7 = Cache + 42;
  BitMapHeader.Buffer = (unsigned int *)*((_QWORD *)TransitionEntry + 1);
  v8 = v7 + 96;
  while( v7 < v8 )
  {
    if( v7 != TransitionEntry )
    {
      v9 = (_DWORD *)*((_QWORD *)v7 + 1);
      if( v9 )
      {
        v10 = (_DWORD *)*((_QWORD *)TransitionEntry + 1);
        v11 = v6;
        v12 = 0i64;
        if( v9 > &v9[v6] )
          v11 = 0i64;
        if( v11 )
        {
          do
          {
            ++v12;
            *v10++ ^= *v9++;
          }
          while( v12 < v11 );
        }
      }
    }
    v7 += 6;
  }
  SetBits = RtlFindSetBits((INT64)&BitMapHeader, v5, 0i64);
  v14 = SetBits;
  if( SetBits == -1 )
  {
    v16 = 0;
    v17 = RtlFindSetBits((INT64)&BitMapHeader, 1ui64, 0i64);
    if( v17 < 0 )
      return -1073741697;
    while( 1 )
    {
      ++v16;
      v15 = v17 + 1;
      if( v16 == v5 )
        break;
      v17 = RtlFindSetBits((INT64)&BitMapHeader, 1ui64, v15);
      if( v17 < (int)v15 )
        return -1073741697;
    }
  }
  else
  {
    RtlClearBits(&BitMapHeader, 0, SetBits);
    v15 = v5 + v14;
  }
  RtlClearBits(&BitMapHeader, v15, BitMapHeader.SizeOfBitMap - v15);
  return v3;
}

Referenced by:

SmcStoreResize
SmcStoreSlotReserve