//
// png_handle_hIST from 0xbe0904 to 0xbe0a64 (352 bytes)
//
// 4 xrefs:
// > png_push_read_chunk @ 0xbcf880
// > png_read_info @ 0xbd3614
// > png_read_end @ 0xbd5b84
// > ??> @ 0x77b50
//
// 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
//
__int64 __fastcall png_handle_hIST(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // x0
int v6; // w1
unsigned int v7; // w0
_WORD *v8; // x19
_WORD *v9; // x22
_BYTE v10[8]; // [xsp+48h] [xbp+48h] BYREF
_WORD v11[256]; // [xsp+50h] [xbp+50h] BYREF
if ( (*(_DWORD *)(a1 + 356) & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (*(_DWORD *)(a1 + 356) & 6) == 2 )
{
if ( a2 && (*(_DWORD *)(a2 + 8) & 0x40) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "duplicate");
}
else
{
v6 = *(unsigned __int16 *)(a1 + 672);
v7 = a3 >> 1;
if ( a3 >> 1 == v6 && v7 <= 0x100 )
{
if ( v7 )
{
v8 = v11;
v9 = &v11[v7];
do
{
png_crc_read(a1, (__int64)v10, 2u);
*v8++ = (v10[0] << 8) + v10[1];
}
while ( v8 != v9 );
}
result = png_crc_finish((_DWORD *)a1, 0);
if ( !(_DWORD)result )
return png_set_hIST(a1, a2, v11);
}
else
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "invalid");
}
}
}
else
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "out of place");
}
return result;
}