//
// sub_1005AD9B8 from 0x1005ad9b8 to 0x1005adb88 (464 bytes)
//
// 9 xrefs:
// > sub_1005ADB88 @ 0x1005adbe8
// > sub_100606F78 @ 0x100606ff0
// > sub_100627F50 @ 0x100627f88
// > sub_1006285F0 @ 0x100628634
// > sub_1006298EC @ 0x10062995c
// > sub_100629A68 @ 0x100629bb4
// > sub_10062E538 @ 0x10062e594
// > sub_10062E538 @ 0x10062e5b4
// > sub_10062E538 @ 0x10062e5d0
//
// 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_1005AD9B8(__int64 *a1, _BYTE *a2)
{
__int64 v3; // x20
int v4; // w8
__int64 v5; // x25
_BYTE *v6; // x24
_BOOL4 v7; // w23
_BYTE *v8; // x21
int v10; // w8
int v11; // w9
int v12; // w8
char v13; // w8
__int64 v14; // x22
int v15; // w9
unsigned __int8 *v16; // x24
int v17; // t1
int v18; // w8
_QWORD *v19; // x9
bool v20; // vf
if ( !a2 )
return 0;
v3 = 0;
v4 = (unsigned __int8)*a2;
if ( *a2 )
{
v5 = 0;
if ( v4 == 45 )
v6 = a2 + 1;
else
v6 = a2;
v7 = v4 == 45;
while ( (unsigned int)(unsigned __int8)v6[v5] - 48 <= 9 )
{
if ( ++v5 >= 0x20000000 )
goto LABEL_11;
}
if ( (int)v5 > 0x1FFFFFFF )
{
LABEL_11:
v8 = nullptr;
LABEL_12:
if ( !*a1 )
sub_1005AACD0(v8);
return 0;
}
v3 = (unsigned int)(v5 + v7);
if ( !a1 )
return v3;
v8 = (_BYTE *)*a1;
if ( *a1 )
{
sub_1005AB128(*a1, 0);
}
else
{
v8 = sub_1005AAD34();
if ( !v8 )
return 0;
}
v10 = 4 * v5;
if ( 4 * (int)v5 > 2147483584 )
goto LABEL_12;
v11 = v10 + 63;
v12 = v10 + 126;
if ( v11 >= 0 )
v12 = v11;
if ( v12 >> 6 > *((_DWORD *)v8 + 3) && !sub_1005AAF94((__int64)v8, v12 >> 6) )
goto LABEL_12;
v13 = *v6;
if ( *v6 )
{
v14 = 0;
if ( (int)v5 % 19 )
v15 = 19 - (int)v5 % 19;
else
v15 = 0;
v16 = v6 + 1;
do
{
v14 = 10 * v14 + v13 - 48;
if ( ++v15 == 19 )
{
sub_1005AEA08(v8);
sub_1005AE83C(v8, v14);
v14 = 0;
v15 = 0;
}
v17 = *v16++;
v13 = v17;
}
while ( v17 );
}
*((_DWORD *)v8 + 4) = v7;
v18 = *((_DWORD *)v8 + 2);
if ( v18 >= 1 )
{
v19 = (_QWORD *)(*(_QWORD *)v8 + 8LL * (v18 - 1));
do
{
if ( *v19 )
break;
--v19;
v20 = __OFSUB__(v18--, 1);
}
while ( !((v18 < 0) ^ v20 | (v18 == 0)) );
*((_DWORD *)v8 + 2) = v18;
}
*a1 = (__int64)v8;
}
return v3;
}