//
// sub_1004B9BE4 from 0x1004b9be4 to 0x1004b9d08 (292 bytes)
//
// 1 xrefs:
// > sub_1004B98A0 @ 0x1004b98dc
//
// 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_1004B9BE4(__int64 *a1)
{
__int64 v2; // x20
__int64 result; // x0
int v4; // w10
int v5; // w9
int v6; // w8
int v7; // w8
signed __int64 v8; // x2
signed __int64 v9; // x8
__int64 v10; // x9
int v11; // [xsp+Ch] [xbp-14h] BYREF
v2 = *a1;
v11 = 0;
result = sub_1004B5828(&v11);
if ( !(_DWORD)result )
{
v4 = *(_DWORD *)(v2 + 28);
v5 = v11 - *(_DWORD *)(v2 + 24);
*(_DWORD *)(v2 + 24) = v11;
if ( v5 <= 1000 )
v6 = v5;
else
v6 = 0;
v7 = v6 * *(_DWORD *)v2 / 1000 + *(_DWORD *)(v2 + 32);
*(_DWORD *)(v2 + 32) = v7;
if ( v7 - v4 >= *(_DWORD *)(v2 + 8) )
{
result = ((__int64 (__fastcall *)(__int64 *, _QWORD))a1[1])(a1, *(_QWORD *)(v2 + 40));
if ( !(_DWORD)result )
{
*(_DWORD *)(v2 + 28) += *(_DWORD *)(v2 + 8);
if ( *(_DWORD *)(v2 + 20) == 1 )
{
v8 = *(unsigned int *)(v2 + 12);
if ( (int)v8 >= 1 )
{
v9 = 0;
v10 = *(_QWORD *)(v2 + 40);
do
{
*(_BYTE *)(v10 + v9++) ^= 0x80u;
v8 = *(int *)(v2 + 12);
}
while ( v9 < v8 );
}
}
else
{
v8 = *(unsigned int *)(v2 + 12);
}
result = sub_1004B5730(*(FILE **)(v2 + 48), *(void **)(v2 + 40), v8, 0);
if ( !(_DWORD)result )
*(_DWORD *)(v2 + 36) += *(_DWORD *)(v2 + 12);
}
}
else
{
sub_1004B586C(*(_DWORD *)(v2 + 16));
return 0;
}
}
return result;
}