RtlFindClearBitsAndSetEx
UINT64 __fastcall RtlFindClearBitsAndSetEx(UINT64 *a1, UINT64 a2, UINT64 a3){
UINT64 v3;
UINT64 v5;
UINT64 v8;
UINT64 v9;
UINT64 v10;
UINT64 v11;
unsigned __int64 *v12;
__int64 v13;
unsigned __int64 v14;
unsigned __int64 v15;
unsigned __int64 v16;
__int64 v18;
unsigned __int64 *v19;
bool v20;
__int64 v21;
unsigned int v22;
unsigned __int64 v23;
UINT64 v24;
__int64 v25;
UINT64 v26;
__int64 v27;
unsigned int v28;
unsigned int v29;
__int64 v30;
__int64 v31;
unsigned __int64 *v32;
unsigned __int64 v33;
__int64 v34;
unsigned int v35;
UINT64 v36;
v3 = *a1;
v5 = a1[1];
v8 = a3 & -(__int64)(a3 < *a1);
v9 = *a1 - 1;
if( a2 )
{
while( 1 )
{
if( v9 - v8 + 1 < a2 )
{
LABEL_26:
v15 = -1i64;
goto LABEL_27;
}
v10 = v9 - a2 + 1;
v11 = v5 + 8 * (v10 >> 6);
v12 = (unsigned __int64 *)(v5 + 8 * (v8 >> 6));
v13 = *v12 | ((1i64 << (v8 & 0x3F)) - 1);
if( a2 > 0x7F )
{
v26 = v11 + 8;
if( (v10 & 0x3F) == 0 )
v26 = v5 + 8 * (v10 >> 6);
if( v13 )
{
if( *++v12 )
goto LABEL_49;
v20 = !_BitScanReverse64((unsigned __int64 *)&v27, v13);
if( v20 )
v28 = 64;
else
v28 = 63 - v27;
}
else
{
v28 = 0;
}
while( 1 )
{
v15 = ((__int64)((__int64)v12 - v5) >> 3 << 6) - v28;
if( v15 > v10 )
goto LABEL_26;
v32 = &v12[(a2 - v28) >> 6];
while( ++v12 != v32 )
{
if( *v12 )
goto LABEL_49;
}
v29 = ((_BYTE)a2 - (_BYTE)v28) & 0x3F;
if( (((_BYTE)a2 - (_BYTE)v28) & 0x3F) == 0 )
goto LABEL_11;
v20 = !_BitScanForward64((unsigned __int64 *)&v30, *v12);
if( v20 )
LODWORD(v30) = 64;
if( (unsigned int)v30 >= v29 )
goto LABEL_11;
do
{
LABEL_49:
if( (unsigned __int64)v12 > v26 )
goto LABEL_26;
++v12;
}
while( *v12 );
v20 = !_BitScanReverse64((unsigned __int64 *)&v31, *(v12 - 1));
if( v20 )
v28 = 64;
else
v28 = 63 - v31;
}
}
if( a2 >= 0x40 )
break;
if( a2 > 1 )
{
v18 = 0i64;
v19 = (unsigned __int64 *)(v5 + 8 * (v9 >> 6));
while( v13 != -1 )
{
LABEL_18:
v20 = !_BitScanForward64((unsigned __int64 *)&v21, v13);
if( v20 )
LODWORD(v21) = 64;
if( (unsigned int)(v18 + v21) >= a2 )
{
v23 = -v18;
LABEL_25:
v15 = ((__int64)((__int64)v12 - v5) >> 3 << 6) + v23;
goto LABEL_10;
}
v22 = a2;
v23 = ~v13;
while( 1 )
{
v23 &= v23 >> (v22 >> 1);
if( !v23 )
break;
v22 -= v22 >> 1;
if( v22 <= 1 )
{
_BitScanForward64(&v23, v23);
goto LABEL_25;
}
}
if( v12 == v19 )
goto LABEL_26;
v20 = !_BitScanReverse64((unsigned __int64 *)&v25, v13);
if( v20 )
v18 = 64i64;
else
v18 = (unsigned int)(63 - v25);
v13 = *++v12;
}
while( 1 )
{
if( (unsigned __int64)++v12 > v11 )
goto LABEL_26;
v13 = *v12;
if( *v12 != -1i64 )
{
v18 = 0i64;
goto LABEL_18;
}
}
}
while( v13 == -1 )
{
if( (unsigned __int64)++v12 > v11 )
goto LABEL_26;
v13 = *v12;
}
_BitScanForward64(&v14, ~v13);
v15 = v14 + ((__int64)((__int64)v12 - v5) >> 3 << 6);
LABEL_10:
if( v15 > v10 )
goto LABEL_26;
LABEL_11:
if( v15 != -1i64 )
{
LABEL_12:
v16 = v15;
goto LABEL_13;
}
LABEL_27:
if( !v8 )
goto LABEL_12;
v24 = a2 + a3;
if( a2 + a3 > v3 )
v24 = v3;
v9 = v24 - 1;
v8 = 0i64;
}
while( 1 )
{
while( 1 )
{
while( v13 < 0 )
{
if( (unsigned __int64)++v12 > v11 )
goto LABEL_26;
v13 = *v12;
}
v20 = !_BitScanReverse64((unsigned __int64 *)&v34, v13);
if( v20 )
v35 = 64;
else
v35 = 63 - v34;
v15 = ((((__int64)((__int64)v12 - v5) >> 3) + 1) << 6) - v35;
if( v15 > v10 )
goto LABEL_26;
v36 = a2 - v35;
if( a2 == v35 )
goto LABEL_11;
v13 = *++v12;
if( v36 >= 0x40 )
break;
LABEL_58:
v20 = !_BitScanForward64(&v33, v13);
if( v20 )
v33 = 64i64;
if( v33 >= v36 )
goto LABEL_11;
}
if( !*v12 )
{
v36 -= 64i64;
if( !v36 )
goto LABEL_11;
v13 = *++v12;
goto LABEL_58;
}
}
}
v16 = v8 & 0xFFFFFFFFFFFFFFF8ui64;
LABEL_13:
if( v16 != -1i64 )
RtlSetBitsEx((INT64)a1, v16, a2);
return v16;
}Referenced by:
ExpSaPageGroupAllocateMemory
MiAllocateFromSubAllocatedRegion
MiObtainRelocationBits
MiObtainSessionVa
RtlpHpFixedVsAllocate