//
// sub_BA9E34 from 0xba9e34 to 0xbaa084 (592 bytes)
//
// 1 xrefs:
// > sub_B928E0 @ 0xb93494
//
// 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_BA9E34(__int64 *a1, __int64 a2)
{
__int64 v2; // x27
__int64 v4; // x25
char *v5; // x24
__int64 v6; // x22
void *v7; // d10
void *v8; // d9
__int64 v9; // x21
__int64 v10; // x20
__int64 v11; // x2
__int64 v12; // x19
_BYTE *v13; // x0
int v14; // w4
char *v15; // x0
size_t v16; // x2
char *v17; // x0
char *v18; // x1
size_t v20; // x2
char *v21; // x1
char *v22; // x0
__int64 v23; // x20
int v24; // w1
v2 = *a1;
v4 = *a1 + 0x8000;
v5 = *(char **)(*a1 + 35672);
v6 = *(_QWORD *)(*a1 + 536);
if ( !v5 || *(_BYTE *)(v2 + 978) )
{
v15 = (char *)off_1231000(0x8000u);
v8 = v15;
if ( !v15 )
{
sub_B7B690(v2, "Failed to alloc scratch buffer!");
return 27;
}
v7 = v5;
v5 = v15;
}
else
{
v7 = nullptr;
v8 = nullptr;
}
if ( a2 <= 0 )
{
v10 = 0;
goto LABEL_21;
}
v9 = *(_QWORD *)(v6 + 24);
v10 = 0;
v11 = v9;
v12 = 0;
do
{
while ( 1 )
{
v13 = (_BYTE *)(*(_QWORD *)(v2 + 520) + v12);
v14 = (unsigned __int8)*v13;
if ( (unsigned __int8)asc_F27188[v11] == v14 )
break;
if ( !v11 )
goto LABEL_7;
v20 = v11 - v9;
v21 = &asc_F27188[v9];
v22 = &v5[v10];
v23 = v10 - v9;
v9 = 0;
memcpy(v22, v21, v20);
v13 = (_BYTE *)(*(_QWORD *)(v2 + 520) + v12);
v24 = (unsigned __int8)*v13;
v10 = v23 + *(_QWORD *)(v6 + 24);
*(_BYTE *)(v6 + 32) = 0;
v11 = v24 == 13;
*(_QWORD *)(v6 + 24) = v11;
LABEL_14:
if ( v11 )
goto LABEL_8;
LOBYTE(v14) = *v13;
LABEL_7:
v5[v10++] = v14;
v11 = *(_QWORD *)(v6 + 24);
LABEL_8:
if ( ++v12 == a2 )
goto LABEL_19;
}
*(_QWORD *)(v6 + 24) = ++v11;
*(_BYTE *)(v6 + 32) = v11 == 5 || v11 == 2;
if ( v11 != 3 )
goto LABEL_14;
v16 = 4 - v9;
v17 = &v5[v10];
++v12;
v10 = v10 - v9 + 4;
v18 = &asc_F273A8[v9];
v9 = 0;
memcpy(v17, v18, v16);
*(_QWORD *)(v6 + 24) = 0;
v11 = 0;
}
while ( v12 != a2 );
LABEL_19:
if ( v11 != v9 )
{
memcpy(&v5[v10], &asc_F27188[v9], v11 - v9);
v10 = v10 - v9 + *(_QWORD *)(v6 + 24);
}
LABEL_21:
if ( v10 == a2 )
{
off_1231008(v8);
}
else
{
*(_QWORD *)(v2 + 520) = v5;
*(_QWORD *)(v4 + 2904) = v5;
off_1231008(v7);
*(_QWORD *)(v2 + 512) = v10;
}
return 0;
}