//
// sub_100596D78 from 0x100596d78 to 0x100596ea4 (300 bytes)
//
// 2 xrefs:
// > sub_100595974 @ 0x100595e88
// > sub_100596058 @ 0x10059632c
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:08:47 +0000
//
__int64 __fastcall sub_100596D78(__int64 a1, unsigned __int8 *a2, __int64 a3, __int64 a4)
{
__int64 v8; // x9
int v9; // w8
__int64 v10; // x11
void *v11; // x0
__int64 v12; // x9
int v13; // w11
int v14; // w8
__int64 result; // x0
int *v16; // x8
int v17; // w9
v8 = *(_QWORD *)(a1 + 376);
v9 = *(_DWORD *)(v8 + 18628);
if ( !v9 )
{
result = sub_1005968A8(a1, a2, nullptr, nullptr, nullptr);
if ( (_DWORD)result )
return result;
v8 = *(_QWORD *)(a1 + 376);
v9 = *(_DWORD *)(v8 + 18628);
}
v10 = *(int *)(v8 + 18592);
v11 = (void *)(v8 + 2304 * v10 + 512);
*(_QWORD *)(v8 + 18608) = v11;
*(_DWORD *)(v8 + 18592) = (v10 & 1) == 0;
*(_DWORD *)(v8 + 18600) = 0;
memcpy(v11, a2 + 4, v9);
v12 = *(_QWORD *)(a1 + 376);
if ( *(_DWORD *)(v12 + 18540) )
{
v13 = *(_DWORD *)(v12 + 18600);
*(_QWORD *)(v12 + 18608) += (v13 + 16) >> 3;
*(_DWORD *)(v12 + 18600) = v13 & 7;
}
v14 = *(_DWORD *)(v12 + 18536);
if ( v14 == 3 )
{
result = sub_10059E948(a1, a3, a4);
}
else if ( v14 == 2 )
{
result = sub_100598538(a1, a3, a4);
}
else
{
result = 0;
}
v16 = (int *)(*(_QWORD *)(a1 + 376) + 18628LL);
v17 = *v16;
*v16 = 0;
v16[1] = v17;
return result;
}