//
// sub_140633A60 from 0x140633a60 to 0x140633dfb (923 bytes)
//
// 2 xrefs:
// > sub_140633E00 @ 0x140633e47
// > ??> @ 0x140930bb4
//
// 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:35:29 +0000
//
// Hidden C++ exception states: #wind=3
__int64 *__fastcall sub_140633A60(__int64 *a1, size_t *a2)
{
__int64 v3; // rax
void **v4; // rbx
void **v5; // r14
unsigned __int64 v6; // r15
unsigned __int64 v7; // rsi
unsigned __int8 *v8; // rdi
unsigned __int8 *v9; // rcx
unsigned __int8 *v10; // rdx
unsigned __int64 v11; // rdx
void **v12; // rcx
unsigned __int64 v13; // rsi
void **v14; // rbx
void **v15; // r14
unsigned __int64 v16; // r15
__int64 v17; // rcx
unsigned __int64 v18; // rdi
__int64 v19; // rdx
__int64 v20; // r8
__int64 v21; // r9
unsigned __int8 *v22; // rcx
void **v23; // rax
__int64 v24; // rax
void **v25; // rax
__int64 v26; // rax
void *v27; // rcx
__int64 v29; // [rsp+38h] [rbp-C8h]
_QWORD v30[3]; // [rsp+40h] [rbp-C0h] BYREF
void **v31; // [rsp+58h] [rbp-A8h] BYREF
char v32[120]; // [rsp+60h] [rbp-A0h] BYREF
char v33[104]; // [rsp+D8h] [rbp-28h] BYREF
_BYTE v34[256]; // [rsp+140h] [rbp+40h] BYREF
void *Block[2]; // [rsp+240h] [rbp+140h] BYREF
unsigned __int64 v36; // [rsp+250h] [rbp+150h]
unsigned __int64 v37; // [rsp+258h] [rbp+158h]
HIDWORD(v29) = HIDWORD(a1);
sub_14010F2D0((__int64)v30, a2);
*(_OWORD *)Block = 0;
v36 = 0;
v37 = 15;
LOBYTE(Block[0]) = 0;
*a1 = 0;
a1[1] = 0;
a1[2] = 0;
v3 = sub_14010F9D0((__int64)v30, (__int64)Block, 0x2Cu);
if ( (unsigned __int8)std::ios_base::operator bool(v3 + *(int *)(*(_QWORD *)v3 + 4LL)) )
{
do
{
v4 = Block;
v5 = (void **)Block[0];
v6 = v37;
if ( v37 > 0xF )
v4 = (void **)Block[0];
v7 = v36;
if ( !v36 )
goto LABEL_10;
v8 = (unsigned __int8 *)v4 + v36;
memset(v34, 0, sizeof(v34));
v9 = (unsigned __int8 *)&unk_14081DC2C;
do
v34[*v9++] = 1;
while ( v9 != (unsigned __int8 *)&unk_14081DC32 );
v10 = (unsigned __int8 *)v4;
if ( v4 < (void **)v8 )
{
while ( v34[*v10] )
{
if ( ++v10 >= v8 )
goto LABEL_10;
}
v11 = v10 - (unsigned __int8 *)v4;
}
else
{
LABEL_10:
v11 = -1;
}
if ( v7 < v11 )
v11 = v7;
v12 = Block;
if ( v6 > 0xF )
v12 = v5;
v13 = v7 - v11;
memmove(v12, (char *)v12 + v11, v13 + 1);
v36 = v13;
v14 = Block;
v15 = (void **)Block[0];
v16 = v37;
if ( v37 > 0xF )
v14 = (void **)Block[0];
if ( v13 )
{
v18 = v13 - 1;
memset(v34, 0, sizeof(v34));
v22 = (unsigned __int8 *)&unk_14081DC2C;
do
v34[*v22++] = 1;
while ( v22 != (unsigned __int8 *)&unk_14081DC32 );
v23 = (void **)((char *)v14 + v18);
if ( v34[*((unsigned __int8 *)v14 + v18)] )
{
while ( v23 != v14 )
{
v23 = (void **)((char *)v23 - 1);
if ( !v34[*(unsigned __int8 *)v23] )
goto LABEL_25;
}
v24 = -1;
}
else
{
LABEL_25:
v24 = (char *)v23 - (char *)v14;
}
v17 = v24 + 1;
if ( v13 < v24 + 1 )
sub_14003F4D0(v17, v19, v20, v21);
}
else
{
v17 = 0;
}
v36 = v17;
v25 = Block;
if ( v16 > 0xF )
v25 = v15;
*((_BYTE *)v25 + v17) = 0;
if ( v36 )
sub_140075F50(a1, (__int64)Block);
v26 = sub_14010F9D0((__int64)v30, (__int64)Block, 0x2Cu);
}
while ( (unsigned __int8)std::ios_base::operator bool(v26 + *(int *)(*(_QWORD *)v26 + 4LL)) );
}
if ( v37 > 0xF )
{
v27 = Block[0];
if ( v37 + 1 >= 0x1000 )
{
v27 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v27 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v27);
}
v36 = 0;
v37 = 15;
LOBYTE(Block[0]) = 0;
*(_QWORD *)((char *)v30 + *(int *)(v30[0] + 4LL)) = &std::basic_stringstream,std::allocator>::`vftable';
*(_DWORD *)((char *)&v29 + *(int *)(v30[0] + 4LL) + 4) = *(_DWORD *)(v30[0] + 4LL) - 152;
v31 = &std::stringbuf::`vftable';
sub_14010FC00((__int64)&v31);
std::streambuf::~streambuf>(&v31);
std::iostream::~iostream>(v32);
std::ios::~ios>(v33);
return a1;
}