//
// sub_9E4F9C from 0x9e4f9c to 0x9e5114 (376 bytes)
//
// 2 xrefs:
// > sub_9E5114 @ 0x9e5120
// > sub_9E512C @ 0x9e515c
//
// 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:07:22 +0000
//
int __fastcall sub_9E4F9C(int a1, char *a2, signed int a3)
{
_DWORD *v3; // r5
int v5; // r8
signed int v8; // r12
int v9; // r2
int v10; // r3
int v11; // r0
signed int v12; // r6
bool v13; // zf
int v14; // r0
int v15; // r6
int v17; // r0
v3 = *(_DWORD **)(a1 + 32);
if ( !v3 )
return 0;
v5 = *(_DWORD *)(a1 + 36);
if ( !v5 )
return v5;
v5 = 0;
BIO_clear_flags(a1, 15);
v8 = v3[1];
while ( 1 )
{
v9 = v3[6];
v10 = v3[7];
v11 = v9 + v10;
v12 = v8 - (v9 + v10);
if ( v12 >= a3 )
{
memcpy((void *)(v3[5] + v11), a2, a3);
v3[6] += a3;
return v5 + a3;
}
if ( v9 )
break;
LABEL_13:
v3[7] = 0;
while ( a3 >= v8 )
{
v17 = BIO_write(*(_DWORD *)(a1 + 36), a2, a3, v10);
v15 = v17;
if ( v17 <= 0 )
{
BIO_copy_next_retry(a1);
if ( !v15 )
return v5;
goto LABEL_19;
}
a3 -= v17;
v5 += v17;
a2 += v17;
if ( !a3 )
return v5;
v8 = v3[1];
}
}
if ( v12 > 0 )
{
memcpy((void *)(v3[5] + v11), a2, v12);
v10 = v3[7];
v9 = v12 + v3[6];
a3 -= v12;
v5 += v12;
a2 += v12;
v3[6] = v9;
}
while ( 1 )
{
v14 = BIO_write(*(_DWORD *)(a1 + 36), v3[5] + v10, v9, v10);
v15 = v14;
if ( v14 <= 0 )
break;
v9 = v3[6] - v14;
v10 = v14 + v3[7];
v13 = v3[6] == v14;
v3[6] = v9;
v3[7] = v10;
if ( v13 )
{
v8 = v3[1];
goto LABEL_13;
}
}
BIO_copy_next_retry(a1);
if ( !v15 )
return v5;
LABEL_19:
if ( v5 )
return v5;
else
return v15;
}