//
// sub_CA9E4 from 0xca9e4 to 0xcaba2 (446 bytes)
//
// 1 xrefs:
// > sub_CB2F0 @ 0xcb5d8
//
// 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_CA9E4(int a1, int a2, _DWORD *a3)
{
int *v4; // r5
int v5; // r0
int v6; // r6
int v7; // r4
int v8; // r0
_DWORD *v9; // r6
_DWORD *v10; // r10
_DWORD *v11; // r9
int i; // r11
int v13; // r0
int v14; // r0
int v15; // r6
int v16; // r0
int v17; // r0
unsigned int v18; // r6
int v19; // r10
int v20; // r4
int v21; // r9
int j; // r1
int v23; // r0
int v24; // r0
int v25; // r6
_DWORD *v26; // r1
int v27; // r0
bool v28; // zf
_DWORD *v30; // [sp+Ch] [bp-12Ch]
int v32; // [sp+14h] [bp-124h]
int v33; // [sp+14h] [bp-124h]
_DWORD base[65]; // [sp+18h] [bp-120h] BYREF
v32 = *(_DWORD *)(a2 + 28);
v4 = (int *)sub_8112C(a1, 1, 1120);
if ( !v4 )
goto LABEL_38;
v5 = sub_C91BC(a3, 5u);
v6 = 0;
v7 = -1;
*v4 = v5;
while ( v6 < v5 )
{
v8 = sub_C91BC(a3, 4u);
v4[v6 + 1] = v8;
if ( v8 < 0 )
goto LABEL_38;
if ( v7 < v8 )
v7 = v8;
v5 = *v4;
++v6;
}
v9 = v4 + 32;
v10 = v4 + 80;
v30 = v4 + 64;
v11 = v4 + 48;
for ( i = 0; i <= v7; ++i )
{
v9[i] = sub_C91BC(a3, 3u) + 1;
v13 = sub_C91BC(a3, 2u);
v11[i] = v13;
if ( v13 < 0 )
goto LABEL_38;
if ( v13 )
{
v14 = sub_C91BC(a3, 8u);
v30[i] = v14;
}
else
{
v14 = v30[i];
}
if ( v14 < 0 || v14 >= *(_DWORD *)(v32 + 24) )
goto LABEL_38;
v15 = 0;
while ( v15 < 1 << v11[i] )
{
v16 = sub_C91BC(a3, 8u);
v10[v15] = v16 - 1;
if ( v16 >= 0 )
{
++v15;
if ( v16 <= *(_DWORD *)(v32 + 24) )
continue;
}
goto LABEL_38;
}
v9 = v4 + 32;
v10 += 8;
}
v4[208] = sub_C91BC(a3, 2u) + 1;
v17 = sub_C91BC(a3, 4u);
if ( v17 >= 0 )
{
v18 = v17;
v19 = 1 << v17;
v20 = 0;
v21 = 0;
for ( j = 0; j < *v4; j = v33 + 1 )
{
v33 = j;
v20 += v4[v4[j + 1] + 32];
while ( v21 < v20 )
{
v23 = sub_C91BC(a3, v18);
v4[v21 + 211] = v23;
if ( v23 < 0 || v23 >= v19 )
goto LABEL_38;
++v21;
}
}
v24 = 0;
v25 = v20 + 2;
v4[209] = 0;
v4[210] = v19;
v26 = v4 + 209;
while ( v24 < v25 )
base[v24++] = v26++;
qsort(base, v20 + 2, 4u, (__compar_fn_t)sub_CB0A4);
v27 = 0;
while ( v27 + 1 < v25 )
{
v28 = *(_DWORD *)base[v27] == *(_DWORD *)base[v27 + 1];
++v27;
if ( v28 )
goto LABEL_38;
}
}
else
{
LABEL_38:
sub_CAD0C(a1, v4);
return nullptr;
}
return v4;
}