//
// sub_74A4BC from 0x74a4bc to 0x74a620 (356 bytes)
//
// 1 xrefs:
// > sub_747C80 @ 0x747caa
//
// 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
//
int *__fastcall sub_74A4BC(int *a1, wchar_t *a2, int a3, wchar_t a4)
{
int v8; // r1
_DWORD *v9; // r5
int *v10; // r3
int v11; // r2
int v12; // r3
bool v13; // zf
int v14; // r0
bool v15; // r1
unsigned int v16; // r1
const wchar_t *v17; // r0
int v18; // r3
signed int v19; // r4
wchar_t *v20; // r0
const wchar_t *v21; // r1
int v22; // r0
unsigned int v23; // lr
unsigned int v24; // r1
int v25; // r3
unsigned int v27; // r3
unsigned int v28; // r2
int *v29; // r3
_BYTE v30[8]; // [sp+4h] [bp-8h] BYREF
a1[1] = 0;
sub_747D3C(v30, a1, 1);
v8 = v30[0];
if ( v30[0] )
{
v9 = *(_DWORD **)((char *)a1 + *(_DWORD *)(*a1 - 12) + 124);
v10 = (int *)v9[2];
if ( (unsigned int)v10 >= v9[3] )
v11 = (*(int (__fastcall **)(_DWORD))(*v9 + 36))(*(int *)((char *)a1 + *(_DWORD *)(*a1 - 12) + 124));
else
v11 = *v10;
LABEL_4:
v12 = a1[1];
while ( 1 )
{
v13 = a4 == v11;
if ( a4 != v11 )
v13 = v11 == -1;
v14 = v12 + 1;
v15 = !v13;
v8 = v14 < a3 && v15;
if ( !v8 )
break;
v16 = v9[3];
v17 = (const wchar_t *)v9[2];
v18 = a3 - v12 - 1;
v19 = (int)(v16 - (_DWORD)v17) >> 2;
if ( v19 >= v18 )
v19 = v18;
if ( v19 <= 1 )
{
*a2++ = v11;
++a1[1];
if ( v16 <= (unsigned int)v17 )
{
v11 = (*(int (__fastcall **)(_DWORD *))(*v9 + 40))(v9);
}
else
{
v11 = *v17;
v9[2] = v17 + 1;
}
if ( v11 == -1 )
goto LABEL_4;
v29 = (int *)v9[2];
if ( (unsigned int)v29 >= v9[3] )
{
LABEL_40:
v11 = (*(int (__fastcall **)(_DWORD *))(*v9 + 36))(v9);
goto LABEL_4;
}
v11 = *v29;
v12 = a1[1];
}
else
{
v20 = wmemchr(v17, a4, v19);
v21 = (const wchar_t *)v9[2];
if ( v20 )
v19 = v20 - v21;
wmemcpy(a2, v21, v19);
v22 = v9[2];
v23 = v9[3];
v24 = v22 + 4 * v19;
v25 = a1[1];
v9[2] = v24;
v12 = v25 + v19;
a2 += v19;
a1[1] = v12;
if ( v24 >= v23 )
goto LABEL_40;
v11 = *(_DWORD *)(v22 + 4 * v19);
}
}
if ( v11 == -1 )
{
v8 = 2;
}
else if ( a4 == v11 )
{
v27 = v9[2];
v28 = v9[3];
a1[1] = v14;
if ( v27 >= v28 )
{
(*(void (__fastcall **)(_DWORD *))(*v9 + 40))(v9);
v8 = 0;
}
else
{
v9[2] = v27 + 4;
}
}
else
{
v8 = 4;
}
}
if ( a3 > 0 )
*a2 = 0;
if ( !a1[1] )
{
v8 |= 4u;
LABEL_26:
sub_744C5C((int *)((char *)a1 + *(_DWORD *)(*a1 - 12)), v8 | *(int *)((char *)a1 + *(_DWORD *)(*a1 - 12) + 20));
return a1;
}
if ( v8 )
goto LABEL_26;
return a1;
}