//
// png_do_invert from 0x870cd8 to 0x870e08 (304 bytes)
//
// 2 xrefs:
// > png_do_read_transformations @ 0x86a6f6
// > png_do_write_transformations @ 0x873664
//
// 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:58 +0000
//
unsigned int __fastcall png_do_invert(unsigned int result, int a2)
{
int v2; // r5
unsigned int v3; // r3
_BYTE *v4; // r2
unsigned int v5; // r4
int v6; // r12
int *v7; // r1
unsigned int v8; // r6
int *v9; // lr
int v10; // t1
int v11; // r3
unsigned int i; // r3
unsigned int v13; // r4
_BYTE *v14; // r1
char v15; // r2
char v16; // r3
if ( *(_BYTE *)(result + 8) )
{
v11 = *(unsigned __int16 *)(result + 8);
if ( v11 == 2052 )
{
result = *(_DWORD *)(result + 4);
if ( result )
{
for ( i = 0; i < result; i += 2 )
*(_BYTE *)(a2 + i) = ~*(_BYTE *)(a2 + i);
}
}
else if ( v11 == 4100 )
{
v13 = *(_DWORD *)(result + 4);
if ( v13 )
{
v14 = (_BYTE *)(a2 + 4);
result = 0;
do
{
v15 = *(v14 - 4);
result += 4;
v16 = *(v14 - 3);
v14 += 4;
*(v14 - 8) = ~v15;
*(v14 - 7) = ~v16;
}
while ( v13 > result );
}
}
}
else
{
result = *(_DWORD *)(result + 4);
if ( !result )
return result;
v3 = -a2 & 3;
if ( v3 >= result )
v3 = result;
if ( result > 4 )
{
if ( !v3 )
{
v4 = (_BYTE *)a2;
v2 = 0;
goto LABEL_15;
}
}
else
{
v3 = result;
}
*(_BYTE *)a2 = ~*(_BYTE *)a2;
v4 = (_BYTE *)(a2 + 1);
if ( v3 == 1 || (v4 = (_BYTE *)(a2 + 2), *(_BYTE *)(a2 + 1) = ~*(_BYTE *)(a2 + 1), v3 == 2) )
{
v2 = v3;
if ( v3 == result )
return result;
goto LABEL_15;
}
v4 = (_BYTE *)(a2 + 3);
if ( v3 != 4 )
v2 = 3;
*(_BYTE *)(a2 + 2) = ~*(_BYTE *)(a2 + 2);
if ( v3 == 4 )
{
v4 = (_BYTE *)(a2 + 4);
v2 = 4;
*(_BYTE *)(a2 + 3) = ~*(_BYTE *)(a2 + 3);
}
if ( v3 != result )
{
LABEL_15:
v5 = ((result - v3 - 4) >> 2) + 1;
v6 = 4 * v5;
if ( result - 1 - v3 <= 2 )
goto LABEL_19;
v7 = (int *)(a2 + v3);
v8 = 0;
v9 = v7 - 1;
do
{
v10 = v9[1];
++v9;
++v8;
*v7++ = ~v10;
}
while ( v5 > v8 );
v4 += v6;
v2 += v6;
if ( result - v3 != v6 )
{
LABEL_19:
*v4 = ~*v4;
if ( result > v2 + 1 )
{
v4[1] = ~v4[1];
if ( result > v2 + 2 )
v4[2] = ~v4[2];
}
}
}
}
return result;
}