//
// sub_4B96E from 0x4b96e to 0x4bb6a (508 bytes)
//
// 4 xrefs:
// > sub_4A40A @ 0x4a4a4
// > sub_4A9A4 @ 0x4a9c8
// > sub_4B298 @ 0x4b38e
// > sub_4BB6C @ 0x4bc4c
//
// 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_4B96E(int a1, int a2)
{
_DWORD *v3; // r9
_DWORD *v4; // r0
int result; // r0
float v7; // s0
bool v8; // fzf
bool v9; // fnf
_DWORD *v10; // r0
_DWORD *v11; // r0
unsigned int v12; // r1
unsigned int v13; // r2
_DWORD *v14; // r2
int v15; // r5
int *v16; // r0
int *v17; // r6
int *v18; // r6
int v19; // r0
unsigned int v20; // [sp+Ch] [bp-1Ch] BYREF
v3 = *(_DWORD **)(*(_DWORD *)(a1 + 332) + 20);
if ( !v3 )
return 0;
v4 = (_DWORD *)v3[43];
if ( v4 && v3[41] && !*(_DWORD *)(a1 + 348) )
*(_DWORD *)(a1 + 348) = *v4;
if ( !*(_DWORD *)(a1 + 348) )
return 0;
if ( !sub_4AF98(a1, &v20, 2) )
{
v7 = *(float *)(a1 + 388);
v8 = v7 == 0.0;
v9 = v7 < 0.0;
if ( a2 )
{
if ( v9 || v8 )
v10 = (_DWORD *)(v3[44] + 4);
else
v10 = (_DWORD *)v3[43];
v11 = (_DWORD *)*v10;
*(_DWORD *)(a1 + 348) = v11;
v12 = v20;
while ( 1 )
{
if ( v7 <= 0.0 || v12 <= v11[6] )
{
if ( v7 >= 0.0 || v12 >= v11[6] )
goto LABEL_8;
v13 = v11[6];
if ( v7 <= 0.0 )
{
if ( v13 <= v12 )
goto LABEL_8;
v11 = (_DWORD *)v11[1];
*(_DWORD *)(a1 + 348) = v11;
v14 = (_DWORD *)v3[43];
goto LABEL_26;
}
}
else
{
v13 = v11[6];
}
if ( v13 >= v12 )
goto LABEL_8;
v11 = (_DWORD *)*v11;
*(_DWORD *)(a1 + 348) = v11;
v14 = (_DWORD *)v3[44];
LABEL_26:
if ( v14 == v11 )
goto LABEL_8;
}
}
v15 = !v9 && !v8 && v20 < *(_DWORD *)(a1 + 352) || v7 < 0.0 && v20 > *(_DWORD *)(a1 + 352);
while ( 1 )
{
if ( v7 > 0.0 )
{
v16 = *(int **)(a1 + 348);
if ( v20 > v16[6] )
goto LABEL_42;
}
if ( v7 >= 0.0 )
{
if ( !(v15 << 31) )
break;
v16 = *(int **)(a1 + 348);
}
else
{
v16 = *(int **)(a1 + 348);
if ( !(((v20 < v16[6]) | v15) << 31) )
break;
}
if ( v7 <= 0.0 )
{
if ( v16 == (int *)v3[43] )
{
v18 = v16;
}
else
{
v18 = (int *)v16[1];
if ( !v3[31] || v3[35] == *((unsigned __int16 *)v16 + 14) )
{
if ( *(_DWORD *)(a1 + 276) )
{
result = sub_479CC(a1, *(_DWORD *)(a1 + 44), 0, 2, *((unsigned __int16 *)v16 + 15), 0);
if ( result )
return result;
}
}
*(_DWORD *)(a1 + 348) = v18;
}
if ( !(v15 << 31) )
goto LABEL_64;
if ( v18 != (int *)v3[43] )
{
LABEL_61:
v15 = 1;
goto LABEL_65;
}
v19 = *(_DWORD *)(v3[44] + 4);
}
else
{
LABEL_42:
if ( v16 == (int *)v3[44] )
{
v17 = v16;
}
else
{
v17 = (int *)*v16;
if ( !v3[31] || v3[35] == *((unsigned __int16 *)v16 + 14) )
{
if ( *(_DWORD *)(a1 + 276) )
{
result = sub_479CC(a1, *(_DWORD *)(a1 + 44), 0, 2, *((unsigned __int16 *)v16 + 15), 0);
if ( result )
return result;
}
}
*(_DWORD *)(a1 + 348) = v17;
}
if ( !(v15 << 31) )
goto LABEL_64;
if ( v17 != (int *)v3[44] )
goto LABEL_61;
v19 = *(_DWORD *)v3[43];
}
*(_DWORD *)(a1 + 348) = v19;
LABEL_64:
v15 = 0;
LABEL_65:
v7 = *(float *)(a1 + 388);
}
}
LABEL_8:
*(_DWORD *)(a1 + 352) = v20;
return 0;
}