RtlpLfhBlockBitmapAllocate

NTSTATUS __stdcall RtlpLfhBlockBitmapAllocate(UINT64 *a1, INT64 a2, UINT64 a3, UINT64 a4, INT64 a5){
  UINT64 v5; 
  unsigned int v6; 
  UINT64 v7; 
  int v8; 
  volatile signed __int64 *v9; 
  volatile signed __int64 *v10; 
  signed __int64 v11; 
  signed __int64 v12; 
  __int64 v13; 
  unsigned __int64 v14; 
  int v15; 
  bool v16; 
  signed __int64 v17; 
  volatile signed __int64 *v19; 
  unsigned __int64 v20; 
  volatile signed __int64 *v21; 

  v5 = a1[1];
  v6 = a4;
  v7 = *a1;
  v8 = a3;
  v9 = (volatile signed __int64 *)(v5 + 8 * ((unsigned __int64)(unsigned int)(2 * a2) >> 6));
  v10 = (volatile signed __int64 *)(v5 + 8 * ((*a1 - 1) >> 6));
LABEL_2:
  if( v7 < 0x40 )
  {
    if( (unsigned int)v7 < v6 )
      v6 = v7;
    v11 = *v9;
  }
  else
  {
    while( 1 )
    {
      v11 = *v9;
      if( (*v9 & 0x5555555555555555i64) != 0x5555555555555555i64 )
        break;
      v19 = v9++;
      if( v19 == v10 )
        v9 = (volatile signed __int64 *)v5;
    }
    if( v9 == v10 && (v7 & 0x3F) != 0 && (v7 & 0x3F) < v6 )
      v6 = v7 & 0x3F;
  }
  v8 = ((v6 * v8) >> 7) & 0x1FFFFFE;
  while( 1 )
  {
    v12 = ~v11;
    if( v6 < 0x40 )
    {
      _BitScanForward64(&v20, v12 & 0x5555555555555555i64);
      v8 += v20;
      v13 = (((1i64 << v6) - 1) << v20) & 0x5555555555555555i64;
    }
    else
    {
      v13 = 0x5555555555555555i64;
    }
    _BitScanForward64(&v14, __ROR8__(v13 & v12, v8));
    v15 = ((_BYTE)v8 + (_BYTE)v14) & 0x3F;
    v17 = _InterlockedCompareExchange64(v9, v11 | (a5 << v15), v11);
    v16 = v11 == v17;
    v11 = v17;
    if( v16 )
      return(v15 + ((unsigned int)((__int64)((__int64)v9 - v5) >> 3) << 6)) >> 1;
    if( (v17 & 0x5555555555555555i64) == 0x5555555555555555i64 )
    {
      v21 = v9 + 1;
      v9 = (volatile signed __int64 *)v5;
      if( v21 <= v10 )
        v9 = v21;
      goto LABEL_2;
    }
  }
}

Referenced by:

RtlpHpLfhSlotAllocate