//
// sub_D79468 from 0xd79468 to 0xd795a8 (320 bytes)
//
// 2 xrefs:
// > ??> @ 0x1122490
// > ??> @ 0x11224e0
//
// 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_D79468(__int64 a1, _BYTE *a2, int a3)
{
_QWORD *v4; // x21
int v6; // w19
unsigned __int8 *v7; // x2
int v8; // w3
int v9; // w4
__int64 v10; // x21
__int64 result; // x0
__int64 v12; // x0
__int64 v13; // x2
v4 = *(_QWORD **)(*(_QWORD *)(a1 + 48) + 8LL);
BIO_clear_flags(a1, 15);
v6 = a3 - 1;
if ( a3 > (int)*v4 )
v6 = *v4;
if ( v6 <= 0 )
{
*a2 = 0;
return 0;
}
v7 = (unsigned __int8 *)v4[1];
v8 = 0;
while ( 1 )
{
v9 = *v7++;
if ( v9 == 10 )
break;
if ( ++v8 == v6 )
goto LABEL_7;
}
v6 = v8 + 1;
LABEL_7:
v10 = *(_QWORD *)(*(_QWORD *)(a1 + 48) + 8LL);
BIO_clear_flags(a1, 15);
if ( *(_QWORD *)v10 < (unsigned __int64)v6 )
v6 = *(_QWORD *)v10;
if ( v6 > 0 && a2 )
{
memcpy(a2, *(const void **)(v10 + 8), v6);
v12 = v6;
v13 = *(_QWORD *)(v10 + 8);
*(_QWORD *)v10 -= v6;
*(_QWORD *)(v10 + 8) = v13 + v6;
goto LABEL_17;
}
if ( !*(_QWORD *)v10 )
{
v6 = *(_DWORD *)(a1 + 40);
result = 0;
if ( !v6 )
return result;
BIO_set_flags(a1, 9);
}
result = (unsigned int)v6;
if ( v6 > 0 )
{
v12 = v6;
LABEL_17:
a2[v12] = 0;
return (unsigned int)v6;
}
return result;
}