//
// sub_A572AC from 0xa572ac to 0xa5754c (672 bytes)
//
// 2 xrefs:
// > sub_A589E0 @ 0xa5956c
// > sub_A589E0 @ 0xa599dc
//
// 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:08:26 +0000
//
int __fastcall sub_A572AC(int a1, signed int a2)
{
int *v2; // r8
int v5; // r0
signed int v6; // r6
unsigned int v7; // r4
int v8; // r7
int v9; // r0
int v10; // r3
_BOOL4 v12; // r3
int v13; // r3
int v14; // r2
int v15; // r0
int v16; // r0
int (__fastcall *v17)(int, int); // r4
int subject_name; // r0
_DWORD *v19; // r6
signed int v20; // r4
int v21; // r10
int v22; // r0
v2 = *(int **)(a1 + 128);
v5 = OPENSSL_sk_num(*(_DWORD *)(a1 + 80));
v6 = v5;
if ( v2 && (v2[5] & 5) != 0 )
{
v12 = a2 > 0;
if ( a2 >= v5 )
v12 = 0;
if ( v12 )
{
v13 = *(_DWORD *)(a1 + 128);
if ( v13 )
{
if ( (*(_DWORD *)(v13 + 20) & 5) != 0 )
{
v14 = OPENSSL_sk_value(*(_DWORD **)(a1 + 80), a2);
if ( v14 )
{
v15 = sub_A56ACC(*(_DWORD *)(a1 + 76), *(int **)(a1 + 128), v14, a2);
if ( v15 < 0 )
return 2;
if ( v15 )
{
*(_DWORD *)(a1 + 76) = a2 - 1;
return 1;
}
}
}
}
}
}
if ( a2 < v6 )
{
v7 = a2;
while ( 1 )
{
v8 = OPENSSL_sk_value(*(_DWORD **)(a1 + 80), v7);
v9 = X509_check_trust(v8, *(char **)(*(_DWORD *)(a1 + 16) + 20), 0);
if ( v9 == 1 )
break;
if ( v9 == 2 )
goto LABEL_35;
if ( ++v7 == v6 )
{
if ( (*(_DWORD *)(*(_DWORD *)(a1 + 16) + 12) & 0x80000) != 0 )
break;
return 3;
}
}
LABEL_9:
if ( !v2 || OPENSSL_sk_num(v2[1]) <= 0 )
return 1;
v10 = v2[6];
if ( v2[7] < 0 )
v2[7] = a2;
if ( v10 >= 0 )
return 1;
return 3;
}
if ( a2 == v6 && (*(_DWORD *)(*(_DWORD *)(a1 + 16) + 12) & 0x80000) != 0 )
{
v16 = OPENSSL_sk_value(*(_DWORD **)(a1 + 80), 0);
v17 = *(int (__fastcall **)(int, int))(a1 + 60);
v8 = v16;
subject_name = X509_get_subject_name(v16);
v19 = (_DWORD *)v17(a1, subject_name);
if ( v19 )
{
v20 = 0;
v21 = 0;
while ( v20 < OPENSSL_sk_num((int)v19) )
{
v21 = OPENSSL_sk_value(v19, v20);
if ( !X509_cmp(v21, v8) )
break;
++v20;
}
if ( OPENSSL_sk_num((int)v19) <= v20 )
{
OPENSSL_sk_pop_free((int)v19, (void (__fastcall *)(int))X509_free);
return 3;
}
X509_up_ref(v21);
OPENSSL_sk_pop_free((int)v19, (void (__fastcall *)(int))X509_free);
if ( v21 )
{
if ( X509_check_trust(v21, *(char **)(*(_DWORD *)(a1 + 16) + 20), 0) != 2 )
{
OPENSSL_sk_set(*(_DWORD **)(a1 + 80), 0, v21);
X509_free(v8);
*(_DWORD *)(a1 + 76) = 0;
goto LABEL_9;
}
X509_free(v21);
v7 = 0;
LABEL_35:
*(_DWORD *)(a1 + 92) = v7;
v22 = v8 ? v8 : OPENSSL_sk_value(*(_DWORD **)(a1 + 80), v7);
*(_DWORD *)(a1 + 100) = v22;
*(_DWORD *)(a1 + 96) = 28;
if ( !(*(int (__fastcall **)(_DWORD, int))(a1 + 28))(0, a1) )
return 2;
}
}
}
return 3;
}