//
// sub_1004E0578 from 0x1004e0578 to 0x1004e067c (260 bytes)
//
// 0 xrefs:
//
// 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_1004E0578(__int64 a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
__int64 v6; // x22
int v7; // w21
double v8; // d8
__int64 v9; // x23
unsigned int v10; // w24
double v11; // d9
unsigned int v12; // w25
double v13; // d0
double v14; // d0
double v15; // d0
if ( !a2 )
return 1;
v6 = 0;
v7 = 0;
v8 = 0.240226507 / (double)a3;
v9 = a2;
v10 = a3 - 1;
v11 = 4294967300.0;
v12 = a4;
do
{
v15 = *(double *)(a1 + 8 * v6);
if ( v15 <= 0.0 )
{
if ( v15 >= 0.0 )
v13 = 0.0;
else
v13 = 1.0e32;
}
else
{
v13 = log(v8 * v15) * 0.5 / 0.693147181;
if ( v13 < 0.0 )
v13 = 0.0;
}
v14 = (double)v12 + v13 * (double)v10;
if ( v14 < v11 )
{
v7 = v6;
v11 = v14;
}
++v6;
--v10;
v12 += a4;
}
while ( v9 != v6 );
return (unsigned int)(v7 + 1);
}