//
// png_handle_pCAL from 0xbe0ce8 to 0xbe1034 (844 bytes)
//
// 4 xrefs:
// > png_push_read_chunk @ 0xbcf8f8
// > png_read_info @ 0xbd3634
// > png_read_end @ 0xbd5bb4
// > ??> @ 0xa8300
//
// 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
//
void __fastcall png_handle_pCAL(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // w1
__int64 v6; // x19
_BYTE *v7; // x21
unsigned __int64 v8; // x23
unsigned __int64 v9; // x25
unsigned __int8 *v10; // x19
int v12; // w27
int v13; // w24
unsigned int v14; // w5
int v15; // w28
_BYTE *v16; // x0
int v17; // w0
unsigned __int8 *v18; // x19
unsigned __int8 *v19; // x23
_QWORD *v21; // x26
__int64 v22; // x7
unsigned __int8 *v23; // x0
int v24; // [xsp+78h] [xbp+68h]
unsigned int v25; // [xsp+78h] [xbp+68h]
v4 = *(_DWORD *)(a1 + 356);
v6 = a3;
if ( (v4 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v4 & 4) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
png_chunk_benign_error(a1, "out of place");
return;
}
if ( a2 && (*(_DWORD *)(a2 + 8) & 0x400) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
png_chunk_benign_error(a1, "duplicate");
return;
}
v7 = *(_BYTE **)(a1 + 1232);
v8 = a3 + 1;
if ( v7 )
{
if ( v8 <= *(_QWORD *)(a1 + 1240) )
goto LABEL_7;
*(_QWORD *)(a1 + 1232) = 0;
*(_QWORD *)(a1 + 1240) = 0;
png_free(a1, v7);
}
v16 = png_malloc_base(a1, (unsigned int)(v6 + 1));
v7 = v16;
if ( !v16 )
{
png_crc_finish((_DWORD *)a1, v6);
goto LABEL_22;
}
*(_QWORD *)(a1 + 1232) = v16;
*(_QWORD *)(a1 + 1240) = v8;
LABEL_7:
png_crc_read(a1, (__int64)v7, v6);
if ( png_crc_finish((_DWORD *)a1, 0) )
return;
v7[v6] = 0;
v9 = (unsigned __int64)&v7[v6];
v10 = v7;
if ( *v7 )
{
while ( *++v10 )
;
}
if ( v9 <= (unsigned __int64)(v10 + 12) )
{
png_chunk_benign_error(a1, "invalid");
return;
}
v12 = (v10[2] << 16) + (v10[1] << 24) + v10[4] + (v10[3] << 8);
v13 = v10[10];
v14 = v10[9];
v15 = (v10[6] << 16) + (v10[5] << 24) + v10[8] + (v10[7] << 8);
if ( v13 != 2 && !v10[9] || (unsigned __int8)(v14 - 1) <= 1u && v13 != 3 || v13 != 4 && v14 == 3 )
{
png_chunk_benign_error(a1, "invalid parameter count");
return;
}
if ( v14 > 3 )
{
v25 = v10[9];
png_chunk_benign_error(a1, "unrecognized equation type");
v14 = v25;
}
v17 = v10[11];
v18 = v10 + 11;
v19 = v18;
if ( v17 )
{
while ( *++v19 )
;
}
v24 = v14;
v21 = png_malloc_warn(a1, 8LL * (unsigned __int8)v13);
if ( !v21 )
{
LABEL_22:
png_chunk_benign_error(a1, "out of memory");
return;
}
v22 = 0;
if ( v13 )
{
while ( 1 )
{
v23 = v19 + 1;
v21[v22] = v19 + 1;
if ( v9 < (unsigned __int64)(v19 + 1) )
break;
if ( v19[1] )
{
while ( ++v23 != (unsigned __int8 *)(v9 + 1) )
{
if ( !*v23 )
goto LABEL_38;
}
break;
}
LABEL_38:
++v22;
v19 = v23;
if ( v13 <= (int)v22 )
goto LABEL_39;
}
png_free(a1, v21);
png_chunk_benign_error(a1, "invalid data");
}
else
{
LABEL_39:
png_set_pCAL(a1, a2, v7, v12, v15, v24, v13, (int)v18, (__int64)v21);
png_free(a1, v21);
}
}