//
// sub_8202A4 from 0x8202a4 to 0x820412 (366 bytes)
//
// 8 xrefs:
// > sub_82042C @ 0x8204b2
// > sub_82042C @ 0x82051a
// > sub_828FD8 @ 0x829126
// > sub_82A4FC @ 0x82a678
// > sub_82A4FC @ 0x82a774
// > sub_83CCC8 @ 0x83d318
// > sub_845000 @ 0x8450ce
// > sub_84542C @ 0x84570e
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:01:50 +0000
//
int __fastcall sub_8202A4(int *a1, const char *a2, int a3, const char **a4)
{
int v5; // r5
int v7; // r7
const char *v8; // r0
char *v9; // r10
int v10; // r4
bool v11; // zf
char *v12; // r1
int v13; // t1
bool v14; // zf
size_t v15; // r4
const char *v16; // r11
int v17; // r1
int v18; // r4
int v19; // r6
int result; // r0
char *v21; // [sp+0h] [bp-14h]
int v22; // [sp+4h] [bp-10h]
int v23; // [sp+8h] [bp-Ch]
time_t timer; // [sp+Ch] [bp-8h] BYREF
v5 = *a1;
*a4 = nullptr;
v21 = (char *)a2;
v22 = a3;
if ( *(_DWORD *)(v5 + 72) )
{
sub_841E84(v5, 3, 2);
a2 = v21;
a3 = v22;
}
v7 = *a1;
v8 = (const char *)sub_837044("%s:%d", a2, a3);
v9 = (char *)v8;
if ( v8 )
{
v10 = *(unsigned __int8 *)v8;
v11 = v10 == 58;
if ( v10 != 58 )
v11 = v10 == 0;
if ( !v11 )
{
v12 = (char *)v8;
do
{
*v12 = *(_WORD *)(tolower_tab_ + 2 * (v10 + 1));
v13 = (unsigned __int8)*++v12;
v10 = v13;
v14 = v13 == 58;
if ( v13 != 58 )
v14 = v10 == 0;
}
while ( !v14 );
}
v15 = strlen(v8) + 1;
v16 = (const char *)sub_83E594(*(_DWORD *)(v7 + 56), v9, v15);
if ( v16 )
{
if ( *(_DWORD *)(v7 + 844) == -1
|| (time(&timer), v23 = *(_DWORD *)(v7 + 844), (v17 = *((_DWORD *)v16 + 1)) == 0)
|| *(_DWORD *)(v7 + 844) > timer - v17 )
{
off_D200B0(v9);
sub_8280FC(v5, "Hostname %s was found in DNS cache\n", v21);
++*((_DWORD *)v16 + 2);
v18 = *(_DWORD *)(v5 + 72);
if ( v18 )
{
v18 = 0;
sub_841EA4(v5, 3);
}
goto LABEL_28;
}
sub_8280FC(v7, "Hostname in DNS cache was stale, zapped\n");
sub_83E540(*(_DWORD *)(v7 + 56), v9, v15);
}
off_D200B0(v9);
}
v18 = -1;
if ( *(_DWORD *)(v5 + 72) )
sub_841EA4(v5, 3);
if ( !sub_8426E4(a1) )
return -1;
v19 = sub_84272C((int)a1, v21);
if ( v19 )
{
if ( *(_DWORD *)(v5 + 72) )
sub_841E84(v5, 3, 2);
v16 = sub_8201C8(v5, v19, v21, v22);
if ( *(_DWORD *)(v5 + 72) )
sub_841EA4(v5, 3);
if ( v16 )
v18 = 0;
else
sub_845B5C(v19);
goto LABEL_28;
}
if ( v23 )
return -1;
v16 = nullptr;
LABEL_28:
result = v18;
*a4 = v16;
return result;
}