//
// sub_83C074 from 0x83c074 to 0x83c608 (1428 bytes)
//
// 1 xrefs:
// > ??> @ 0xac0f28
//
// 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_83C074(int a1, int a2, int a3, _DWORD *a4)
{
int v5; // r11
int v6; // r4
char *v8; // r7
int v9; // r10
int v10; // r6
_DWORD *v11; // r4
size_t v12; // r0
int v13; // r11
unsigned int v14; // r0
_DWORD *v15; // r11
pthread_rwlock_t *v16; // r0
signed int v17; // r1
int v18; // r0
int v19; // r9
unsigned int v20; // r0
int v21; // r3
const void *v22; // r1
int v23; // r9
signed int v24; // r1
_DWORD *v25; // r0
void *v26; // r5
int v27; // [sp+10h] [bp-190h]
signed int v28; // [sp+14h] [bp-18Ch]
int v31; // [sp+2Ch] [bp-174h]
int v33; // [sp+40h] [bp-160h] BYREF
_BYTE *v34; // [sp+44h] [bp-15Ch]
_DWORD v35[2]; // [sp+48h] [bp-158h] BYREF
_BYTE v36[108]; // [sp+50h] [bp-150h] BYREF
_BYTE v37[12]; // [sp+BCh] [bp-E4h] BYREF
int v38; // [sp+C8h] [bp-D8h]
int v39; // [sp+E4h] [bp-BCh]
if ( a3 )
{
v33 = a2;
if ( a2 == 1 )
{
v39 = a3;
v34 = v37;
v8 = &byte_9B1912;
v5 = BUF_MEM_new();
if ( v5 )
goto LABEL_7;
}
else
{
if ( a2 != 2 )
{
ERR_put_error(11, 103, 112, (int)"crypto/x509/by_dir.c", 236);
v5 = 0;
v6 = 0;
goto LABEL_5;
}
v38 = a3;
v34 = v37;
v8 = "r";
v5 = BUF_MEM_new();
if ( v5 )
{
LABEL_7:
v27 = *(_DWORD *)(a1 + 12);
v28 = 0;
v9 = v5;
v10 = X509_NAME_hash(a3);
while ( 1 )
{
if ( v28 >= OPENSSL_sk_num(*(_DWORD *)(v27 + 4)) )
{
v5 = v9;
v6 = 0;
goto LABEL_5;
}
v11 = (_DWORD *)OPENSSL_sk_value(*(_DWORD **)(v27 + 4), v28);
v12 = strlen((const char *)*v11);
if ( !BUF_MEM_grow((size_t *)v9, v12 + 17) )
{
v5 = v9;
v6 = 0;
ERR_put_error(11, 103, 65, (int)"crypto/x509/by_dir.c", 255);
goto LABEL_5;
}
if ( a2 != 2 )
{
if ( a2 == 1 )
{
v23 = 0;
do
BIO_snprintf(*(const void **)(v9 + 4), *(_DWORD *)(v9 + 8), "%s%c%08lx.%s%d", *v11, 47, v10, v8, v23++);
while ( stat(*(const char **)(v9 + 4), (struct stat *)v36) >= 0 && X509_load_cert_file() );
}
else
{
v13 = 0;
do
BIO_snprintf(*(const void **)(v9 + 4), *(_DWORD *)(v9 + 8), "%s%c%08lx.%s%d", *v11, 47, v10, v8, v13++);
while ( stat(*(const char **)(v9 + 4), (struct stat *)v36) >= 0 );
}
CRYPTO_THREAD_write_lock(*(pthread_rwlock_t **)(v27 + 8));
v14 = OPENSSL_sk_find(*(_DWORD *)(*(_DWORD *)(a1 + 16) + 4), (int)&v33);
if ( v14 == -1 )
{
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
}
else
{
v15 = (_DWORD *)OPENSSL_sk_value(*(_DWORD **)(*(_DWORD *)(a1 + 16) + 4), v14);
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
if ( v15 )
goto LABEL_31;
}
goto LABEL_16;
}
if ( v11[2] )
{
v16 = *(pthread_rwlock_t **)(v27 + 8);
v35[0] = v10;
CRYPTO_THREAD_read_lock(v16);
v17 = OPENSSL_sk_find(v11[2], (int)v35);
if ( v17 < 0 )
{
v31 = 0;
v19 = 0;
}
else
{
v18 = OPENSSL_sk_value((_DWORD *)v11[2], v17);
v19 = *(_DWORD *)(v18 + 4);
v31 = v18;
}
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
}
else
{
v31 = 0;
v19 = 0;
}
while ( 1 )
{
BIO_snprintf(*(const void **)(v9 + 4), *(_DWORD *)(v9 + 8), "%s%c%08lx.%s%d", *v11, 47, v10, v8, v19);
if ( stat(*(const char **)(v9 + 4), (struct stat *)v36) < 0 )
{
CRYPTO_THREAD_write_lock(*(pthread_rwlock_t **)(v27 + 8));
v20 = OPENSSL_sk_find(*(_DWORD *)(*(_DWORD *)(a1 + 16) + 4), (int)&v33);
if ( v20 == -1 )
goto LABEL_38;
LABEL_26:
v15 = (_DWORD *)OPENSSL_sk_value(*(_DWORD **)(*(_DWORD *)(a1 + 16) + 4), v20);
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
goto LABEL_27;
}
if ( !X509_load_crl_file(a1, *(_DWORD *)(v9 + 4), v11[1]) )
break;
++v19;
}
CRYPTO_THREAD_write_lock(*(pthread_rwlock_t **)(v27 + 8));
v20 = OPENSSL_sk_find(*(_DWORD *)(*(_DWORD *)(a1 + 16) + 4), (int)&v33);
if ( v20 != -1 )
goto LABEL_26;
LABEL_38:
v15 = nullptr;
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
LABEL_27:
CRYPTO_THREAD_write_lock(*(pthread_rwlock_t **)(v27 + 8));
v21 = v31;
if ( !v31 )
break;
LABEL_28:
if ( *(_DWORD *)(v21 + 4) < v19 )
*(_DWORD *)(v31 + 4) = v19;
LABEL_30:
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
if ( v15 )
{
LABEL_31:
v22 = v15 + 1;
*a4 = *v15;
v5 = v9;
memcpy(a4 + 1, v22, sizeof(_DWORD));
v6 = 1;
goto LABEL_5;
}
LABEL_16:
++v28;
}
v35[0] = v10;
v24 = OPENSSL_sk_find(v11[2], (int)v35);
if ( v24 >= 0 )
{
v31 = OPENSSL_sk_value((_DWORD *)v11[2], v24);
if ( v31 )
{
v21 = v31;
goto LABEL_28;
}
}
v25 = CRYPTO_malloc(byte_8, (int)"crypto/x509/by_dir.c", 349);
v26 = v25;
if ( v25 )
{
*v25 = v10;
v25[1] = v19;
if ( OPENSSL_sk_push((int *)v11[2], (int)v25) )
goto LABEL_30;
v6 = 0;
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
v5 = v9;
CRYPTO_free(v26, (int)"crypto/x509/by_dir.c", 360);
}
else
{
v5 = v9;
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(v27 + 8));
v6 = 0;
ERR_put_error(11, 103, 65, (int)"crypto/x509/by_dir.c", 352);
}
goto LABEL_5;
}
}
ERR_put_error(11, 103, 7, (int)"crypto/x509/by_dir.c", 241);
v6 = v5;
LABEL_5:
BUF_MEM_free(v5);
return v6;
}
return 0;
}