//
// sub_667F7C from 0x667f7c to 0x668172 (502 bytes)
//
// 5 xrefs:
// > sub_668188 @ 0x668470
// > sub_668498 @ 0x668608
// > sub_66861C @ 0x668672
// > sub_668688 @ 0x668834
// > sub_66885C @ 0x6689d6
//
// 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
//
void *__fastcall sub_667F7C(_DWORD *a1, char a2)
{
int v4; // r5
int v5; // r3
_BYTE *v6; // r2
void *result; // r0
int v8; // r2
int v9; // r3
_BYTE *v10; // r2
int v11; // r2
int v12; // r6
int v13; // r6
int v14; // r6
int v15; // r6
v4 = a1[106];
sub_667BF4((int)a1);
v5 = a1[6];
v6 = *(_BYTE **)v5;
result = (void *)(*(_DWORD *)v5 + 1);
*(_DWORD *)v5 = result;
*v6 = -1;
v8 = *(_DWORD *)(v5 + 4) - 1;
*(_DWORD *)(v5 + 4) = v8;
if ( !v8 )
{
result = (void *)(*(int (__fastcall **)(_DWORD *))(v5 + 12))(a1);
if ( !result )
{
*(_DWORD *)(*a1 + 20) = 25;
result = (void *)(*(int (__fastcall **)(_DWORD *))*a1)(a1);
}
}
v9 = a1[6];
v10 = (_BYTE *)(*(_DWORD *)v9)++;
*v10 = a2 - 48;
v11 = *(_DWORD *)(v9 + 4) - 1;
*(_DWORD *)(v9 + 4) = v11;
if ( !v11 )
{
result = (void *)(*(int (__fastcall **)(_DWORD *))(v9 + 12))(a1);
if ( !result )
{
*(_DWORD *)(*a1 + 20) = 25;
result = (void *)(*(int (__fastcall **)(_DWORD *))*a1)(a1);
}
}
if ( (int)a1[73] <= 0 )
goto LABEL_15;
v12 = a1[74];
if ( a1[91] || a1[93] )
{
if ( !a1[92] )
goto LABEL_6;
}
else
{
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v12 + 20) + 76), 0, 0x40u);
*(_DWORD *)(v4 + 36) = 0;
*(_DWORD *)(v4 + 52) = 0;
if ( !a1[92] )
goto LABEL_6;
}
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v12 + 24) + 140), 0, 0x100u);
LABEL_6:
if ( (int)a1[73] <= 1 )
goto LABEL_15;
v13 = a1[75];
if ( a1[91] || a1[93] )
{
if ( !a1[92] )
goto LABEL_9;
}
else
{
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v13 + 20) + 76), 0, 0x40u);
*(_DWORD *)(v4 + 40) = 0;
*(_DWORD *)(v4 + 56) = 0;
if ( !a1[92] )
goto LABEL_9;
}
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v13 + 24) + 140), 0, 0x100u);
LABEL_9:
if ( (int)a1[73] <= 2 )
goto LABEL_15;
v14 = a1[76];
if ( a1[91] || a1[93] )
{
if ( !a1[92] )
goto LABEL_12;
}
else
{
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v14 + 20) + 76), 0, 0x40u);
*(_DWORD *)(v4 + 44) = 0;
*(_DWORD *)(v4 + 60) = 0;
if ( !a1[92] )
goto LABEL_12;
}
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v14 + 24) + 140), 0, 0x100u);
LABEL_12:
if ( (int)a1[73] > 3 )
{
v15 = a1[77];
if ( a1[91] || a1[93] )
{
if ( a1[92] )
LABEL_18:
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v15 + 24) + 140), 0, 0x100u);
}
else
{
result = memset(*(void **)(v4 + 4 * *(_DWORD *)(v15 + 20) + 76), 0, 0x40u);
*(_DWORD *)(v4 + 48) = 0;
*(_DWORD *)(v4 + 64) = 0;
if ( a1[92] )
goto LABEL_18;
}
}
LABEL_15:
*(_QWORD *)(v4 + 12) = 0x1000000000000LL;
*(_QWORD *)(v4 + 20) = 0;
*(_QWORD *)(v4 + 28) = -4294967285LL;
return result;
}