//
// gzwrite from 0x9512f0 to 0x9514c2 (466 bytes)
//
// 2 xrefs:
// > gzputc @ 0x951548
// > gzputs @ 0x951678
//
// 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:05:24 +0000
//
int __fastcall gzwrite(int a1, char *a2, int a3)
{
unsigned int v3; // r5
int v5; // r9
unsigned int v8; // r3
int v9; // r3
int v10; // r2
int v11; // r6
int v12; // r0
void *v13; // r0
size_t v14; // r6
int v15; // r3
int v16; // r3
signed int v17; // r10
int i; // r2
signed int v19; // r3
int v20; // r7
size_t v21; // r7
int v22; // r1
int v23; // r2
int v24; // r3
_BYTE *v25; // r1
_BYTE *v26; // r2
int v27; // r11
int v28; // r11
int v29; // r3
ssize_t v30; // r0
ssize_t v31; // r0
int *v32; // r0
char *v33; // r0
if ( !a1 )
return 0;
v3 = a3;
if ( *(_DWORD *)(a1 + 12) != 31153 || *(_DWORD *)(a1 + 76) )
return 0;
v5 = a3;
if ( a3 < 0 )
{
v5 = *(_DWORD *)(a1 + 76);
sub_950728((_DWORD *)a1, -3, "requested length does not fit in int");
return v5;
}
if ( !a3 || !*(_DWORD *)(a1 + 24) && sub_951010(a1) == -1 )
return 0;
if ( *(_DWORD *)(a1 + 72) )
{
v16 = *(_DWORD *)(a1 + 88);
v17 = *(_DWORD *)(a1 + 68);
*(_DWORD *)(a1 + 72) = 0;
if ( v16 && sub_951234(a1) == -1 )
return 0;
for ( i = 1; v17; i = 0 )
{
v19 = *(_DWORD *)(a1 + 24);
v20 = (unsigned int)v19 >> 31;
if ( v19 > v17 )
v20 = 1;
if ( v20 )
v21 = v17;
else
v21 = *(_DWORD *)(a1 + 24);
if ( i )
{
memset(*(void **)(a1 + 32), 0, v21);
v19 = *(_DWORD *)(a1 + 24);
}
v22 = *(_DWORD *)(a1 + 32);
v23 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 88) = v21;
*(_DWORD *)(a1 + 84) = v22;
*(_DWORD *)(a1 + 8) = v23 + v21;
if ( !v19 && sub_951010(a1) == -1 )
return 0;
if ( !*(_DWORD *)(a1 + 40) )
{
v24 = *(_DWORD *)(a1 + 100);
while ( 1 )
{
if ( v24 )
{
v28 = v24;
}
else
{
v25 = *(_BYTE **)(a1 + 4);
v26 = *(_BYTE **)(a1 + 96);
v27 = v26 - v25;
if ( v26 == v25 )
goto LABEL_40;
v30 = write(*(_DWORD *)(a1 + 16), v25, v26 - v25);
if ( v30 < 0 || v27 != v30 )
goto LABEL_57;
v28 = *(_DWORD *)(a1 + 100);
if ( !v28 )
{
LABEL_40:
v28 = *(_DWORD *)(a1 + 24);
v29 = *(_DWORD *)(a1 + 36);
*(_DWORD *)(a1 + 100) = v28;
*(_DWORD *)(a1 + 96) = v29;
}
else
{
v29 = *(_DWORD *)(a1 + 96);
}
*(_DWORD *)(a1 + 4) = v29;
}
if ( deflate(a1 + 84, 0) == -2 )
break;
v24 = *(_DWORD *)(a1 + 100);
if ( v24 == v28 )
goto LABEL_44;
}
sub_950728((_DWORD *)a1, -2, "internal error: deflate stream corrupt");
return 0;
}
v31 = write(*(_DWORD *)(a1 + 16), *(const void **)(a1 + 84), *(_DWORD *)(a1 + 88));
if ( v31 < 0 || v31 != *(_DWORD *)(a1 + 88) )
{
LABEL_57:
v32 = (int *)_errno();
v33 = strerror(*v32);
sub_950728((_DWORD *)a1, -1, v33);
return 0;
}
*(_DWORD *)(a1 + 88) = 0;
LABEL_44:
v17 -= v21;
}
}
v8 = *(_DWORD *)(a1 + 24);
if ( v3 < v8 )
{
v10 = *(_DWORD *)(a1 + 88);
v11 = *(_DWORD *)(a1 + 32);
if ( !v10 )
goto LABEL_22;
LABEL_16:
v12 = *(_DWORD *)(a1 + 84);
while ( 1 )
{
v13 = (void *)(v12 + v10);
v14 = v8 - ((unsigned int)v13 - v11);
if ( v14 >= v3 )
v14 = v3;
memcpy(v13, a2, v14);
v15 = *(_DWORD *)(a1 + 8);
v3 -= v14;
*(_DWORD *)(a1 + 88) += v14;
*(_DWORD *)(a1 + 8) = v15 + v14;
if ( !v3 )
break;
a2 += v14;
if ( sub_951234(a1) == -1 )
return 0;
v10 = *(_DWORD *)(a1 + 88);
v8 = *(_DWORD *)(a1 + 24);
v11 = *(_DWORD *)(a1 + 32);
if ( v10 )
goto LABEL_16;
LABEL_22:
v12 = v11;
*(_DWORD *)(a1 + 84) = v11;
}
}
else
{
if ( *(_DWORD *)(a1 + 88) && sub_951234(a1) == -1 )
return 0;
v9 = *(_DWORD *)(a1 + 8);
*(_DWORD *)(a1 + 88) = v3;
*(_DWORD *)(a1 + 84) = a2;
*(_DWORD *)(a1 + 8) = v9 + v3;
if ( sub_951234(a1) == -1 )
return 0;
}
return v5;
}