//
// sub_180084180 from 0x180084180 to 0x18008430e (398 bytes)
//
// 2 xrefs:
// > sub_180083740 @ 0x1800837b8
// > ??> @ 0x1801b54fc
//
// 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
//
unsigned __int8 *__fastcall sub_180084180(unsigned __int8 *a1, char a2)
{
__int64 v2; // rax
unsigned __int8 *v4; // rbx
unsigned __int8 *v5; // rdx
__int64 v6; // rbp
bool v7; // zf
__int64 v8; // rax
__int64 v9; // rcx
__int64 v10; // rax
unsigned __int8 *v11; // rdi
__int64 v12; // rax
__int64 v13; // rax
unsigned __int8 *v15; // rcx
unsigned __int8 *v16; // [rsp+20h] [rbp-28h] BYREF
__int64 v17; // [rsp+28h] [rbp-20h]
v2 = *a1;
v4 = a1;
v5 = nullptr;
v16 = nullptr;
v6 = 0;
v7 = (byte_180101290[v2] & 8) == 0;
v17 = 0;
if ( !v7 )
{
v5 = a1;
do
v8 = *++v5;
while ( (byte_180101290[v8] & 8) != 0 );
v16 = v5;
v6 = v5 - a1;
v4 = v5;
v17 = v5 - a1;
}
while ( 1 )
{
v9 = *v4;
if ( (byte_180101290[v9] & 0xC) == 0 )
{
do
v10 = *++v4;
while ( (byte_180101290[v10] & 0xC) == 0 );
LOBYTE(v9) = v10;
}
if ( (_BYTE)v9 == a2 )
break;
if ( (byte_180101290[(unsigned __int8)v9] & 8) != 0 )
{
*v4++ = 32;
if ( (byte_180101290[*v4] & 8) != 0 )
{
v11 = v4 + 1;
if ( (byte_180101290[v4[1]] & 8) != 0 )
{
do
v12 = *++v11;
while ( (byte_180101290[v12] & 8) != 0 );
}
if ( v5 )
memmove(&v5[-v6], v5, v4 - v5);
v5 = v11;
v6 += v11 - v4;
v16 = v11;
v4 = v11;
v17 = v6;
}
}
else if ( (_BYTE)v9 == 38 )
{
v13 = sub_180085450(v4, &v16);
v5 = v16;
v4 = (unsigned __int8 *)v13;
v6 = v17;
}
else
{
if ( !(_BYTE)v9 )
return nullptr;
++v4;
}
}
if ( v5 )
{
memmove(&v5[-v6], v5, v4 - v5);
v15 = &v4[-v6];
}
else
{
v15 = v4;
}
do
*v15-- = 0;
while ( (byte_180101290[*v15] & 8) != 0 );
return v4 + 1;
}