//
// sub_18007ECE0 from 0x18007ece0 to 0x18007efed (781 bytes)
//
// 2 xrefs:
// > pugi::xml_document::load @ 0x180081251
// > ??> @ 0x1801b4f5c
//
// 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
//
// Hidden C++ exception states: #wind=2
__int64 __fastcall sub_18007ECE0(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
_QWORD *v9; // rax
int v10; // ebx
int v11; // eax
char *v12; // r14
unsigned __int64 v13; // r9
_QWORD *v14; // rax
__int64 v15; // rbp
void (__cdecl *v16)(void *); // r15
char *v17; // rax
char v18; // r8
char v19; // cl
char v20; // al
char v21; // dl
bool v22; // zf
unsigned __int64 v24; // [rsp+30h] [rbp-78h] BYREF
__int128 v25; // [rsp+40h] [rbp-68h] BYREF
__int64 v26; // [rsp+50h] [rbp-58h]
__int128 v27; // [rsp+60h] [rbp-48h] BYREF
__int64 v28; // [rsp+70h] [rbp-38h]
char *v29; // [rsp+C0h] [rbp+18h] BYREF
v29 = nullptr;
v24 = 0;
if ( std::ios_base::fail((std::ios_base *)(a3 + *(int *)(*(_QWORD *)a3 + 4LL))) )
{
*(_DWORD *)a1 = 2;
LABEL_53:
*(_QWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 16) = 0;
return a1;
}
v9 = (_QWORD *)std::istream::tellg(a3, &v27);
v10 = 2;
if ( (__int64)(*v9 + v9[1]) >= 0 )
{
std::istream::tellg(a3, &v27);
std::istream::seekg(a3, 0, 2);
v14 = (_QWORD *)std::istream::tellg(a3, &v25);
v15 = *v14 + v14[1] - (v27 + *((_QWORD *)&v27 + 1));
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 )
{
v11 = 3;
goto LABEL_52;
}
v16 = off_1801A2FA8;
v17 = (char *)off_1801A2FA0(v15 + 1);
v12 = v17;
*(_QWORD *)&v25 = v17;
*((_QWORD *)&v25 + 1) = v16;
if ( !v17 )
{
v11 = 3;
goto LABEL_52;
}
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)))) )
{
v13 = std::istream::gcount(a3);
goto LABEL_15;
}
v16(v12);
}
v11 = 2;
goto LABEL_52;
}
std::ios::clear(a3 + *(int *)(*(_QWORD *)a3 + 4LL), 0, 0);
v11 = sub_18007E980(a3, &v29, &v24);
if ( v11 )
{
LABEL_52:
*(_DWORD *)a1 = v11;
goto LABEL_53;
}
v12 = v29;
v13 = v24;
LABEL_15:
if ( a5 == 8 || a5 == 4 )
goto LABEL_49;
if ( a5 != 7 )
{
if ( a5 )
{
v10 = a5;
goto LABEL_47;
}
if ( v13 < 4 )
{
v10 = 1;
goto LABEL_48;
}
v18 = *v12;
v19 = v12[1];
v20 = v12[2];
v21 = v12[3];
if ( !*v12 )
{
if ( !v19 )
{
if ( v20 == -2 )
{
if ( v21 == -1 )
{
v10 = 6;
goto LABEL_47;
}
}
else if ( !v20 && v21 == 60 )
{
v10 = 6;
goto LABEL_47;
}
goto LABEL_46;
}
if ( v19 == 60 )
{
if ( !v20 && v21 == 63 )
{
v10 = 3;
goto LABEL_47;
}
goto LABEL_43;
}
goto LABEL_46;
}
switch ( v18 )
{
case -1:
v22 = v19 == -2;
break;
case -2:
if ( v19 == -1 )
{
LABEL_43:
v10 = 3;
goto LABEL_47;
}
LABEL_46:
v10 = 1;
goto LABEL_47;
case 60:
v22 = v19 == 0;
break;
default:
goto LABEL_46;
}
if ( v22 )
{
if ( !v20 && !v21 )
v10 = 5;
LABEL_47:
if ( v10 != 1 )
goto LABEL_49;
LABEL_48:
v12[v13++] = 0;
goto LABEL_49;
}
goto LABEL_46;
}
v10 = 5;
LABEL_49:
pugi::xml_document::load_buffer_inplace_own(a2, a1, v12, v13, a4, v10);
return a1;
}