//
// sub_74CA40 from 0x74ca40 to 0x74cc28 (488 bytes)
//
// 6 xrefs:
// > sub_74CC28 @ 0x74cc84
// > sub_75072C @ 0x750a6e
// > sub_75072C @ 0x750b0a
// > sub_75072C @ 0x750d4e
// > sub_75072C @ 0x750d8c
// > sub_75072C @ 0x750f0c
//
// 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
//
_DWORD *__fastcall sub_74CA40(
_DWORD *a1,
int a2,
_DWORD *a3,
int a4,
_DWORD *a5,
int a6,
int *a7,
int a8,
int a9,
unsigned int a10,
int a11,
_DWORD *a12)
{
int v12; // r5
char *v16; // r0
char *v18; // r11
int v19; // r6
unsigned int v20; // r10
int v21; // r7
int v22; // r3
bool v23; // zf
int v24; // r0
unsigned __int8 *v25; // r3
int v26; // r7
char *v27; // r7
int v28; // r3
int v29; // r3
unsigned int v30; // r3
unsigned __int8 *v31; // r3
unsigned __int8 *v32; // r3
int v33; // r0
int v35; // r0
int v36; // [sp+8h] [bp-14h]
int v37; // [sp+8h] [bp-14h]
int v38; // [sp+8h] [bp-14h]
int v39; // [sp+8h] [bp-14h]
v16 = (char *)sub_74C87C(a11 + 108);
if ( a10 == 2 )
v12 = 10;
v18 = v16;
if ( a10 != 2 )
{
if ( a10 == 4 )
v12 = 1000;
else
v12 = 1;
}
v19 = 0;
v20 = 0;
while ( a3 )
{
if ( a4 == -1 )
{
v31 = (unsigned __int8 *)a3[2];
if ( (unsigned int)v31 >= a3[3] )
{
v36 = a6;
v24 = (*(int (__fastcall **)(_DWORD *))(*a3 + 36))(a3);
a6 = v36;
if ( v24 == -1 )
break;
a4 = v24;
}
else
{
a4 = *v31;
}
}
v21 = 0;
if ( !a5 )
{
if ( v20 >= a10 )
goto LABEL_15;
goto LABEL_28;
}
if ( a6 != -1 )
goto LABEL_12;
LABEL_24:
v25 = (unsigned __int8 *)a5[2];
if ( (unsigned int)v25 >= a5[3] )
{
a6 = (*(int (__fastcall **)(_DWORD *))(*a5 + 36))(a5);
if ( a6 == -1 )
{
v22 = 1;
a5 = nullptr;
goto LABEL_13;
}
}
else
{
a6 = *v25;
}
LABEL_12:
v22 = 0;
LABEL_13:
if ( v21 == v22 || v20 >= a10 )
goto LABEL_15;
v26 = 255;
if ( a3 )
{
if ( a4 != -1 )
goto LABEL_28;
v32 = (unsigned __int8 *)a3[2];
if ( (unsigned int)v32 < a3[3] )
{
a4 = *v32;
LABEL_28:
v26 = (unsigned __int8)a4;
goto LABEL_29;
}
v39 = a6;
v35 = (*(int (__fastcall **)(_DWORD *))(*a3 + 36))(a3);
a6 = v39;
a4 = v35;
if ( v35 != -1 )
goto LABEL_28;
a3 = nullptr;
v26 = 255;
}
LABEL_29:
v27 = &v18[v26];
v28 = (unsigned __int8)v27[285];
if ( !v27[285] )
{
v37 = a6;
v33 = (*(int (__fastcall **)(char *))(*(_DWORD *)v18 + 32))(v18);
if ( v33 == 42 )
goto LABEL_15;
v28 = v33;
v27[285] = v33;
a6 = v37;
}
v29 = v28 - 48;
if ( (unsigned __int8)v29 > 9u )
goto LABEL_15;
v19 = v29 + 10 * v19;
if ( v12 * v19 > a9 || a8 >= v12 * v19 + v12 )
goto LABEL_15;
v12 /= 10;
if ( a3 )
{
v30 = a3[2];
if ( v30 >= a3[3] )
{
v38 = a6;
(*(void (__fastcall **)(_DWORD *))(*a3 + 40))(a3);
a6 = v38;
}
else
{
a3[2] = v30 + 1;
}
a4 = -1;
}
++v20;
}
if ( a5 )
{
a3 = nullptr;
v21 = 1;
if ( a6 != -1 )
goto LABEL_12;
goto LABEL_24;
}
a3 = nullptr;
LABEL_15:
if ( a10 == v20 )
{
LABEL_46:
*a7 = v19;
goto LABEL_47;
}
v23 = v20 == 2;
if ( v20 == 2 )
v23 = a10 == 4;
if ( v23 )
{
v19 -= 100;
goto LABEL_46;
}
*a12 |= 4u;
LABEL_47:
*a1 = a3;
a1[1] = a4;
return a1;
}