//
// sub_180081BE0 from 0x180081be0 to 0x180081f1f (831 bytes)
//
// 2 xrefs:
// > pugi::xml_document::load @ 0x180084231
// > ??> @ 0x1801bf220
//
// 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
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall sub_180081BE0(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
int v5; // ebp
__int64 v7; // r12
char *v9; // r14
unsigned __int64 v10; // r15
_QWORD *v11; // rax
int v12; // ebx
int v13; // eax
_QWORD *v14; // rax
__int64 v15; // r13
void (__cdecl *v16)(void *); // r12
char *v17; // rax
char *v18; // rbp
char v19; // r8
char v20; // cl
char v21; // al
char v22; // dl
bool v23; // zf
__int128 v25; // [rsp+30h] [rbp-78h] BYREF
__int64 v26; // [rsp+40h] [rbp-68h]
__int128 v27; // [rsp+50h] [rbp-58h] BYREF
__int64 v28; // [rsp+60h] [rbp-48h]
char *v30; // [rsp+C0h] [rbp+18h] BYREF
int v31; // [rsp+C8h] [rbp+20h]
v31 = a4;
v5 = a4;
v7 = a2;
v9 = nullptr;
v30 = nullptr;
v10 = 0;
*(_QWORD *)&v25 = 0;
if ( !std::ios_base::fail((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL))) )
{
v11 = (_QWORD *)std::istream::tellg(a3, &v27);
v12 = 2;
if ( (__int64)(*v11 + v11[1]) < 0 )
{
std::ios::clear(a3 + *(int *)(*(_QWORD *)a3 + 4LL), 0, 0);
v13 = sub_180081860(a3, &v30, (unsigned __int64 *)&v25);
v9 = v30;
v10 = v25;
goto LABEL_16;
}
std::istream::tellg(a3, &v27);
std::istream::seekg(a3, 0, 2);
v14 = (_QWORD *)std::istream::tellg(a3, &v25);
v15 = *v14 + v14[1] - *((_QWORD *)&v27 + 1) - v27;
v25 = v27;
v26 = v28;
std::istream::seekg(a3, &v25);
if ( !std::ios_base::fail((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL)))
&& (__int64)(*((_QWORD *)&v27 + 1) + v27) >= 0 )
{
if ( v15 < 0 )
{
v13 = 3;
LABEL_16:
if ( v13 )
{
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)a1 = v13;
*(_QWORD *)(a1 + 8) = 0;
return a1;
}
if ( a5 == 8 || a5 == 4 )
{
LABEL_53:
pugi::xml_document::load_buffer_inplace_own(v7, a1, v9, v10, v5, v12);
return a1;
}
if ( a5 == 7 )
{
v12 = 5;
goto LABEL_53;
}
if ( a5 )
{
v12 = a5;
goto LABEL_51;
}
if ( v10 < 4 )
{
v12 = 1;
goto LABEL_52;
}
v19 = *v9;
v20 = v9[1];
v21 = v9[2];
v22 = v9[3];
if ( !*v9 )
{
if ( !v20 )
{
if ( v21 == -2 )
{
if ( v22 == -1 )
{
v12 = 6;
goto LABEL_51;
}
}
else if ( !v21 && v22 == 60 )
{
v12 = 6;
goto LABEL_51;
}
goto LABEL_50;
}
if ( v20 == 60 )
{
if ( !v21 && v22 == 63 )
{
v12 = 3;
goto LABEL_51;
}
goto LABEL_47;
}
goto LABEL_50;
}
switch ( v19 )
{
case -1:
v23 = v20 == -2;
break;
case -2:
if ( v20 == -1 )
{
LABEL_47:
v12 = 3;
goto LABEL_51;
}
LABEL_50:
v12 = 1;
goto LABEL_51;
case 60:
v23 = v20 == 0;
break;
default:
goto LABEL_50;
}
if ( v23 )
{
if ( !v21 && !v22 )
v12 = 5;
LABEL_51:
if ( v12 != 1 )
goto LABEL_53;
LABEL_52:
v9[v10++] = 0;
goto LABEL_53;
}
goto LABEL_50;
}
v16 = off_1801ACF78;
v17 = (char *)off_1801ACF70(v15 + 1);
v18 = v17;
*(_QWORD *)&v25 = v17;
*((_QWORD *)&v25 + 1) = v16;
if ( !v17 )
{
v13 = 3;
v5 = v31;
v7 = a2;
goto LABEL_16;
}
std::istream::read(a3, v17, v15);
if ( !std::ios_base::bad((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL)))
&& (std::ios_base::eof((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL)))
|| !std::ios_base::fail((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL)))) )
{
v10 = std::istream::gcount(a3);
v9 = v18;
v13 = 0;
v5 = v31;
v7 = a2;
goto LABEL_16;
}
v16(v18);
v5 = v31;
v7 = a2;
}
v13 = 2;
goto LABEL_16;
}
*(_DWORD *)(a1 + 16) = 0;
*(_DWORD *)a1 = 2;
*(_QWORD *)(a1 + 8) = 0;
return a1;
}