//
// sub_1006066D4 from 0x1006066d4 to 0x100606834 (352 bytes)
//
// 3 xrefs:
// > sub_100602E38 @ 0x100602e40
// > sub_100602E68 @ 0x100602e70
// > sub_100602E74 @ 0x100602e78
//
// 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_1006066D4(unsigned int *a1, int a2, int *a3, int *a4)
{
int v8; // w8
int v9; // w23
__int64 *v10; // x24
__int64 *v11; // x25
int v13; // w8
if ( !a1 )
{
if ( a4 )
*a4 = -1;
if ( !a3 )
return 0;
LABEL_31:
v13 = -1;
goto LABEL_32;
}
if ( a4 )
v8 = *a4 + 1;
else
v8 = 0;
if ( v8 >= 0 )
v9 = v8;
else
v9 = 0;
if ( v9 >= (int)sub_1005DEA4C(a1) )
{
LABEL_28:
if ( a4 )
*a4 = -1;
if ( !a3 )
return 0;
goto LABEL_31;
}
if ( a4 )
{
while ( 1 )
{
v10 = (__int64 *)sub_1005DEA60((__int64)a1, v9);
if ( (unsigned int)sub_10058AE10(*v10) == a2 )
break;
if ( ++v9 >= (int)sub_1005DEA4C(a1) )
goto LABEL_28;
}
*a4 = v9;
LABEL_24:
if ( v10 )
{
if ( a3 )
*a3 = sub_100602E04((__int64)v10);
return sub_1006065E4(v10);
}
goto LABEL_28;
}
v10 = nullptr;
while ( 1 )
{
v11 = (__int64 *)sub_1005DEA60((__int64)a1, v9);
if ( (unsigned int)sub_10058AE10(*v11) == a2 )
break;
LABEL_21:
if ( ++v9 >= (int)sub_1005DEA4C(a1) )
goto LABEL_24;
}
if ( !v10 )
{
v10 = v11;
goto LABEL_21;
}
if ( a3 )
{
v13 = -2;
LABEL_32:
*a3 = v13;
}
return 0;
}