//
// sub_CA3AF4 from 0xca3af4 to 0xca3c14 (288 bytes)
//
// 2 xrefs:
// > sub_C9AC60 @ 0xc9acb4
// > sub_CA4098 @ 0xca41dc
//
// 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
//
unsigned __int64 __fastcall sub_CA3AF4(__int64 *a1, __int64 a2)
{
int v2; // w2
int v3; // w1
int v4; // w1
unsigned __int64 result; // x0
char *v6; // x2
char *v7; // x2
__int64 v8; // x2
int v9; // w1
signed int v10; // w1
unsigned int v11; // w2
signed int v12; // w2
unsigned int v13; // w3
if ( *(_BYTE *)a2 )
{
if ( *(_BYTE *)a2 == 1 )
{
v8 = *a1;
v9 = *(_DWORD *)(a2 + 4) + 280;
result = (unsigned int)(*(_DWORD *)(*a1 + 4LL * v9) + 1);
*(_DWORD *)(v8 + 4LL * v9) = result;
}
else
{
if ( *(unsigned __int16 *)(a2 + 2) > 0x1FFu )
{
v12 = *(unsigned __int16 *)(a2 + 2) - 1;
v13 = __clz(v12) ^ 0x1F;
v2 = ((v12 >> (v13 - 1)) & 1) + 2 * v13;
}
else
{
v2 = byte_F55780[2 * *(unsigned __int16 *)(a2 + 2)];
}
++*(_DWORD *)(*a1 + 4LL * (v2 + 256));
v3 = *(_DWORD *)(a2 + 4);
if ( v3 > 511 )
{
v10 = v3 - 1;
v11 = __clz(v10) ^ 0x1F;
v4 = ((v10 >> (v11 - 1)) & 1) + 2 * v11;
}
else
{
v4 = byte_F55780[2 * v3];
}
result = (unsigned __int64)a1 + 4 * v4;
++*(_DWORD *)(result + 3080);
}
}
else
{
v6 = (char *)a1 + 4 * *(unsigned __int8 *)(a2 + 7);
++*((_DWORD *)v6 + 514);
v7 = (char *)a1 + 4 * *(unsigned __int8 *)(a2 + 6);
++*((_DWORD *)v7 + 2);
++*(_DWORD *)(*a1 + 4LL * *(unsigned __int8 *)(a2 + 5));
result = (unsigned __int64)a1 + 4 * *(unsigned __int8 *)(a2 + 4);
++*(_DWORD *)(result + 1032);
}
return result;
}