//
// sub_849CC8 from 0x849cc8 to 0x849eb8 (496 bytes)
//
// 1 xrefs:
// > ??> @ 0xa39160
//
// 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_849CC8(int **a1, void **a2)
{
int *v2; // r6
signed int *v4; // r3
signed int v5; // r4
int result; // r0
signed int v7; // r4
size_t *v8; // r0
int *v9; // r7
int v10; // r8
int v11; // r5
int v12; // r0
unsigned int v13; // r1
size_t *v15; // [sp+8h] [bp-Ch] BYREF
int v16; // [sp+Ch] [bp-8h] BYREF
v2 = *a1;
if ( !(*a1)[1] )
goto LABEL_2;
v7 = 0;
v8 = OPENSSL_sk_new_null();
v15 = v8;
if ( !v8 )
{
LABEL_21:
OPENSSL_sk_pop_free((int)v8, (void (__fastcall *)(int))j_OPENSSL_sk_free_0);
ERR_put_error(13, 203, 65, (int)"crypto/x509/x_name.c", 288);
return -1;
}
v9 = nullptr;
v10 = -1;
while ( 1 )
{
v12 = OPENSSL_sk_num(*v2);
v13 = v7;
if ( v7++ >= v12 )
break;
v11 = OPENSSL_sk_value((_DWORD *)*v2, v13);
if ( *(_DWORD *)(v11 + 8) != v10 )
{
v9 = OPENSSL_sk_new_null();
v8 = v15;
if ( !v9 )
goto LABEL_21;
if ( !OPENSSL_sk_push((int *)v15, (int)v9) )
goto LABEL_20;
v10 = *(_DWORD *)(v11 + 8);
}
if ( !OPENSSL_sk_push(v9, v11) )
goto LABEL_20;
}
v5 = ASN1_item_ex_i2d(&v15, nullptr, byte_A39114, -1, -1);
if ( !BUF_MEM_grow((size_t *)v2[2], v5) )
{
LABEL_20:
v8 = v15;
goto LABEL_21;
}
v16 = *(_DWORD *)(v2[2] + 4);
ASN1_item_ex_i2d(&v15, &v16, byte_A39114, -1, -1);
OPENSSL_sk_pop_free((int)v15, (void (__fastcall *)(int))j_OPENSSL_sk_free_0);
v2[1] = 0;
if ( v5 < 0 )
return v5;
CRYPTO_free((void *)v2[3], (int)"crypto/x509/x_name.c", 320);
v2[3] = 0;
if ( !OPENSSL_sk_num(*v2) )
{
v2[4] = 0;
goto LABEL_2;
}
result = sub_849870(v2);
if ( result >= 0 )
{
LABEL_2:
v4 = (signed int *)v2[2];
v5 = *v4;
if ( a2 )
{
memcpy(*a2, (const void *)v4[1], *v4);
result = v5;
*a2 = (char *)*a2 + v5;
}
else
{
return v5;
}
}
return result;
}