//
// sub_100578084 from 0x100578084 to 0x100578294 (528 bytes)
//
// 2 xrefs:
// > sub_100565E88 @ 0x1005665ec
// > sub_100578294 @ 0x100578904
//
// 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_100578084(__int64 *a1, __int64 a2, unsigned __int64 a3)
{
__int64 v6; // x23
unsigned __int64 v7; // x9
unsigned __int64 v8; // x24
unsigned __int64 v9; // x8
char v10; // w28
int v11; // w10
unsigned __int64 v12; // x10
__int64 result; // x0
__int64 v14; // x10
v6 = *a1;
v7 = a1[182];
if ( a3 )
{
v8 = 0;
v9 = 0;
v10 = 0;
while ( 1 )
{
v11 = *(char *)(a2 + v8);
switch ( v11 )
{
case 10:
if ( v7 != 1 && v7 != 4 )
{
LABEL_15:
v12 = 0;
a1[182] = 0;
if ( !v7 )
goto LABEL_29;
break;
}
v12 = v7 + 1;
a1[182] = v7 + 1;
break;
case 46:
if ( v7 == 3 )
{
v12 = 0;
a1[182] = 0;
v10 = 1;
}
else
{
if ( v7 != 2 )
goto LABEL_15;
a1[182] = 3;
v12 = 3;
}
break;
case 13:
if ( v7 == 3 )
{
a1[182] = 4;
v12 = 4;
}
else
{
if ( !v7 )
{
a1[182] = 1;
if ( v8 )
{
result = sub_100552F3C((__int64)a1, 1, (char *)(a2 + v9), v8 - v9);
v9 = v8;
if ( (_DWORD)result )
return result;
}
goto LABEL_29;
}
a1[182] = 1;
v12 = 1;
}
break;
default:
goto LABEL_15;
}
if ( v7 >= v12 )
{
v14 = a1[183] - 1;
while ( v14 != -1 )
{
--v7;
a1[183] = v14--;
if ( !v7 )
goto LABEL_29;
}
result = sub_100552F3C((__int64)a1, 1, "\r\n.\r\n", v7 - (v10 & 1));
if ( (_DWORD)result )
return result;
v10 = 0;
v9 = v8;
}
LABEL_29:
++v8;
v7 = a1[182];
if ( v8 >= a3 )
goto LABEL_32;
}
}
v9 = 0;
LABEL_32:
if ( v7 )
{
if ( v7 == 5 )
{
result = sub_100552F3C((__int64)a1, 1, "\r\n.\r\n", 2u);
*(_DWORD *)(v6 + 484) &= ~1u;
a1[182] = 0;
}
else
{
return 0;
}
}
else if ( v9 == a3 )
{
return 0;
}
else
{
return sub_100552F3C((__int64)a1, 1, (char *)(a2 + v9), a3 - v9);
}
return result;
}