//
// sub_1007021B8 from 0x1007021b8 to 0x100702368 (432 bytes)
//
// 2 xrefs:
// > sub_1007024C0 @ 0x1007024f0
// > ??> @ 0x1009e9240
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// 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 11:12:49 +0000
//
__int64 __fastcall sub_1007021B8(__int64 a1, char *a2, __int64 a3)
{
__int64 v3; // x20
char *v4; // x21
__int64 v6; // x19
__int64 v7; // x24
__int64 v8; // x2
int v9; // w8
int v10; // w9
int v11; // w25
int v12; // w0
unsigned int v13; // w23
int v14; // w9
int v15; // w10
int v16; // w0
int v17; // w23
unsigned int v18; // w8
v3 = a3;
v4 = a2;
v6 = 0;
if ( !a2 || (int)a3 < 1 )
return v6;
v7 = *(_QWORD *)(a1 + 48);
if ( !v7 )
return 0;
if ( !*(_QWORD *)(a1 + 56) )
return 0;
sub_100700768(a1, 15);
v6 = 0;
v8 = *(unsigned int *)(v7 + 32);
v9 = *(_DWORD *)(v7 + 36);
v10 = v9 + v8;
v11 = *(_DWORD *)(v7 + 4) - (v9 + v8);
if ( v11 >= (int)v3 )
{
LABEL_17:
memcpy((void *)(*(_QWORD *)(v7 + 24) + v10), v4, (int)v3);
*(_DWORD *)(v7 + 32) += v3;
return (unsigned int)(v6 + v3);
}
while ( 2 )
{
if ( !(_DWORD)v8 )
{
LABEL_11:
*(_DWORD *)(v7 + 36) = 0;
while ( 1 )
{
v15 = *(_DWORD *)(v7 + 4);
if ( (int)v3 < v15 )
break;
v16 = sub_100700894(*(_QWORD *)(a1 + 56), (__int64)v4, v3);
v17 = v16;
if ( v16 <= 0 )
{
sub_100701210(a1);
if ( (int)v6 <= 0 )
v18 = v17;
else
v18 = v6;
if ( v17 < 0 )
return v18;
else
return (unsigned int)v6;
}
v6 = (unsigned int)(v16 + v6);
v4 += v16;
v3 = (unsigned int)(v3 - v16);
if ( !(_DWORD)v3 )
return v6;
}
v8 = *(unsigned int *)(v7 + 32);
v9 = *(_DWORD *)(v7 + 36);
v10 = v9 + v8;
v11 = v15 - (v9 + v8);
if ( (int)v3 > v11 )
continue;
goto LABEL_17;
}
break;
}
if ( v11 >= 1 )
{
memcpy((void *)(*(_QWORD *)(v7 + 24) + v10), v4, v11);
v4 += v11;
v3 = (unsigned int)(v3 - v11);
v6 = (unsigned int)(v11 + v6);
v9 = *(_DWORD *)(v7 + 36);
v8 = (unsigned int)(*(_DWORD *)(v7 + 32) + v11);
*(_DWORD *)(v7 + 32) = v8;
}
while ( 1 )
{
v12 = sub_100700894(*(_QWORD *)(a1 + 56), *(_QWORD *)(v7 + 24) + v9, v8);
v13 = v12;
if ( v12 <= 0 )
break;
v14 = *(_DWORD *)(v7 + 32);
v9 = *(_DWORD *)(v7 + 36) + v12;
v8 = (unsigned int)(v14 - v12);
*(_DWORD *)(v7 + 32) = v8;
*(_DWORD *)(v7 + 36) = v9;
if ( v14 == v12 )
goto LABEL_11;
}
sub_100701210(a1);
if ( (v13 & 0x80000000) != 0 )
{
if ( (int)v6 <= 0 )
return v13;
else
return (unsigned int)v6;
}
return v6;
}