//
// sub_8AF050 from 0x8af050 to 0x8af126 (214 bytes)
//
// 2 xrefs:
// > sub_8AF128 @ 0x8af12e
// > sub_8AF128 @ 0x8af136
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:03:53 +0000
//
_DWORD *__fastcall sub_8AF050(_DWORD *result, unsigned int a2)
{
int v2; // r6
_DWORD *v4; // r7
_DWORD *v5; // r8
_DWORD *v6; // r3
_DWORD *v7; // r4
int v8; // r5
_DWORD *v9; // r3
_DWORD *v10; // r4
int v11; // r5
int i; // r4
int v13; // r5
v2 = (int)result;
v4 = (_DWORD *)result[1];
if ( a2 <= 1 )
{
if ( a2 == 1 )
{
for ( i = v4[17]; i; i = *(_DWORD *)(i + 44) )
{
while ( !*(_DWORD *)(i + 40) )
{
i = *(_DWORD *)(i + 44);
if ( !i )
goto LABEL_14;
}
*(_DWORD *)(i + 40) = 0;
result = (_DWORD *)(*(int (__fastcall **)(int, int))(i + 56))(v2, i + 48);
}
LABEL_14:
v13 = v4[18];
for ( v4[17] = 0; v13; v13 = *(_DWORD *)(v13 + 44) )
{
while ( !*(_DWORD *)(v13 + 40) )
{
v13 = *(_DWORD *)(v13 + 44);
if ( !v13 )
goto LABEL_19;
}
*(_DWORD *)(v13 + 40) = 0;
result = (_DWORD *)(*(int (__fastcall **)(int, int))(v13 + 56))(v2, v13 + 48);
}
LABEL_19:
v4[18] = 0;
}
}
else
{
*(_DWORD *)(*result + 20) = 15;
*(_DWORD *)(*result + 24) = a2;
result = (_DWORD *)(*(int (__fastcall **)(_DWORD *))*result)(result);
}
v5 = &v4[a2];
v6 = (_DWORD *)v5[15];
v5[15] = 0;
if ( v6 )
{
do
{
v7 = (_DWORD *)*v6;
v8 = v6[1] + v6[2] + 16;
result = (_DWORD *)jpeg_free_large(v2, v6);
v6 = v7;
v4[19] -= v8;
}
while ( v7 );
}
v9 = (_DWORD *)v5[13];
v5[13] = 0;
if ( v9 )
{
do
{
v10 = (_DWORD *)*v9;
v11 = v9[1] + v9[2] + 16;
result = (_DWORD *)jpeg_free_small(v2, v9);
v9 = v10;
v4[19] -= v11;
}
while ( v10 );
}
return result;
}