//
// sub_D7870 from 0xd7870 to 0xd7968 (248 bytes)
//
// 1 xrefs:
// > sub_7DFE4 @ 0x7e000
//
// 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 12:14:53 +0000
//
__int64 __fastcall sub_D7870(__int64 a1, char *a2, int a3, char a4)
{
__int64 v5; // x19
int v7; // w21
int v8; // w8
__int64 v9; // x9
__int64 v10; // x8
size_t v11; // x23
const void *v12; // x1
char *v13; // x0
size_t v14; // x2
v5 = a1;
if ( *(_DWORD *)(a1 + 20) < a3 )
{
a1 = ((__int64 (*)(void))sub_D7B90)();
a3 = 0;
}
v7 = (*(_DWORD *)(v5 + 44) - *(_DWORD *)(v5 + 40)) * *(_DWORD *)(v5 + 24);
if ( a3 <= v7 )
{
v7 = a3;
}
else
{
sub_D7B90(a1);
v8 = *(_DWORD *)(v5 + 36);
if ( v8 < *(_DWORD *)(v5 + 16) / *(_DWORD *)(v5 + 8) )
*(_DWORD *)(v5 + 36) = v8 + 1;
}
v9 = *(int *)(v5 + 20);
v10 = *(int *)(v5 + 24) * (__int64)*(int *)(v5 + 32);
if ( (int)v10 + v7 <= (int)v9 )
{
v14 = v7;
v13 = a2;
v12 = (const void *)(*(_QWORD *)v5 + (int)v10);
}
else
{
v11 = v9 - (int)v10;
memcpy(a2, (const void *)(*(_QWORD *)v5 + v10), v11);
v12 = *(const void **)v5;
v13 = &a2[v11];
v14 = v7 - (int)v11;
}
memcpy(v13, v12, v14);
if ( (a4 & 1) != 0 )
sub_D7968(v5, (unsigned int)v7);
return (unsigned int)v7;
}