//
// sub_180081A20 from 0x180081a20 to 0x180081bd3 (435 bytes)
//
// 2 xrefs:
// > sub_180081F20 @ 0x180081fc0
// > ??> @ 0x1801bf214
//
// This function is hookable on this platform (idp: pc, 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:22:02 +0000
//
__int64 __fastcall sub_180081A20(__int64 a1, _QWORD *a2, unsigned __int64 *a3)
{
unsigned int v6; // ebp
_QWORD *v7; // rdi
unsigned __int64 v8; // r15
_QWORD *i; // r14
_QWORD *v10; // rax
_QWORD *v11; // rbx
char *v12; // rax
void *v13; // r14
char *v14; // rsi
_QWORD *j; // rbx
_QWORD *v16; // rbx
v6 = 0;
v7 = nullptr;
v8 = 0;
for ( i = nullptr; !std::ios_base::eof((std::ios_base *)(a1 + *(int *)(*(_QWORD *)a1 + 4LL))); v8 += v11[1] )
{
v10 = off_1801ACF70(0x8010u);
v11 = v10;
*v10 = 0;
v10[1] = 0;
if ( !v10 )
goto LABEL_12;
if ( i )
*i = v10;
else
v7 = v10;
i = v10;
std::wistream::read(a1, v10 + 2, 0x4000);
v11[1] = 2 * std::wistream::gcount(a1);
if ( std::ios_base::bad((std::ios_base *)(a1 + *(int *)(*(_QWORD *)a1 + 4LL)))
|| !std::ios_base::eof((std::ios_base *)(a1 + *(int *)(*(_QWORD *)a1 + 4LL)))
&& std::ios_base::fail((std::ios_base *)(a1 + *(int *)(*(_QWORD *)a1 + 4LL))) )
{
v6 = 2;
goto LABEL_17;
}
if ( v8 + v11[1] < v8 )
goto LABEL_12;
}
v12 = (char *)off_1801ACF70(v8 + 1);
v13 = v12;
if ( !v12 )
{
LABEL_12:
v6 = 3;
goto LABEL_17;
}
v14 = v12;
for ( j = v7; j; j = (_QWORD *)*j )
{
memcpy(v14, j + 2, j[1]);
v14 += j[1];
}
*a2 = v13;
*a3 = v8;
LABEL_17:
if ( v7 )
{
do
{
v16 = (_QWORD *)*v7;
off_1801ACF78(v7);
v7 = v16;
}
while ( v16 );
}
return v6;
}