//
// png_set_tRNS from 0x870504 to 0x8705bc (184 bytes)
//
// 2 xrefs:
// > png_handle_tRNS @ 0x86d872
// > sub_8713B8 @ 0x871714
//
// 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:57 +0000
//
_DWORD *__fastcall png_set_tRNS(_DWORD *result, int a2, const void *a3, size_t a4, int a5)
{
bool v5; // zf
int v7; // r3
_DWORD *v9; // r7
int v11; // r3
int v12; // r1
int v13; // r3
v5 = a2 == 0;
if ( a2 )
v5 = result == nullptr;
v7 = v5;
if ( !v5 )
{
v9 = result;
if ( a3 )
{
png_free_data((int)result, a2, 0x2000, v7);
result = png_malloc(v9, 0x100u);
*(_DWORD *)(a2 + 156) = result;
v9[157] = result;
if ( a4 - 1 <= 0xFF )
result = memcpy(result, a3, a4);
}
if ( a5 )
{
v11 = 1 << *(_BYTE *)(a2 + 24);
if ( *(_BYTE *)(a2 + 25) )
{
if ( *(_BYTE *)(a2 + 25) != 2
|| v11 >= *(unsigned __int16 *)(a5 + 2)
&& v11 >= *(unsigned __int16 *)(a5 + 4)
&& v11 >= *(unsigned __int16 *)(a5 + 6) )
{
LABEL_13:
result = *(_DWORD **)a5;
v12 = *(_DWORD *)(a5 + 4);
*(_DWORD *)(a2 + 160) = *(_DWORD *)a5;
*(_DWORD *)(a2 + 164) = v12;
*(_WORD *)(a2 + 168) = *(_WORD *)(a5 + 8);
if ( !a4 )
LOWORD(a4) = 1;
*(_WORD *)(a2 + 22) = a4;
goto LABEL_16;
}
}
else if ( v11 >= *(unsigned __int16 *)(a5 + 8) )
{
goto LABEL_13;
}
png_warning((int)v9, "tRNS chunk has out-of-range samples for bit_depth");
goto LABEL_13;
}
*(_WORD *)(a2 + 22) = a4;
if ( a4 )
{
LABEL_16:
v13 = *(_DWORD *)(a2 + 232);
*(_DWORD *)(a2 + 8) |= 0x10u;
*(_DWORD *)(a2 + 232) = v13 | 0x2000;
}
}
return result;
}