//
// sub_B90040 from 0xb90040 to 0xb90480 (1088 bytes)
//
// 4 xrefs:
// > sub_B90480 @ 0xb90630
// > sub_B90480 @ 0xb9064c
// > sub_B90480 @ 0xb90788
// > sub_B907E4 @ 0xb90a88
//
// 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
//
__int64 __fastcall sub_B90040(__int64 a1, int a2, const char *a3, unsigned __int64 a4)
{
__int64 v8; // x22
const char *v9; // x2
__int64 result; // x0
unsigned int v11; // w22
unsigned __int8 *v12; // x0
int v13; // w24
unsigned int v14; // w22
__int64 v15; // x2
v8 = 0;
if ( !a2 )
goto LABEL_6;
if ( a2 == 60 )
v9 = "RCVD";
else
v9 = "SENT";
sub_B7B528(a1, "%s IAC SB ", v9);
if ( a4 <= 2 )
{
a4 -= 2LL;
v8 = 0;
goto LABEL_6;
}
v12 = (unsigned __int8 *)&a3[a4];
a4 -= 2LL;
v13 = *(v12 - 1);
v8 = (unsigned __int8)a3[a4];
if ( v13 != 240 || (_DWORD)v8 != 255 )
{
sub_B7B528(a1, "(terminated by ");
if ( (unsigned int)v8 <= 0x27 )
{
sub_B7B528(a1, "%s ", off_111C5A0[(unsigned int)v8]);
}
else if ( (unsigned int)(v8 - 236) > 0x13 )
{
sub_B7B528(a1, "%u ", v8);
}
else
{
sub_B7B528(a1, "%s ", off_111C6E0[(unsigned int)(v8 - 236)]);
}
if ( v13 <= 39 )
{
sub_B7B528(a1, "%s", off_111C5A0[v13]);
}
else if ( (unsigned int)(v13 - 236) > 0x13 )
{
sub_B7B528(a1, "%d", v13);
}
else
{
sub_B7B528(a1, "%s", off_111C6E0[v13 - 236]);
}
sub_B7B528(a1, ", not IAC SE!) ");
LABEL_6:
if ( a4 )
goto LABEL_7;
return sub_B7B528(a1, "(Empty suboption?)");
}
v8 = 255;
if ( !a4 )
return sub_B7B528(a1, "(Empty suboption?)");
LABEL_7:
if ( *(unsigned __int8 *)a3 <= 0x27u )
{
switch ( *a3 )
{
case 0x18:
case 0x1F:
case 0x23:
case 0x27:
sub_B7B528(a1, "%s", off_111C5A0[*(unsigned __int8 *)a3]);
result = *(unsigned __int8 *)a3;
if ( (_DWORD)result != 31 )
goto LABEL_31;
goto LABEL_11;
default:
sub_B7B528(a1, "%s (unsupported)", off_111C5A0[*(unsigned __int8 *)a3]);
goto LABEL_10;
}
}
sub_B7B528(a1, "%d (unknown)", (unsigned __int8)a3[v8]);
LABEL_10:
result = *(unsigned __int8 *)a3;
if ( (_DWORD)result == 31 )
{
LABEL_11:
if ( a4 > 4 )
result = sub_B7B528(
a1,
"Width: %hu ; Height: %hu",
*((unsigned __int8 *)a3 + 2) | (*((unsigned __int8 *)a3 + 1) << 8),
*((unsigned __int8 *)a3 + 4) | (*((unsigned __int8 *)a3 + 3) << 8));
LABEL_13:
if ( !a2 )
return result;
return sub_B7B528(a1, &byte_F1AB78);
}
LABEL_31:
switch ( a3[1] )
{
case 0:
sub_B7B528(a1, " IS");
result = *(unsigned __int8 *)a3;
break;
case 1:
sub_B7B528(a1, " SEND");
result = *(unsigned __int8 *)a3;
break;
case 2:
sub_B7B528(a1, " INFO/REPLY");
result = *(unsigned __int8 *)a3;
break;
case 3:
sub_B7B528(a1, " NAME");
result = *(unsigned __int8 *)a3;
break;
default:
break;
}
switch ( (_DWORD)result )
{
case 0x23:
goto LABEL_52;
case 0x27:
result = *((unsigned __int8 *)a3 + 1);
if ( !a3[1] )
{
result = sub_B7B528(a1, " ");
if ( a4 > 3 )
{
v14 = 3;
result = 3;
do
{
v15 = (unsigned __int8)a3[result];
if ( a3[result] )
{
if ( (_DWORD)v15 == 1 )
sub_B7B528(a1, " = ");
else
sub_B7B528(a1, "%c", v15);
}
else
{
sub_B7B528(a1, ", ");
}
result = ++v14;
}
while ( a4 > v14 );
}
}
goto LABEL_13;
case 0x18:
LABEL_52:
a3[a4] = 0;
result = sub_B7B528(a1, " \"%s\"", a3 + 2);
goto LABEL_13;
}
if ( a4 <= 2 )
goto LABEL_13;
v11 = 2;
result = 2;
do
{
++v11;
sub_B7B528(a1, " %.2x", (unsigned __int8)a3[result]);
result = v11;
}
while ( a4 > v11 );
if ( a2 )
return sub_B7B528(a1, &byte_F1AB78);
return result;
}