//
// png_write_zTXt from 0x6653a4 to 0x6654dc (312 bytes)
//
// 2 xrefs:
// > png_write_info @ 0x661a84
// > png_write_end @ 0x661cf0
//
// 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 png_write_zTXt(int a1, char *a2, const char *a3, int a4)
{
unsigned int v6; // r0
unsigned int v7; // r5
size_t v8; // r3
int v9; // r5
int v10; // r1
unsigned int v11; // r5
_DWORD *v12; // r6
char *v13; // r1
unsigned int v14; // r4
_BOOL4 v15; // r3
char v17[4]; // [sp+0h] [bp-468h] BYREF
char v18[4]; // [sp+4h] [bp-464h] BYREF
_BYTE v19[84]; // [sp+8h] [bp-460h] BYREF
_DWORD v20[2]; // [sp+5Ch] [bp-40Ch] BYREF
unsigned int v21; // [sp+64h] [bp-404h]
char v22; // [sp+68h] [bp-400h] BYREF
if ( a4 == -1 )
return png_write_tEXt((_DWORD *)a1, a2, a3);
if ( a4 )
png_error(a1, "zTXt: invalid compression type");
v6 = sub_663DFC(a1, a2, v19);
v7 = v6;
if ( !v6 )
png_error(a1, "zTXt: invalid keyword");
v19[v6 + 1] = 0;
v8 = (size_t)a3;
if ( a3 )
v8 = strlen(a3);
v20[0] = a3;
v20[1] = v8;
v21 = 0;
if ( sub_663BEC(a1, 2052348020, v8) || (v9 = v7 + 2, sub_663EF0((_DWORD *)a1, (int)v20, v9)) )
png_error(a1, *(const char **)(a1 + 348));
if ( a1 )
{
v10 = v21 + v9;
*(_DWORD *)(a1 + 900) = 34;
png_save_uint_32(v17, v10);
png_save_uint_32(v18, 2052348020);
png_write_data(a1);
*(_DWORD *)(a1 + 476) = 2052348020;
png_reset_crc(a1);
png_calculate_crc((_DWORD *)a1, (int)v18, 4);
*(_DWORD *)(a1 + 900) = 66;
}
png_write_chunk_data((_DWORD *)a1, (int)v19, v9);
v11 = v21;
v12 = *(_DWORD **)(a1 + 380);
v13 = &v22;
v14 = 1024;
while ( 1 )
{
if ( v14 >= v11 )
v14 = v11;
png_write_chunk_data((_DWORD *)a1, (int)v13, v14);
v11 -= v14;
v15 = v11 == 0;
if ( !v12 )
v15 = 1;
if ( v15 )
break;
v13 = (char *)(v12 + 1);
v14 = *(_DWORD *)(a1 + 384);
v12 = (_DWORD *)*v12;
}
if ( v11 )
png_error(a1, "error writing ancillary chunked compressed data");
return png_write_chunk_end(a1);
}