//
// png_set_text_2 from 0x870204 to 0x870474 (624 bytes)
//
// 4 xrefs:
// > png_handle_tEXt @ 0x86e28a
// > png_handle_zTXt @ 0x86e482
// > png_handle_iTXt @ 0x86e676
// > png_set_text @ 0x870484
//
// 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:02:57 +0000
//
int __fastcall png_set_text_2(int a1, int a2, int a3, signed int a4)
{
bool v4; // zf
bool v5; // cc
size_t v9; // r2
char *v10; // r5
int v11; // r1
signed int v12; // r9
const char **v13; // r10
int v14; // r8
int *v15; // r5
size_t v16; // r4
const char *v17; // r0
const char *v18; // r0
const char *v19; // r0
size_t v20; // r3
size_t v21; // r7
void *v22; // r0
int v23; // r1
size_t v24; // r4
int v25; // r0
void *v26; // r0
void *v27; // r0
_BYTE *v28; // r0
bool v29; // cc
size_t v30; // r2
signed int v32; // r3
size_t v33; // r0
int v34; // r1
unsigned int v35; // r7
char *v36; // r8
int v37; // r3
size_t v38; // [sp+Ch] [bp-3Ch]
size_t v39; // [sp+10h] [bp-38h]
v4 = a2 == 0;
if ( a2 )
v4 = a1 == 0;
if ( v4 )
return 0;
v5 = a3 <= 0;
if ( a3 )
v5 = a4 <= 0;
if ( v5 )
return 0;
v9 = *(_DWORD *)(a2 + 128);
if ( a4 > (int)(*(_DWORD *)(a2 + 132) - v9) )
{
v32 = 0x7FFFFFFF - v9;
if ( a4 > (int)(0x7FFFFFFF - v9)
|| ((v34 = a4 + v9, v34 > 2147483638) ? (v35 = 0x7FFFFFFF) : (v35 = (v34 + 8) & 0xFFFFFFF8, v32 = v35 - v9),
(v36 = png_realloc_array(a1, *(const void **)(a2 + 136), v9, v32, 28)) == nullptr) )
{
png_chunk_report(a1, "too many text chunks", 1);
return 1;
}
png_free(a1, *(void **)(a2 + 136));
v11 = *(_DWORD *)(a2 + 128);
v10 = v36;
v37 = *(_DWORD *)(a2 + 232) | 0x4000;
*(_DWORD *)(a2 + 136) = v36;
*(_DWORD *)(a2 + 132) = v35;
*(_DWORD *)(a2 + 232) = v37;
}
else
{
v10 = *(char **)(a2 + 136);
v11 = *(_DWORD *)(a2 + 128);
}
v12 = 0;
v13 = (const char **)(a3 + 4);
while ( 1 )
{
if ( !*v13 )
goto LABEL_28;
v14 = (int)*(v13 - 1);
if ( (unsigned int)(v14 + 1) <= 3 )
break;
++v12;
png_chunk_report(a1, "text compression mode is out of range", 1);
v13 += 7;
if ( a4 <= v12 )
return 0;
LABEL_29:
v10 = *(char **)(a2 + 136);
v11 = *(_DWORD *)(a2 + 128);
}
v15 = (int *)&v10[28 * v11];
v16 = strlen(*v13);
if ( v14 > 0 )
{
v17 = v13[4];
if ( v17 )
{
v38 = strlen(v17);
v18 = v13[5];
if ( v18 )
{
LABEL_15:
v39 = strlen(v18);
LABEL_16:
v19 = v13[1];
if ( !v19 || !*v19 )
{
v20 = v38;
v21 = 0;
*v15 = 1;
goto LABEL_19;
}
goto LABEL_38;
}
}
else
{
v38 = 0;
v18 = v13[5];
if ( v18 )
goto LABEL_15;
}
v39 = (size_t)v18;
goto LABEL_16;
}
v19 = v13[1];
if ( v19 && *v19 )
{
v39 = 0;
v38 = 0;
LABEL_38:
v33 = strlen(v19);
*v15 = v14;
v20 = v38;
v21 = v33;
goto LABEL_19;
}
v20 = 0;
v39 = 0;
v21 = 0;
v38 = 0;
*v15 = -1;
LABEL_19:
v22 = png_malloc_base(a1, v16 + 4 + v21 + v20 + v39);
v15[1] = (int)v22;
if ( v22 )
{
memcpy(v22, *v13, v16);
*(_BYTE *)(v15[1] + v16) = 0;
v24 = v16 + 1;
v25 = v15[1];
if ( (int)*(v13 - 1) <= 0 )
{
v28 = (_BYTE *)(v25 + v24);
v15[5] = 0;
v15[6] = 0;
v15[2] = (int)v28;
if ( !v21 )
goto LABEL_22;
}
else
{
v26 = (void *)(v25 + v24);
v15[5] = (int)v26;
memcpy(v26, v13[4], v38);
*(_BYTE *)(v15[5] + v38) = 0;
v27 = (void *)(v15[5] + v38 + 1);
v15[6] = (int)v27;
memcpy(v27, v13[5], v39);
v23 = v15[6];
*(_BYTE *)(v23 + v39) = 0;
v28 = (_BYTE *)(v15[6] + v39 + 1);
v15[2] = (int)v28;
if ( !v21 )
{
LABEL_22:
v28[v21] = 0;
v29 = *v15 <= 0;
if ( *v15 <= 0 )
{
v30 = 0;
v23 = v21;
}
else
{
v30 = v21;
}
v15[4] = v30;
if ( !v29 )
v23 = 0;
v15[3] = v23;
++*(_DWORD *)(a2 + 128);
LABEL_28:
++v12;
v13 += 7;
if ( a4 <= v12 )
return 0;
goto LABEL_29;
}
}
memcpy(v28, v13[1], v21);
v28 = (_BYTE *)v15[2];
goto LABEL_22;
}
png_chunk_report(a1, "text chunk: out of memory", 1);
return 1;
}