//
// sub_CA5FC from 0xca5fc to 0xca6da (222 bytes)
//
// 5 xrefs:
// > sub_CA5D8 @ 0xca5e6
// > sub_CA6DA @ 0xca716
// > sub_CA77C @ 0xca7a6
// > sub_CA77C @ 0xca7ee
// > sub_CA954 @ 0xca98e
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:41:55 +0000
//
int __fastcall sub_CA5FC(_DWORD *a1, __int64 *a2)
{
signed int v3; // r6
int v5; // r0
int v6; // r0
int v7; // r5
int v8; // r1
int v9; // r4
signed int v10; // r0
unsigned int v11; // r0
unsigned int v12; // r0
unsigned int v13; // r0
unsigned int v14; // r0
unsigned int v15; // r1
v3 = a1[10];
v5 = sub_C90EC(a2, a1[9]);
if ( v5 < 0 )
{
v9 = a1[2];
v7 = 0;
}
else
{
v6 = *(_DWORD *)(a1[8] + 4 * v5);
if ( v6 > -1 )
{
v7 = v6 - 1;
v8 = *(unsigned __int8 *)(a1[7] + v6 - 1);
goto LABEL_17;
}
v7 = ((unsigned int)v6 >> 15) & 0x7FFF;
v9 = a1[2] - (v6 & 0x7FFF);
}
while ( 1 )
{
v10 = sub_C90EC(a2, v3);
if ( v10 > -1 || v3 < 2 )
break;
--v3;
}
if ( v10 < 0 )
return -1;
v11 = bswap32(v10);
v12 = ((v11 >> 4) & 0xF0F0F0F) + ((16 * v11) & 0xF0F0F0F0);
v13 = ((v12 >> 2) & 0x33333333) + ((4 * v12) & 0xCCCCCCCC);
v14 = ((v13 >> 1) & 0x55555555) + ((2 * v13) & 0xAAAAAAAA);
while ( 1 )
{
v15 = v9 - v7;
if ( v9 - v7 < 2 )
break;
if ( *(_DWORD *)(a1[5] + 4 * (v7 + (v15 >> 1))) <= v14 )
v7 += v15 >> 1;
else
v9 -= v15 >> 1;
}
v8 = *(unsigned __int8 *)(a1[7] + v7);
if ( v3 < v8 )
{
v7 = -1;
v8 = v3;
}
LABEL_17:
sub_C9180(a2, v8);
return v7;
}