//
// sub_B4E4B4 from 0xb4e4b4 to 0xb4e620 (364 bytes)
//
// 2 xrefs:
// > sub_B57FA0 @ 0xb589f0
// > sub_B57FA0 @ 0xb58f74
//
// 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_B4E4B4(unsigned __int8 *a1, unsigned __int8 a2)
{
int v2; // w21
_BYTE *v3; // x19
int v4; // w0
unsigned __int8 v5; // w1
_BYTE *v7; // x0
void *v8; // [xsp+48h] [xbp+48h] BYREF
__int64 v9; // [xsp+50h] [xbp+50h]
v2 = a2;
v8 = nullptr;
v3 = a1;
v9 = 0;
v4 = *a1;
LABEL_2:
while ( 2 )
{
while ( 1 )
{
v5 = byte_F1EC70[v4];
if ( (v5 & 4) != 0 )
break;
LABEL_7:
v4 = (unsigned __int8)*++v3;
}
while ( 1 )
{
if ( v2 == v4 )
{
if ( v8 )
{
memmove((char *)v8 - v9, v8, v3 - (_BYTE *)v8);
v7 = &v3[-v9];
}
else
{
v7 = v3;
}
*v7 = 0;
return v3 + 1;
}
if ( (v5 & 8) == 0 )
break;
if ( v4 == 13 )
{
v4 = (unsigned __int8)v3[1];
*v3 = 32;
if ( v4 == 10 )
{
if ( v8 )
memmove((char *)v8 - v9, v8, v3 + 1 - (_BYTE *)v8);
v8 = v3 + 2;
++v9;
v4 = (unsigned __int8)v3[2];
v3 += 2;
}
else
{
++v3;
}
goto LABEL_2;
}
*v3++ = 32;
v4 = (unsigned __int8)*v3;
v5 = byte_F1EC70[(unsigned __int8)*v3];
if ( (v5 & 4) == 0 )
goto LABEL_7;
}
if ( v4 == 38 )
{
v3 = sub_B4D5DC(v3, (__int64)&v8);
v4 = (unsigned __int8)*v3;
continue;
}
break;
}
if ( v4 )
goto LABEL_7;
return nullptr;
}