//
// sub_BAF320 from 0xbaf320 to 0xbaf450 (304 bytes)
//
// 6 xrefs:
// > sub_B73FF0 @ 0xb74070
// > sub_B73FF0 @ 0xb741b4
// > sub_BB276C @ 0xbb2b6c
// > sub_BB352C @ 0xbb387c
// > sub_BB3E44 @ 0xbb3fb4
// > sub_BB3E44 @ 0xbb4050
//
// 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_BAF320(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // x19
__int64 v5; // x20
__int64 v6; // x1
__int64 result; // x0
int v8; // w2
unsigned __int64 v9; // t2
int v10; // w0
int v11; // w1
int v12; // w25
v4 = a2;
if ( !a3 )
return 43;
v5 = a2 + 4 * ((unsigned int)(a3 - 1) + 1LL);
do
{
while ( 1 )
{
v6 = v4;
v4 += 4;
result = sub_BBACA4(a1, v6);
if ( (_DWORD)result != 4 )
break;
if ( byte_1247844 )
{
v8 = dword_1247848;
}
else
{
v10 = sub_B70B94();
v12 = v10 + v11;
sub_B7B528(a1, "WARNING: Using weak random seed\n");
byte_1247844 = 1;
v8 = 1103515245 * (1103515245 * (1103515245 * (v12 + dword_1247848) + 12345) + 12345) + 12345;
}
dword_1247848 = 1103515245 * v8 + 12345;
HIDWORD(v9) = 1103515245 * v8 + 12345;
LODWORD(v9) = HIDWORD(v9);
*(_DWORD *)(v4 - 4) = v9 >> 16;
if ( v4 == v5 )
return 0;
}
if ( (_DWORD)result )
return result;
}
while ( v4 != v5 );
return 0;
}