//
// sub_100582BB8 from 0x100582bb8 to 0x100582d80 (456 bytes)
//
// 2 xrefs:
// > sub_10058212C @ 0x1005821d0
// > sub_100582418 @ 0x10058255c
//
// 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_100582BB8(__int64 *a1, __int64 *a2)
{
__int64 v4; // x9
unsigned __int64 v5; // x8
int v6; // w1
__int64 result; // x0
__int64 v8; // x8
__int64 v9; // x21
__int64 v10; // x21
unsigned __int64 v11; // x8
unsigned __int64 v12; // x22
__int64 v13; // x8
int v14; // [xsp+4h] [xbp-2Ch] BYREF
__int64 v15; // [xsp+8h] [xbp-28h] BYREF
v4 = a1[174];
if ( v4 )
{
LABEL_10:
v8 = a1[175];
v9 = v4 - v8;
result = sub_100552950((__int64)a1, 0, *a1 + v8 + 18769, v4 - v8, &v15);
if ( (_DWORD)result )
return result;
if ( v15 == v9 )
{
a1[174] = 0;
}
else
{
a1[175] += v15;
if ( a1[174] )
return 81;
}
if ( a1[173] )
return 81;
goto LABEL_17;
}
v5 = a1[173];
if ( v5 )
{
if ( v5 <= 0x4000 )
v6 = a1[173];
else
v6 = 0x4000;
v14 = v6;
*(_QWORD *)(*a1 + 520) = *a1 + 18769;
result = sub_100565ADC(a1, v6, &v14);
if ( (_DWORD)result && (_DWORD)result != 81 )
return result;
v4 = v14;
if ( !v14 )
return 0;
a1[173] -= v14;
a1[174] = v4;
a1[175] = 0;
goto LABEL_10;
}
LABEL_17:
v10 = a1[172];
result = sub_100553124((__int64)a1, 0, (void *)(v10 + a1[176]), 36864 - a1[176], (size_t *)&v15);
if ( !(_DWORD)result )
{
if ( v15 )
{
v11 = a1[176] + v15;
a1[176] = v11;
if ( v11 >= 4 )
{
v12 = sub_100582EE8(v10 + 2) + 4;
if ( a1[176] >= v12 )
{
if ( v12 < 0x25
|| (v13 = (2LL * *(unsigned __int8 *)(v10 + 36)) | 1, v12 < v13 + 38)
|| v12 >= v13 + 38 + (unsigned __int64)(unsigned int)sub_100582EB0(v13 + v10 + 36) )
{
*a2 = v10;
return 0;
}
else
{
return 26;
}
}
else
{
return 0;
}
}
else
{
return 0;
}
}
else
{
return 0;
}
}
return result;
}