//
// sub_1005AE934 from 0x1005ae934 to 0x1005aea08 (212 bytes)
//
// 7 xrefs:
// > sub_10058B470 @ 0x10058b73c
// > sub_1005AE83C @ 0x1005ae874
// > sub_1005AF320 @ 0x1005af558
// > sub_1005B0CB4 @ 0x1005b0f64
// > sub_1005B3828 @ 0x1005b3948
// > sub_1005D2E30 @ 0x1005d2ec4
// > sub_10062E128 @ 0x10062e33c
//
// 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_1005AE934(__int64 a1, unsigned __int64 a2)
{
int v3; // w9
__int64 result; // x0
__int64 v5; // x20
unsigned __int64 *v6; // x8
int v7; // w9
int v8; // w10
unsigned __int64 v9; // x11
unsigned __int64 v10; // x12
bool v11; // cf
if ( !a2 )
return 1;
v3 = *(_DWORD *)(a1 + 8);
if ( !v3 )
{
v5 = sub_1005AB128(a1, a2);
if ( !(_DWORD)v5 )
return 0;
sub_1005AB6E4(a1, 1);
return v5;
}
if ( *(_DWORD *)(a1 + 16) )
{
*(_DWORD *)(a1 + 16) = 0;
result = sub_1005AE83C(a1, a2);
*(_DWORD *)(a1 + 16) = 1;
return result;
}
v6 = *(unsigned __int64 **)a1;
v7 = v3 - 1;
if ( v7 || *v6 >= a2 )
{
v8 = -1;
do
{
v9 = a2;
v10 = *v6;
v11 = *v6 >= a2;
*v6++ -= a2;
++v8;
a2 = 1;
}
while ( !v11 );
if ( v10 == v9 && v8 == v7 )
*(_DWORD *)(a1 + 8) = v8;
return 1;
}
*v6 = a2 - *v6;
v5 = 1;
*(_DWORD *)(a1 + 16) = 1;
return v5;
}