//
// sub_74A850 from 0x74a850 to 0x74a9f8 (424 bytes)
//
// 1 xrefs:
// > sub_75843C @ 0x758462
//
// 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_74A850(int *a1, int *a2, wchar_t a3)
{
int v6; // r3
_DWORD *v8; // r4
int *v9; // r3
int v10; // r5
unsigned int v11; // r6
wchar_t *v12; // r0
int v13; // r1
signed int v14; // r10
int v15; // r2
unsigned int v16; // r1
unsigned int v17; // r3
bool v18; // zf
unsigned int v19; // r2
const wchar_t *v20; // r0
int v21; // r3
int v22; // lr
int v23; // r10
int *v24; // r3
unsigned int v25; // r3
unsigned int v26; // r6
_BYTE v27[8]; // [sp+4h] [bp-8h] BYREF
sub_747D3C(v27, a1, 1);
if ( !v27[0] )
goto LABEL_2;
sub_7777D0(a2, 0, *(_DWORD *)(*a2 - 12), 0);
v8 = *(_DWORD **)((char *)a1 + *(_DWORD *)(*a1 - 12) + 124);
v9 = (int *)v8[2];
if ( (unsigned int)v9 >= v8[3] )
v10 = (*(int (__fastcall **)(_DWORD))(*v8 + 36))(*(int *)((char *)a1 + *(_DWORD *)(*a1 - 12) + 124));
else
v10 = *v9;
v11 = 0;
do
{
while ( 1 )
{
v18 = v10 == -1;
if ( v10 != -1 )
v18 = a3 == v10;
if ( v18 )
{
if ( v10 != -1 )
goto LABEL_33;
v6 = 2;
LABEL_36:
if ( !v11 )
v6 |= 4u;
goto LABEL_3;
}
v19 = v8[3];
v20 = (const wchar_t *)v8[2];
v14 = (int)(v19 - (_DWORD)v20) >> 2;
if ( v14 >= (int)(268435454 - v11) )
v14 = 268435454 - v11;
if ( v14 <= 1 )
break;
v12 = wmemchr(v20, a3, v14);
v13 = v8[2];
if ( v12 )
v14 = ((int)v12 - v13) >> 2;
sub_7785C8(a2, v13, v14);
v15 = v8[2];
v11 += v14;
v16 = v8[3];
v17 = v15 + 4 * v14;
v8[2] = v17;
if ( v17 >= v16 )
goto LABEL_38;
v10 = *(_DWORD *)(v15 + 4 * v14);
LABEL_12:
if ( v11 > 0xFFFFFFD )
goto LABEL_29;
}
v21 = *a2;
v22 = *(_DWORD *)(*a2 - 12);
v23 = v22 + 1;
if ( (unsigned int)(v22 + 1) > *(_DWORD *)(*a2 - 8) || *(int *)(v21 - 4) > 0 )
{
sub_778308(a2, v22 + 1);
v21 = *a2;
v20 = (const wchar_t *)v8[2];
v19 = v8[3];
v22 = *(_DWORD *)(*a2 - 12);
}
*(_DWORD *)(v21 + 4 * v22) = v10;
++v11;
if ( (_UNKNOWN *)(v21 - 12) != &unk_ACDDAC )
{
*(_DWORD *)(v21 - 12) = v23;
*(_DWORD *)(v21 - 4) = 0;
*(_DWORD *)(v21 + 4 * v23) = 0;
}
if ( (unsigned int)v20 >= v19 )
{
v10 = (*(int (__fastcall **)(_DWORD *))(*v8 + 40))(v8);
}
else
{
v10 = *v20;
v8[2] = v20 + 1;
}
if ( v10 == -1 )
goto LABEL_12;
v24 = (int *)v8[2];
if ( (unsigned int)v24 >= v8[3] )
{
LABEL_38:
v10 = (*(int (__fastcall **)(_DWORD *))(*v8 + 36))(v8);
goto LABEL_12;
}
v10 = *v24;
}
while ( v11 <= 0xFFFFFFD );
LABEL_29:
if ( v10 == -1 )
{
v6 = 2;
goto LABEL_3;
}
LABEL_33:
if ( a3 != v10 )
{
v6 = 4;
goto LABEL_36;
}
v25 = v8[2];
v26 = v11 + 1;
if ( v25 >= v8[3] )
{
(*(void (__fastcall **)(_DWORD *))(*v8 + 40))(v8);
if ( v26 )
return a1;
}
else
{
v8[2] = v25 + 4;
if ( v26 )
return a1;
}
LABEL_2:
v6 = 4;
LABEL_3:
sub_744C5C((int *)((char *)a1 + *(_DWORD *)(*a1 - 12)), *(int *)((char *)a1 + *(_DWORD *)(*a1 - 12) + 20) | v6);
return a1;
}