//
// sub_65C6A4 from 0x65c6a4 to 0x65c7a8 (260 bytes)
//
// 3 xrefs:
// > png_handle_iCCP @ 0x65d218
// > png_handle_iCCP @ 0x65d43a
// > png_handle_iCCP @ 0x65d458
//
// 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
//
int __fastcall sub_65C6A4(_DWORD *a1, int a2, unsigned int *a3, int *a4, int a5)
{
_DWORD *v9; // r9
unsigned int v10; // r8
int v11; // r2
int v12; // r1
int v13; // r5
int v14; // r3
int v15; // r2
int v16; // r2
int v17; // r1
v9 = a1 + 81;
v10 = 1024;
if ( a5 )
{
while ( 1 )
{
if ( !a1[82] )
{
if ( v10 >= *a3 )
v10 = *a3;
*a3 -= v10;
if ( v10 )
png_crc_read(a1, a2, v10);
a1[81] = a2;
a1[82] = v10;
}
if ( !a1[85] )
{
v16 = *a4;
*a4 = 0;
a1[85] = v16;
}
v17 = *a3 ? 0 : 4;
v13 = inflate(v9, v17);
if ( v13 )
break;
if ( !*a4 && !a1[85] )
{
v14 = 0;
v15 = 0;
v13 = 0;
goto LABEL_33;
}
}
}
else
{
while ( 1 )
{
if ( !a1[82] )
{
if ( v10 >= *a3 )
v10 = *a3;
*a3 -= v10;
if ( v10 )
png_crc_read(a1, a2, v10);
a1[81] = a2;
a1[82] = v10;
}
if ( !a1[85] )
{
v11 = *a4;
*a4 = 0;
a1[85] = v11;
}
v12 = *a3 ? 0 : 2;
v13 = inflate(v9, v12);
if ( v13 )
break;
if ( !*a4 && !a1[85] )
{
v14 = 0;
v15 = 0;
v13 = 0;
goto LABEL_33;
}
}
}
v15 = *a4;
v14 = a1[85];
LABEL_33:
*a4 = v14 + v15;
a1[85] = 0;
png_zstream_error((int)a1, v13);
return v13;
}