//
// png_write_info_before_PLTE from 0xbe6bfc to 0xbe6e20 (548 bytes)
//
// 2 xrefs:
// > png_write_info @ 0xbe6e44
// > ??> @ 0x41460
//
// 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
//
_DWORD *__fastcall png_write_info_before_PLTE(_DWORD *result, unsigned int *a2)
{
_DWORD *v2; // x21
__int16 v4; // w0
unsigned int v5; // w1
signed int v6; // w1
unsigned __int64 v7; // x20
__int64 v8; // x2
int v9; // w0
if ( !result || !a2 || (result[89] & 0x400) != 0 )
return result;
v2 = result;
png_write_sig();
if ( (v2[89] & 0x1000) != 0 && v2[276] )
{
png_warning((__int64)v2, "MNG features are not allowed in a PNG datastream");
v2[276] = 0;
}
png_write_IHDR(
v2,
*a2,
a2[1],
*((unsigned __int8 *)a2 + 36),
*((unsigned __int8 *)a2 + 37),
*((unsigned __int8 *)a2 + 38),
*((unsigned __int8 *)a2 + 39),
*((unsigned __int8 *)a2 + 40));
v4 = *((_WORD *)a2 + 63);
if ( v4 < 0 )
{
LABEL_23:
if ( (a2[2] & 2) == 0 )
goto LABEL_20;
goto LABEL_24;
}
if ( (v4 & 8) == 0 )
{
LABEL_25:
v5 = a2[2];
goto LABEL_11;
}
v5 = a2[2];
if ( (v5 & 1) != 0 )
{
png_write_gAMA_fixed(v2, a2[13]);
v4 = *((_WORD *)a2 + 63);
if ( v4 < 0 )
goto LABEL_23;
goto LABEL_25;
}
LABEL_11:
if ( (v5 & 0x1000) != 0 )
{
if ( (v5 & 0x800) != 0 )
png_app_warning((__int64)v2, "profile matches sRGB but writing iCCP instead");
png_write_iCCP(v2, *((_QWORD *)a2 + 16), *((_QWORD *)a2 + 17));
LABEL_15:
if ( (a2[2] & 2) == 0 )
goto LABEL_16;
goto LABEL_24;
}
if ( (v5 & 0x800) != 0 )
{
png_write_sRGB(v2, *((unsigned __int16 *)a2 + 62));
goto LABEL_15;
}
if ( (v5 & 2) == 0 )
goto LABEL_17;
LABEL_24:
png_write_sBIT(v2, a2 + 44, *((unsigned __int8 *)a2 + 37));
LABEL_16:
v4 = *((_WORD *)a2 + 63);
if ( (v4 & 0x8000) == 0 )
{
LABEL_17:
if ( (v4 & 0x10) != 0 && (a2[2] & 4) != 0 )
png_write_cHRM_fixed(v2, a2 + 14);
}
LABEL_20:
v6 = a2[74];
if ( v6 )
{
v7 = *((_QWORD *)a2 + 36);
if ( v7 < v7 + 32LL * v6 )
{
v8 = *((_QWORD *)a2 + 36);
do
{
if ( (*(_BYTE *)(v7 + 24) & 1) != 0 )
{
v9 = png_handle_as_unknown((__int64)v2, (void *)v7);
if ( v9 != 1 && (v9 == 3 || (*(_BYTE *)(v7 + 3) & 0x20) != 0 || !v9 && v2[270] == 3) )
{
if ( !*(_QWORD *)(v7 + 16) )
png_warning((__int64)v2, "Writing zero-length unknown chunk");
png_write_chunk(v2, v7, *(_QWORD *)(v7 + 8));
v8 = *((_QWORD *)a2 + 36);
v6 = a2[74];
}
else
{
v8 = *((_QWORD *)a2 + 36);
v6 = a2[74];
}
}
v7 += 32LL;
}
while ( v7 < v8 + 32LL * v6 );
}
}
result = (_DWORD *)(v2[89] | 0x400u);
v2[89] = (_DWORD)result;
return result;
}