//
// ASN1_item_ex_new from 0x9de6ec to 0x9deafc (1040 bytes)
//
// 8 xrefs:
// > sub_9D9D48 @ 0x9da4fc
// > sub_9D9D48 @ 0x9da9c4
// > sub_9DAE6C @ 0x9db670
// > sub_9DAE6C @ 0x9db728
// > ASN1_item_ex_d2i @ 0x9dc074
// > ASN1_item_ex_d2i @ 0x9dc130
// > ASN1_item_new @ 0x9deb34
// > ??> @ 0x784fc
//
// 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:07:18 +0000
//
int __fastcall ASN1_item_ex_new(void **a1, int a2)
{
int v2; // r3
void **v4; // r5
int (__fastcall *v5)(int, void **, int, _DWORD); // r7
int *v6; // r2
int v7; // r3
int v8; // r1
int v9; // r2
int v10; // r0
int (__fastcall *v12)(void **, int); // r3
int v13; // r0
int v14; // r0
int v15; // r0
int v16; // r0
int *v17; // r6
int v18; // r8
int field_ptr; // r0
int v20; // r3
int v21; // r1
int v22; // r2
int *v23; // r9
int v24; // r0
int v25; // r0
void **v26; // [sp+Ch] [bp-4h] BYREF
v2 = *(_DWORD *)(a2 + 16);
v4 = a1;
if ( !v2 )
{
switch ( *(_BYTE *)a2 )
{
case 0:
LABEL_4:
v6 = *(int **)(a2 + 8);
if ( v6 )
{
v7 = *v6;
v8 = v6[4];
v9 = *v6 & 0x1000;
if ( v9 )
{
v26 = a1;
v4 = (void **)&v26;
}
v10 = v7 & 1;
if ( (v7 & 1) != 0 )
{
if ( (v7 & 0x306) != 0 )
*v4 = nullptr;
else
sub_9DE204(v4, v8);
return 1;
}
if ( (v7 & 0x300) != 0 )
{
LABEL_51:
*v4 = (void *)v10;
return 1;
}
if ( (v7 & 6) != 0 )
{
v10 = OPENSSL_sk_new_null(0);
if ( !v10 )
goto LABEL_59;
goto LABEL_51;
}
if ( sub_9DE2C0(v4, v8, v9) )
return 1;
}
else if ( sub_9DE060(a1, a2, 0) )
{
return 1;
}
LABEL_13:
ERR_put_error(13, 121, 65, "crypto/asn1/tasn_new.c", 145);
return 0;
case 1:
case 6:
v5 = nullptr;
LABEL_27:
v16 = CRYPTO_zalloc(*(_DWORD *)(a2 + 20), "crypto/asn1/tasn_new.c", 122);
*v4 = (void *)v16;
if ( !v16 || asn1_do_lock(v4, 0, a2) < 0 )
goto LABEL_13;
asn1_enc_init(v4, a2);
v17 = *(int **)(a2 + 8);
if ( *(int *)(a2 + 12) <= 0 )
goto LABEL_52;
v18 = 0;
break;
case 2:
LABEL_43:
v25 = CRYPTO_zalloc(*(_DWORD *)(a2 + 20), "crypto/asn1/tasn_new.c", 97);
*v4 = (void *)v25;
if ( !v25 )
goto LABEL_13;
asn1_set_choice_selector(v4, -1, a2);
return 1;
case 5:
LABEL_12:
if ( sub_9DE060(a1, a2, 0) )
return 1;
goto LABEL_13;
default:
return 1;
}
while ( 1 )
{
field_ptr = asn1_get_field_ptr(v4, v17);
v20 = *v17;
v21 = v17[4];
v22 = *v17 & 0x1000;
v23 = (int *)field_ptr;
if ( v22 )
{
v26 = (void **)field_ptr;
v23 = (int *)&v26;
}
v24 = v20 & 1;
if ( (v20 & 1) != 0 )
{
if ( (v20 & 0x306) != 0 )
*v23 = 0;
else
sub_9DE204(v23, v21);
}
else
{
if ( (v20 & 0x300) == 0 )
{
if ( (v20 & 6) == 0 )
{
if ( !sub_9DE2C0((void **)v23, v21, v22) )
goto LABEL_13;
goto LABEL_35;
}
v24 = OPENSSL_sk_new_null(0);
if ( !v24 )
{
LABEL_59:
ERR_put_error(13, 133, 65, "crypto/asn1/tasn_new.c", 223);
goto LABEL_13;
}
}
*v23 = v24;
}
LABEL_35:
++v18;
v17 += 5;
if ( v18 >= *(_DWORD *)(a2 + 12) )
{
LABEL_52:
if ( v5 )
goto LABEL_21;
return 1;
}
}
}
v5 = *(int (__fastcall **)(int, void **, int, _DWORD))(v2 + 16);
if ( !v5 )
{
switch ( *(_BYTE *)a2 )
{
case 0:
goto LABEL_4;
case 1:
case 6:
goto LABEL_27;
case 2:
goto LABEL_43;
case 4:
LABEL_14:
v12 = *(int (__fastcall **)(void **, int))(v2 + 4);
if ( !v12 || v12(a1, a2) )
return 1;
goto LABEL_13;
case 5:
goto LABEL_12;
default:
return 1;
}
}
switch ( *(_BYTE *)a2 )
{
case 0:
goto LABEL_4;
case 1:
case 6:
v15 = v5(0, a1, a2, 0);
if ( !v15 )
goto LABEL_22;
if ( v15 == 2 )
return 1;
goto LABEL_27;
case 2:
v13 = v5(0, a1, a2, 0);
if ( !v13 )
goto LABEL_22;
if ( v13 == 2 )
return 1;
v14 = CRYPTO_zalloc(*(_DWORD *)(a2 + 20), "crypto/asn1/tasn_new.c", 97);
*v4 = (void *)v14;
if ( !v14 )
goto LABEL_13;
asn1_set_choice_selector(v4, -1, a2);
break;
case 4:
goto LABEL_14;
case 5:
goto LABEL_12;
default:
return 1;
}
LABEL_21:
if ( v5(1, v4, a2, 0) )
return 1;
LABEL_22:
ERR_put_error(13, 121, 100, "crypto/asn1/tasn_new.c", 152);
ASN1_item_ex_free(v4, a2);
return 0;
}