RtlpHpLfhSubsegmentFindEmptyUnits

INT64 __fastcall RtlpHpLfhSubsegmentFindEmptyUnits(INT64 a1, UINT64 a2, _DWORD *a3){
  INT64 v3; 
  __int64 v4; 
  unsigned __int64 v5; 
  _WORD *v6; 
  INT64 result; 
  __int64 v8; 
  bool v9; 
  _WORD *v10; 
  __int64 v11; 
  _WORD *i; 
  v3 = a1 + *(unsigned __int16 *)(a1 + 46);
  LODWORD(v4) = a2;
  v5 = v3 + 2i64 * *(unsigned __int8 *)(a1 + 45);
  v6 = (_WORD *)(v3 + 2i64 * (unsigned int)a2);
  if( *v6 )
  {
    if( (unsigned __int64)v6 >= v5 )
      return 0xFFFFFFFFi64;
    while( *v6 )
    {
      if( (unsigned __int64)++v6 >= v5 )
        return 0xFFFFFFFFi64;
    }
    if( (unsigned __int64)v6 >= v5 )
      return 0xFFFFFFFFi64;
    v4 = ((__int64)v6 - v3) >> 1;
  }
  else
  {
    for( i = v6 - 1; !*i; --i )
      ;
    v6 = i + 1;
  }
  v8 = (unsigned int)v4 + 1i64;
  v9 = *(_WORD *)(v3 + 2 * v8) == 0;
  v10 = (_WORD *)(v3 + 2 * v8);
  if( v9 )
  {
    do
    {
      if( (unsigned __int64)v10 >= v5 )
        break;
      ++v10;
    }
    while( !*v10 );
  }
  v11 = v10 - v6;
  result = (unsigned int)(((__int64)v6 - v3) >> 1);
  *a3 = v11;
  return result;
}

Referenced by:

RtlpHpLfhSubsegmentDecommitPages
RtlpHpLfhSubsegmentFree