//
// sub_B4E2D0 from 0xb4e2d0 to 0xb4e4b4 (484 bytes)
//
// 2 xrefs:
// > sub_B57FA0 @ 0xb58318
// > sub_B57FA0 @ 0xb590c4
//
// 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
//
_BYTE *__fastcall sub_B4E2D0(unsigned __int8 *a1)
{
_BYTE *v1; // x22
_BYTE *v2; // x19
int v3; // w0
_BYTE *v4; // x23
_BYTE *v6; // x0
void *v7; // [xsp+48h] [xbp+48h] BYREF
__int64 v8; // [xsp+50h] [xbp+50h]
v1 = a1;
v2 = a1;
v3 = *a1;
v7 = nullptr;
v8 = 0;
LABEL_2:
if ( (byte_F1EC70[v3] & 1) != 0 )
{
if ( v3 != 60 )
goto LABEL_4;
}
else
{
while ( 1 )
{
do
v3 = (unsigned __int8)*++v2;
while ( (byte_F1EC70[v3] & 1) == 0 );
if ( v3 == 60 )
break;
LABEL_4:
switch ( v3 )
{
case 13:
v3 = (unsigned __int8)v2[1];
*v2 = 10;
if ( v3 == 10 )
{
if ( v7 )
memmove((char *)v7 - v8, v7, v2 + 1 - (_BYTE *)v7);
v7 = v2 + 2;
++v8;
v3 = (unsigned __int8)v2[2];
v2 += 2;
}
else
{
++v2;
}
goto LABEL_2;
case 38:
v2 = sub_B4D5DC(v2, (__int64)&v7);
v3 = (unsigned __int8)*v2;
goto LABEL_2;
case 0:
if ( v7 )
{
memmove((char *)v7 - v8, v7, v2 - (_BYTE *)v7);
v6 = &v2[-v8];
}
else
{
v6 = v2;
}
if ( v6 > v1 )
{
while ( (byte_F1EC70[(unsigned __int8)*(v6 - 1)] & 8) != 0 )
{
if ( --v6 == v1 )
goto LABEL_30;
}
}
v1 = v6;
LABEL_30:
*v1 = 0;
return v2;
}
}
}
v4 = v2;
if ( v7 )
{
memmove((char *)v7 - v8, v7, v2 - (_BYTE *)v7);
v2 -= v8;
}
if ( v2 > v1 )
{
while ( (byte_F1EC70[(unsigned __int8)*(v2 - 1)] & 8) != 0 )
{
if ( --v2 == v1 )
goto LABEL_16;
}
}
v1 = v2;
LABEL_16:
*v1 = 0;
return v4 + 1;
}