//
// png_write_end from 0x871cdc to 0x871e62 (390 bytes)
//
// 3 xrefs:
// > cocos2d::CCImage::_saveImageToPNG @ 0x7ebfaa
// > sub_872E84 @ 0x87302a
// > png_write_png @ 0x8732e6
//
// 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:58 +0000
//
int __fastcall png_write_end(int result, _DWORD *a2)
{
int v2; // r10
int v4; // r2
int v5; // r4
int v6; // r3
int v7; // r6
int v8; // r1
int v9; // r2
int v10; // r3
unsigned int v11; // r4
int v12; // r1
int v13; // r0
int v14; // r3
if ( result )
{
v2 = result;
if ( (*(_DWORD *)(result + 308) & 4) == 0 )
png_error(result, "No IDATs written into file");
if ( *(_DWORD *)(result + 524) > (int)*(unsigned __int16 *)(result + 520) )
png_benign_error((_DWORD *)result, "Wrote palette index exceeding num_palette");
if ( a2 )
{
if ( (a2[2] & 0x200) != 0 )
{
v10 = *(_DWORD *)(v2 + 308);
if ( (v10 & 0x200) == 0 )
png_write_tIME(v2, a2 + 35, v10 << 22);
}
v4 = a2[32];
if ( v4 > 0 )
{
v5 = 0;
while ( 1 )
{
v7 = a2[34] + 28 * v5;
v8 = *(_DWORD *)v7;
if ( *(int *)v7 > 0 )
{
png_write_iTXt(v2, v8, *(_DWORD *)(v7 + 4), *(_DWORD *)(v7 + 20), *(char **)(v7 + 24), *(_DWORD *)(v7 + 8));
v6 = a2[34];
if ( *(_DWORD *)(v6 + 28 * v5) == -1 )
goto LABEL_18;
LABEL_11:
*(_DWORD *)(v6 + 28 * v5) = -2;
v4 = a2[32];
LABEL_12:
if ( ++v5 >= v4 )
break;
}
else
{
if ( !*(_DWORD *)v7 )
{
png_write_zTXt(v2, *(_DWORD *)(v7 + 4), *(_DWORD *)(v7 + 8), *(_DWORD *)v7);
v6 = a2[34];
goto LABEL_11;
}
if ( v8 != -1 )
goto LABEL_12;
png_write_tEXt(v2, *(_DWORD *)(v7 + 4), *(_DWORD *)(v7 + 8), 0);
v6 = a2[34];
LABEL_18:
*(_DWORD *)(v6 + 28 * v5++) = -3;
v4 = a2[32];
if ( v5 >= v4 )
break;
}
}
}
v9 = a2[60];
if ( v9 )
{
v11 = a2[59];
if ( v11 < v11 + 20 * v9 )
{
v12 = a2[59];
do
{
if ( (*(_BYTE *)(v11 + 16) & 8) != 0 )
{
v13 = png_handle_as_unknown(v2, (void *)v11);
if ( v13 == 1 )
goto LABEL_33;
v14 = (*(unsigned __int8 *)(v11 + 3) >> 5) & 1;
if ( v13 == 3 )
v14 = 1;
if ( v14 || !v13 && *(_DWORD *)(v2 + 788) == 3 )
{
if ( !*(_DWORD *)(v11 + 12) )
png_warning(v2, "Writing zero-length unknown chunk");
png_write_chunk(v2, v11, *(_DWORD *)(v11 + 8));
v12 = a2[59];
v9 = a2[60];
}
else
{
LABEL_33:
v12 = a2[59];
v9 = a2[60];
}
}
v11 += 20;
}
while ( v11 < v12 + 20 * v9 );
}
}
}
*(_DWORD *)(v2 + 308) |= 8u;
return png_write_IEND(v2);
}
return result;
}