//
// png_write_iCCP from 0x874a8c to 0x874bd8 (332 bytes)
//
// 1 xrefs:
// > png_write_info_before_PLTE @ 0x8718ee
//
// 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:03:00 +0000
//
int __fastcall png_write_iCCP(int a1, char *a2, unsigned __int8 *a3)
{
unsigned int v4; // r4
unsigned int v6; // r0
unsigned int v7; // r10
int v8; // r10
int v9; // r1
unsigned int v10; // r4
unsigned int v11; // r5
_DWORD *v12; // r6
char *v13; // r1
_BOOL4 v14; // r3
char v16[4]; // [sp+0h] [bp-468h] BYREF
char v17[4]; // [sp+4h] [bp-464h] BYREF
_BYTE v18[84]; // [sp+8h] [bp-460h] BYREF
_DWORD v19[2]; // [sp+5Ch] [bp-40Ch] BYREF
unsigned int v20; // [sp+64h] [bp-404h]
char v21; // [sp+68h] [bp-400h] BYREF
if ( !a3 )
png_error(a1, "No profile for iCCP chunk");
v4 = (a3[1] << 16) + (*a3 << 24) + a3[3] + (a3[2] << 8);
if ( v4 <= 0x83 )
png_error(a1, "ICC profile too short");
if ( a3[8] > 3u && v4 << 30 )
png_error(a1, "ICC profile length invalid (not a multiple of 4)");
v6 = sub_873E7C(a1, a2, v18);
v7 = v6;
if ( !v6 )
png_error(a1, "iCCP: invalid keyword");
v19[0] = a3;
v18[v6 + 1] = 0;
v20 = 0;
v19[1] = v4;
if ( sub_873C6C(a1, 1766015824, v4) || (v8 = v7 + 2, sub_873F70((_DWORD *)a1, (int)v19, v8)) )
png_error(a1, *(const char **)(a1 + 348));
v9 = v20 + v8;
if ( a1 )
{
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v16, v9);
png_save_uint_32(v17, 1766015824);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 1766015824;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v17, 4);
*(_DWORD *)(a1 + 900) = 66;
}
v10 = 1024;
png_write_chunk_data((_DWORD *)a1, (int)v18, v8);
v11 = v20;
v12 = *(_DWORD **)(a1 + 380);
v13 = &v21;
while ( 1 )
{
if ( v10 >= v11 )
v10 = v11;
png_write_chunk_data((_DWORD *)a1, (int)v13, v10);
v11 -= v10;
v14 = v11 == 0;
if ( !v12 )
v14 = 1;
if ( v14 )
break;
v13 = (char *)(v12 + 1);
v10 = *(_DWORD *)(a1 + 384);
v12 = (_DWORD *)*v12;
}
if ( v11 )
png_error(a1, "error writing ancillary chunked compressed data");
return png_write_chunk_end(a1);
}