//
// sub_650AF8 from 0x650af8 to 0x650c6c (372 bytes)
//
// 2 xrefs:
// > png_chunk_warning @ 0x651014
// > png_chunk_error @ 0x651128
//
// 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
//
unsigned int __fastcall sub_650AF8(unsigned int result, _BYTE *a2, int a3)
{
_BOOL4 v3; // r3
int v4; // r6
_BOOL4 v5; // r3
int v6; // r5
_BOOL4 v7; // r3
int v8; // r6
_BOOL4 v9; // r3
int v10; // r7
_BYTE *v11; // r4
int v12; // r5
char v13; // lr
char v14; // r3
int v15; // r2
_BYTE *v16; // r4
int v17; // r3
int v18; // r5
unsigned int v19; // t1
_BYTE *v20; // r7
char v21; // r12
char v22; // r3
_BYTE *v23; // r7
char v24; // r12
char v25; // r3
char v26; // r7
char v27; // r3
v3 = (unsigned int)HIBYTE(result) - 65 > 0x39;
if ( (unsigned int)HIBYTE(result) - 91 <= 5 )
v3 = 1;
if ( v3 )
{
v4 = 4;
*a2 = 91;
v26 = a0123456789abcd_7[result >> 28];
v27 = a0123456789abcd_7[HIBYTE(result) & 0xF];
a2[3] = 93;
a2[1] = v26;
a2[2] = v27;
}
else
{
v4 = 1;
*a2 = HIBYTE(result);
}
v5 = (unsigned int)BYTE2(result) - 65 > 0x39;
if ( (unsigned int)BYTE2(result) - 91 <= 5 )
v5 = 1;
if ( v5 )
{
v23 = &a2[v4];
v6 = v4 + 4;
a2[v4] = 91;
v24 = a0123456789abcd_7[BYTE2(result) >> 4];
v25 = a0123456789abcd_7[HIWORD(result) & 0xF];
v23[3] = 93;
v23[1] = v24;
v23[2] = v25;
}
else
{
a2[v4] = BYTE2(result);
v6 = v4 + 1;
}
v7 = (unsigned int)BYTE1(result) - 65 > 0x39;
if ( (unsigned int)BYTE1(result) - 91 <= 5 )
v7 = 1;
if ( v7 )
{
v20 = &a2[v6];
v8 = v6 + 4;
a2[v6] = 91;
v21 = a0123456789abcd_7[BYTE1(result) >> 4];
v22 = a0123456789abcd_7[(result >> 8) & 0xF];
v20[3] = 93;
v20[1] = v21;
v20[2] = v22;
}
else
{
a2[v6] = BYTE1(result);
v8 = v6 + 1;
}
v9 = (unsigned int)(unsigned __int8)result - 65 > 0x39;
if ( (unsigned int)(unsigned __int8)result - 91 <= 5 )
v9 = 1;
if ( v9 )
{
v10 = (unsigned __int8)result >> 4;
result &= 0xFu;
v11 = &a2[v8];
v12 = v8 + 4;
a2[v8] = 91;
v13 = a0123456789abcd_7[v10];
v14 = a0123456789abcd_7[result];
v11[3] = 93;
v11[1] = v13;
v11[2] = v14;
if ( a3 )
goto LABEL_17;
LABEL_22:
a2[v12] = a3;
return result;
}
v12 = v8 + 1;
a2[v8] = result;
if ( !a3 )
goto LABEL_22;
LABEL_17:
a2[v12] = 58;
v15 = a3 - 1;
a2[v12 + 1] = 32;
v16 = &a2[v12 + 1];
v17 = v12 + 2;
v18 = v12 + 197;
do
{
v19 = *(unsigned __int8 *)++v15;
result = v19;
if ( !v19 )
break;
++v17;
*++v16 = result;
}
while ( v17 != v18 );
a2[v17] = 0;
return result;
}