//
// sub_1005E9F2C from 0x1005e9f2c to 0x1005ea0a0 (372 bytes)
//
// 1 xrefs:
// > ??> @ 0x100861768
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __fastcall sub_1005E9F2C(__int64 a1, char *a2, __int64 a3)
{
unsigned int *v6; // x22
unsigned int v7; // w8
__int64 v8; // x23
__int64 v9; // x0
__int64 v10; // x24
int v11; // w28
int v12; // w25
__int64 v13; // x26
unsigned int v14; // w8
int v15; // w0
unsigned int v16; // w27
v6 = *(unsigned int **)(a1 + 48);
sub_1005DA600(a1, 15);
v7 = v6[1];
v8 = *v6 - v7;
if ( (int)v8 < 1 )
{
LABEL_4:
v10 = 0;
if ( a2 && (int)a3 >= 1 )
{
v6[1] = 0;
v11 = a3;
while ( 1 )
{
v12 = v11 <= 4096 ? v11 : 4096;
sub_1005E3B20((__int64)(v6 + 6), (_DWORD)v6 + 192, (int)v6, a2);
v11 -= v12;
v6[1] = 0;
v13 = *v6;
if ( (int)v13 >= 1 )
break;
LABEL_15:
a2 += v12;
*(_QWORD *)v6 = 0;
if ( v11 <= 0 )
{
sub_1005DB0A8(a1);
return a3;
}
}
v14 = 0;
while ( 1 )
{
v15 = sub_1005DA72C(*(_QWORD *)(a1 + 56), (__int64)v6 + (int)v14 + 192, v13);
v16 = v15;
if ( v15 <= 0 )
break;
v13 = (unsigned int)(v13 - v15);
v14 = v6[1] + v15;
v6[1] = v14;
if ( (int)v13 <= 0 )
goto LABEL_15;
}
sub_1005DB0A8(a1);
if ( v11 == (_DWORD)a3 )
return v16;
else
return (unsigned int)(a3 - v11);
}
}
else
{
while ( 1 )
{
v9 = sub_1005DA72C(*(_QWORD *)(a1 + 56), (__int64)v6 + (int)v7 + 192, v8);
v10 = v9;
if ( (int)v9 <= 0 )
break;
v7 = v6[1] + v9;
v6[1] = v7;
v8 = (unsigned int)(v8 - v9);
if ( (int)v8 <= 0 )
goto LABEL_4;
}
sub_1005DB0A8(a1);
}
return v10;
}