//
// sub_180015680 from 0x180015680 to 0x1800158d3 (595 bytes)
//
// 17 xrefs:
// > DS_Dictionary::setRectArrayForKey @ 0x18001f72d
// > DS_Dictionary::setRectArrayForKey @ 0x18001f753
// > DS_Dictionary::setRectArrayForKey @ 0x18001f77a
// > DS_Dictionary::setRectArrayForKey @ 0x18001f7a1
// > DS_Dictionary::setRectArrayForKey @ 0x18001f7c8
// > DS_Dictionary::setRectForKey @ 0x18001fadc
// > DS_Dictionary::setRectForKey @ 0x18001fafc
// > DS_Dictionary::setRectForKey @ 0x18001fb1d
// > DS_Dictionary::setRectForKey @ 0x18001fb3e
// > DS_Dictionary::setRectForKey @ 0x18001fb5f
// > DS_Dictionary::setVec2ArrayForKey @ 0x18002064d
// > DS_Dictionary::setVec2ArrayForKey @ 0x180020673
// > DS_Dictionary::setVec2ArrayForKey @ 0x18002069a
// > DS_Dictionary::setVec2ForKey @ 0x1800209ac
// > DS_Dictionary::setVec2ForKey @ 0x1800209cc
// > DS_Dictionary::setVec2ForKey @ 0x1800209ed
// > ??> @ 0x1801ae4c4
//
// 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=3
__int64 __fastcall sub_180015680(__int64 a1, __int64 a2)
{
__int64 v3; // rsi
unsigned int v4; // edi
__int64 v5; // r15
__int64 v6; // r14
__int64 v7; // r13
__int64 v8; // rax
bool v9; // al
__int64 v10; // rax
__int16 v11; // ax
unsigned __int8 v12; // bl
__int64 v13; // rcx
__int64 v14; // rax
unsigned __int8 v15; // bl
__int64 v16; // rax
__int64 v17; // r8
__int64 v18; // rax
__int64 v20; // [rsp+20h] [rbp-38h]
int v22; // [rsp+70h] [rbp+18h]
v3 = a1;
v4 = 0;
v22 = 0;
v5 = -1;
do
++v5;
while ( *(_BYTE *)(a2 + v5) );
if ( std::ios_base::width((std::ios_base *)(a1 + *(int *)(*(_QWORD *)a1 + 4LL))) <= 0
|| std::ios_base::width((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL))) <= v5 )
{
v6 = 0;
}
else
{
v6 = std::ios_base::width((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL))) - v5;
}
v7 = v3;
v20 = v3;
v8 = std::ios::rdbuf(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
if ( v8 )
(*(void (__fastcall **)(__int64))(*(_QWORD *)v8 + 8LL))(v8);
v9 = std::ios_base::good((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL)));
if ( v9 )
{
v10 = std::ios::tie(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
if ( !v10 || v10 == v3 )
{
v9 = 1;
}
else
{
std::ostream::flush(v10);
v9 = std::ios_base::good((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL)));
}
}
if ( v9 )
{
v11 = std::ios_base::flags((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL)));
try
{
if ( (v11 & 0x1C0) != 0x40 )
{
while ( v6 > 0 )
{
v12 = std::ios::fill(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
v13 = std::ios::rdbuf(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
if ( (unsigned int)std::streambuf::sputc(v13, v12) == -1 )
{
v4 = 4;
goto LABEL_27;
}
--v6;
}
}
v14 = std::ios::rdbuf(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
if ( std::streambuf::sputn(v14, a2, v5) == v5 )
{
while ( v6 > 0 )
{
v15 = std::ios::fill(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
v16 = std::ios::rdbuf(v3 + *(int *)(*(_QWORD *)v3 + 4LL));
if ( (unsigned int)std::streambuf::sputc(v16, v15) == -1 )
goto LABEL_26;
--v6;
}
}
else
{
LABEL_26:
v4 = 4;
LABEL_27:
v22 = 4;
}
std::ios_base::width((std::ios_base *)(v3 + *(int *)(*(_QWORD *)v3 + 4LL)), 0);
}
catch ( ... )
{
LOBYTE(v17) = 1;
std::ios::setstate(a1 + *(int *)(*(_QWORD *)a1 + 4LL), 4, v17);
v3 = a1;
v4 = v22;
v7 = v20;
}
}
else
{
v4 = 4;
}
std::ios::setstate(v3 + *(int *)(*(_QWORD *)v3 + 4LL), v4, 0);
if ( !std::uncaught_exception() )
std::ostream::_Osfx(v7);
v18 = std::ios::rdbuf(v7 + *(int *)(*(_QWORD *)v7 + 4LL));
if ( v18 )
(*(void (__fastcall **)(__int64))(*(_QWORD *)v18 + 16LL))(v18);
return v3;
}