//
// sub_1004816C4 from 0x1004816c4 to 0x100481804 (320 bytes)
//
// 4 xrefs:
// > sub_100481A54 @ 0x100481b84
// > sub_100481A54 @ 0x100481bc4
// > sub_1004825A8 @ 0x100482714
// > sub_1004825A8 @ 0x100482740
//
// 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
//
__int64 __fastcall sub_1004816C4(
__int64 a1,
int *a2,
__int64 a3,
int a4,
__int64 a5,
char a6,
int a7,
int a8,
unsigned __int8 a9,
char a10)
{
int v10; // w10
int v11; // w9
int v12; // w13
int v13; // w16
int v14; // w15
__int64 v16; // x17
int v17; // w16
int v18; // w15
int v19; // w17
int v20; // w0
int v21; // w16
int v22; // w17
v10 = a2[1];
if ( v10 >= a4 )
{
v14 = a2[2];
v11 = *a2;
LABEL_23:
a2[3] = v14 >> 16;
*a2 = v11 + 1;
goto LABEL_24;
}
v11 = *a2;
if ( *a2 && v11 != *(unsigned __int16 *)(a5 + 4LL * v10) )
{
v14 = a2[2] + a2[4];
a2[2] = v14;
goto LABEL_23;
}
v12 = 2 * a7;
while ( 1 )
{
if ( (a6 & 4) != 0 && v10 == a8 )
{
v11 = *(unsigned __int16 *)(a5 + 2LL * v12);
*a2 = v11;
a2[1] = a7;
v16 = v12;
v17 = 2 * a7;
v10 = a7;
}
else
{
v17 = 2 * v10;
v16 = 2 * v10;
}
v18 = *(unsigned __int16 *)(a5 + 2LL * (v17 | 1));
if ( v10 == a4 - 1 )
{
a2[3] = v18;
*((_BYTE *)a2 + 20) = 1;
goto LABEL_24;
}
v19 = *(unsigned __int16 *)(a5 + 2 * v16);
v20 = *(unsigned __int16 *)(a5 + 2LL * (v17 + 2));
v21 = *(unsigned __int16 *)(a5 + 2LL * (v17 + 3));
if ( (a6 & 2) != 0 && v10 == a9 && !*(_BYTE *)(a3 + 188) )
break;
v22 = v20 - v19;
if ( v22 )
v13 = ((v21 - v18) << 16) / v22;
else
v13 = 0;
v14 = v18 << 16;
a2[4] = v13;
a2[1] = ++v10;
a2[2] = v14;
if ( v11 != *(unsigned __int16 *)(a5 + 4LL * v10) || v10 >= a4 )
goto LABEL_23;
}
a2[3] = v18;
LABEL_24:
*(_BYTE *)(a3 + 60) |= a10;
return 0;
}