//
// png_handle_bKGD from 0x86d8d8 to 0x86da46 (366 bytes)
//
// 3 xrefs:
// > png_push_read_chunk @ 0x862b48
// > png_read_info @ 0x865902
// > png_read_end @ 0x8673ca
//
// 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:02:55 +0000
//
int __fastcall png_handle_bKGD(int a1, int a2, unsigned int a3)
{
int v4; // r3
int v6; // r1
int v7; // r3
int result; // r0
int v9; // r3
int v10; // r1
int v11; // r3
unsigned __int8 v12; // [sp+4h] [bp-18h] BYREF
unsigned __int8 v13; // [sp+5h] [bp-17h]
unsigned __int8 v14; // [sp+6h] [bp-16h]
unsigned __int8 v15; // [sp+7h] [bp-15h]
unsigned __int8 v16; // [sp+8h] [bp-14h]
unsigned __int8 v17; // [sp+9h] [bp-13h]
_BYTE v18[2]; // [sp+Ch] [bp-10h] BYREF
__int16 v19; // [sp+Eh] [bp-Eh]
__int16 v20; // [sp+10h] [bp-Ch]
__int16 v21; // [sp+12h] [bp-Ah]
__int16 v22; // [sp+14h] [bp-8h]
v4 = *(_DWORD *)(a1 + 308);
if ( (v4 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v4 & 4) != 0 )
goto LABEL_12;
v6 = *(unsigned __int8 *)(a1 + 535);
if ( v6 == 3 )
{
if ( (v4 & 2) != 0 )
{
if ( !a2 || (*(_DWORD *)(a2 + 8) & 0x20) == 0 )
{
v7 = 1;
goto LABEL_9;
}
LABEL_17:
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "duplicate");
}
LABEL_12:
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "out of place");
}
if ( a2 && (*(_DWORD *)(a2 + 8) & 0x20) != 0 )
goto LABEL_17;
if ( (v6 & 2) != 0 )
v7 = 6;
else
v7 = 2;
LABEL_9:
if ( a3 == v7 )
{
png_crc_read((_DWORD *)a1, (int)&v12, a3);
result = png_crc_finish((_DWORD *)a1, 0);
if ( !result )
{
v9 = *(unsigned __int8 *)(a1 + 535);
if ( v9 == 3 )
{
v18[0] = v12;
if ( a2 && *(_WORD *)(a2 + 20) )
{
if ( *(unsigned __int16 *)(a2 + 20) <= (unsigned int)v12 )
return png_chunk_benign_error(a1, "invalid index");
v10 = *(_DWORD *)(a1 + 516);
v11 = 3 * v12;
v19 = *(unsigned __int8 *)(v10 + v11);
v20 = *(unsigned __int8 *)(v10 + v11 + 1);
v21 = *(unsigned __int8 *)(v10 + v11 + 2);
}
else
{
v21 = 0;
v20 = 0;
v19 = 0;
}
v22 = 0;
}
else
{
v18[0] = 0;
if ( (v9 & 2) != 0 )
{
v22 = 0;
v19 = v13 + (v12 << 8);
v20 = v15 + (v14 << 8);
v21 = v17 + (v16 << 8);
}
else
{
v22 = v13 + (v12 << 8);
v21 = v22;
v20 = v22;
v19 = v22;
}
}
return png_set_bKGD(a1, a2, v18);
}
}
else
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "invalid");
}
return result;
}