//
// sub_638AC8 from 0x638ac8 to 0x638c24 (348 bytes)
//
// 2 xrefs:
// > sub_62931C @ 0x6299fa
// > sub_638C2C @ 0x638e0e
//
// 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
//
int __fastcall sub_638AC8(int *a1, int a2, int a3)
{
int v4; // r10
int v6; // r5
size_t v8; // r3
int v9; // lr
int v10; // r11
unsigned int v11; // r2
int result; // r0
_BOOL4 v13; // r2
bool v14; // zf
int v15; // r2
v4 = *a1;
if ( !a3 )
{
if ( a1[288] != 5 )
return 0;
goto LABEL_44;
}
v6 = 0;
v8 = a1[288];
v9 = 0;
v10 = 0;
do
{
while ( 1 )
{
v11 = *(unsigned __int8 *)(a2 + v6);
if ( v11 == 13 )
break;
if ( v11 == 46 )
{
if ( v8 != 2 )
{
if ( v8 == 3 )
{
v10 = 1;
a1[288] = 0;
LABEL_24:
v15 = a1[289];
while ( v15 )
{
--v8;
a1[289] = --v15;
if ( !v8 )
{
v11 = a1[288];
goto LABEL_6;
}
}
if ( v10 )
--v8;
result = sub_618748((int)a1, 1, "\r\n.\r\n", v8);
if ( result )
return result;
v11 = a1[288];
v10 = 0;
v9 = v6;
goto LABEL_6;
}
LABEL_5:
a1[288] = 0;
v11 = v8;
if ( v8 )
goto LABEL_24;
goto LABEL_6;
}
v11 = 3;
a1[288] = 3;
}
else
{
if ( v11 != 10 )
goto LABEL_5;
v14 = v8 == 1;
if ( v8 != 1 )
v14 = v8 == 4;
if ( !v14 )
goto LABEL_5;
v11 = v8 + 1;
a1[288] = v8 + 1;
if ( !v8 )
{
LABEL_17:
v11 = 1;
goto LABEL_6;
}
}
LABEL_23:
if ( v11 <= v8 )
goto LABEL_24;
LABEL_6:
++v6;
v8 = v11;
if ( v6 == a3 )
goto LABEL_12;
}
if ( v8 )
{
if ( v8 == 3 )
v11 = 4;
else
a1[288] = 1;
if ( v8 == 3 )
a1[288] = v11;
else
v11 = 1;
goto LABEL_23;
}
a1[288] = 1;
if ( !v6 )
goto LABEL_17;
result = sub_618748((int)a1, 1, (const char *)(a2 + v9), v6 - v9);
if ( result )
return result;
v11 = a1[288];
v9 = v6++;
v8 = v11;
}
while ( v6 != a3 );
LABEL_12:
if ( v11 == 5 )
{
LABEL_44:
result = sub_618748((int)a1, 1, "\r\n.\r\n", 2u);
*(_DWORD *)(v4 + 304) &= ~1u;
a1[288] = 0;
return result;
}
v13 = v11 == 0;
if ( v6 == v9 )
v13 = 0;
if ( v13 )
return sub_618748((int)a1, 1, (const char *)(a2 + v9), v6 - v9);
return 0;
}