//
// sub_CA3658 from 0xca3658 to 0xca3838 (480 bytes)
//
// 4 xrefs:
// > sub_C9BDA0 @ 0xc9c07c
// > sub_C9BDA0 @ 0xc9c098
// > sub_C9BDA0 @ 0xc9c6d4
// > sub_C9BDA0 @ 0xc9d2d4
//
// 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_CA3658(_DWORD *a1, __int64 a2, int a3)
{
int v5; // w22
__int64 v6; // x24
size_t v7; // x2
__int64 result; // x0
__int64 v9; // x3
int v10; // w1
int v11; // w1
int v12; // w1
char *v13; // x1
char *v14; // x1
char *v15; // x1
signed int v16; // w1
unsigned int v17; // w2
signed int v18; // w1
unsigned int v19; // w2
_QWORD v20[3]; // [xsp+48h] [xbp+48h] BYREF
if ( a3 < 0 )
{
v5 = a1[810];
v6 = *(_QWORD *)a1;
if ( v5 > 0 )
goto LABEL_3;
LABEL_22:
v7 = 4400;
goto LABEL_4;
}
v5 = a3;
a1[810] = a3;
v6 = *(_QWORD *)a1;
if ( a3 <= 0 )
goto LABEL_22;
LABEL_3:
v7 = 4 * ((1 << v5) + 1100);
LABEL_4:
memset(a1, 0, v7);
a1[810] = v5;
*(_QWORD *)a1 = v6;
sub_C9BB94(a2, v20);
LABEL_5:
result = v20[0];
v9 = v20[2];
while ( result )
{
if ( *(_BYTE *)result )
{
if ( *(_BYTE *)result == 1 )
{
++*(_DWORD *)(*(_QWORD *)a1 + 4LL * (*(_DWORD *)(result + 4) + 280));
}
else
{
if ( *(unsigned __int16 *)(result + 2) > 0x1FFu )
{
v18 = *(unsigned __int16 *)(result + 2) - 1;
v19 = __clz(v18) ^ 0x1F;
v10 = ((v18 >> (v19 - 1)) & 1) + 2 * v19;
}
else
{
v10 = byte_F55780[2 * *(unsigned __int16 *)(result + 2)];
}
++*(_DWORD *)(*(_QWORD *)a1 + 4LL * (v10 + 256));
v11 = *(_DWORD *)(result + 4);
if ( v11 > 511 )
{
v16 = v11 - 1;
v17 = __clz(v16) ^ 0x1F;
v12 = ((v16 >> (v17 - 1)) & 1) + 2 * v17;
}
else
{
v12 = byte_F55780[2 * v11];
}
++a1[v12 + 770];
}
}
else
{
v13 = (char *)&a1[*(unsigned __int8 *)(result + 7)];
++*((_DWORD *)v13 + 514);
v14 = (char *)&a1[*(unsigned __int8 *)(result + 6)];
++*((_DWORD *)v14 + 2);
++*(_DWORD *)(*(_QWORD *)a1 + 4LL * *(unsigned __int8 *)(result + 5));
v15 = (char *)&a1[*(unsigned __int8 *)(result + 4)];
++*((_DWORD *)v15 + 258);
}
result += 8;
v20[0] = result;
if ( result == v9 )
{
sub_C9BBD8((__int64)v20);
goto LABEL_5;
}
}
return result;
}