//
// sub_10058B9CC from 0x10058b9cc to 0x10058baec (288 bytes)
//
// 1 xrefs:
// > sub_1005DE730 @ 0x1005de794
//
// 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_10058B9CC(
__int64 a1,
__int64 a2,
__int64 a3,
int a4,
__int64 (__fastcall *a5)(__int64, __int64),
char a6)
{
__int64 v9; // x25
__int64 v12; // x23
int v13; // w26
__int64 v14; // x27
int v15; // w0
int v16; // w8
bool v17; // w9
__int64 v18; // x24
__int64 v19; // x23
int v20; // w26
bool v21; // vf
int v22; // w0
v9 = a3;
v12 = 0;
if ( (_DWORD)a3 )
{
v13 = 0;
LODWORD(v14) = 0;
v15 = 0;
LABEL_4:
v16 = v14;
v14 = v9;
while ( 1 )
{
v9 = v14;
if ( v13 >= (int)v14 )
break;
v14 = (unsigned int)(((int)v14 + v13) / 2);
v12 = a2 + (int)v14 * a4;
v15 = a5(a1, v12);
v16 = v14;
if ( (v15 & 0x80000000) == 0 )
{
if ( v15 >= 1 )
{
v13 = v14 + 1;
goto LABEL_4;
}
v17 = 0;
v16 = v14;
goto LABEL_12;
}
}
v17 = v15 != 0;
if ( (a6 & 1) == 0 && v15 )
return 0;
LABEL_12:
if ( (a6 & 2) != 0 && !v17 )
{
v18 = v16;
v19 = a2 + (v16 - 1LL) * a4;
do
{
v20 = v18;
v21 = __OFSUB__(v18--, 1);
if ( v18 < 0 != v21 )
break;
v22 = a5(a1, v19);
v19 -= a4;
}
while ( !v22 );
return a2 + v20 * a4;
}
}
return v12;
}