//
// sub_BFB504 from 0xbfb504 to 0xbfb63c (312 bytes)
//
// 1 xrefs:
// > sub_BFB63C @ 0xbfb664
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __fastcall sub_BFB504(__int64 result, __int64 a2, _DWORD *a3, unsigned int a4)
{
_DWORD *v4; // x20
__int64 v8; // x19
unsigned int v9; // w2
_DWORD *v10; // x1
int v11; // w0
unsigned int v12; // w1
unsigned int v13; // w6
v4 = *(_DWORD **)(result + 504);
if ( v4[4] < *(_DWORD *)(result + 368) )
{
v8 = result;
v9 = v4[5];
while ( 1 )
{
v13 = *(_DWORD *)(v8 + 364);
if ( v13 <= v9 )
{
result = v8;
v10 = v4 + 8;
if ( v9 != v13 )
return result;
}
else
{
(*(void (__fastcall **)(__int64, __int64, _DWORD *, _QWORD, _DWORD *, _DWORD *))(*(_QWORD *)(v8 + 512) + 8LL))(
v8,
a2,
a3,
a4,
v4 + 8,
v4 + 5);
result = v8;
v10 = v4 + 8;
if ( v4[5] != *(_DWORD *)(v8 + 364) )
return result;
}
v11 = (*(__int64 (__fastcall **)(__int64, _DWORD *))(*(_QWORD *)(v8 + 520) + 8LL))(result, v10);
v9 = 0;
if ( !v11 )
break;
if ( v4[6] )
{
++*a3;
v4[6] = 0;
}
v12 = *(_DWORD *)(v8 + 368);
result = (unsigned int)(v4[4] + 1);
*((_QWORD *)v4 + 2) = (unsigned int)result;
if ( v12 <= (unsigned int)result )
return result;
}
result = (unsigned int)v4[6];
if ( !(_DWORD)result )
{
--*a3;
v4[6] = 1;
return 1;
}
}
return result;
}