//
// sub_40C49C from 0x40c49c to 0x40c59a (254 bytes)
//
// 2 xrefs:
// > sub_40C664 @ 0x40c6a8
// > sub_40C664 @ 0x40c6e2
//
// 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
//
bool __fastcall sub_40C49C(int a1, int a2, int a3, int a4, int a5)
{
int v8; // r4
int v9; // r10
int v10; // r11
int v11; // r11
int v12; // r6
_BOOL4 result; // r0
int v14; // r6
int v15; // r9
_BOOL4 v16; // [sp+Ch] [bp-10h] BYREF
int v17; // [sp+10h] [bp-Ch]
_BOOL4 varg_r3; // [sp+44h] [bp+28h]
v8 = a2;
v9 = (a3 - 1) / 2;
while ( 1 )
{
v10 = 8 * v8;
if ( v8 >= v9 )
break;
v11 = v10 + a1;
v12 = 2 * (v8 + 1);
if ( sub_40C45C((_DWORD *)(a1 + 16 * (v8 + 1)), (_DWORD *)(a1 + 8 * (v12 - 1))) )
--v12;
*(_DWORD *)(a1 + 8 * v8) = *(_DWORD *)(a1 + 8 * v12);
v8 = v12;
*(_DWORD *)(v11 + 4) = *(_DWORD *)(a1 + 8 * v12 + 4);
}
if ( (a3 & 1) == 0 && v8 == (a3 - 2) / 2 )
{
v8 = 2 * v8 + 1;
*(_DWORD *)(a1 + v10) = *(_DWORD *)(a1 + 8 * v8);
*(_DWORD *)(a1 + v10 + 4) = *(_DWORD *)(a1 + 8 * v8 + 4);
}
result = varg_r3;
v14 = (v8 - 1) / 2;
v16 = varg_r3;
v17 = a5;
while ( 1 )
{
v15 = 8 * v8;
if ( v8 <= a2 )
break;
result = sub_40C45C((_DWORD *)(a1 + 8 * v14), &v16);
if ( !result )
break;
v8 = v14;
*(_DWORD *)(a1 + v15) = *(_DWORD *)(a1 + 8 * v14);
*(_DWORD *)(a1 + v15 + 4) = *(_DWORD *)(a1 + 8 * v14 + 4);
v14 = (v14 - 1) / 2;
}
*(_DWORD *)(a1 + 8 * v8) = v16;
*(_DWORD *)(v15 + a1 + 4) = v17;
return result;
}