//
// ASN1_item_d2i_bio from 0x1086798 to 0x1086b68 (976 bytes)
//
// 12 xrefs:
// > d2i_PKCS12_bio @ 0x104a178
// > d2i_X509_bio @ 0x106e2d4
// > d2i_X509_CRL_bio @ 0x106e324
// > d2i_PKCS7_bio @ 0x106e374
// > d2i_X509_REQ_bio @ 0x106e3c4
// > d2i_RSAPrivateKey_bio @ 0x106e46c
// > d2i_RSAPublicKey_bio @ 0x106e494
// > ASN1_item_d2i_fp @ 0x1086bb4
// > d2i_CMS_bio @ 0x109ceec
// > SMIME_read_ASN1 @ 0x10ef3b4
// > SMIME_read_ASN1 @ 0x10ef51c
// > ??> @ 0xf3430
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// 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 13:17:13 +0000
//
__int64 __fastcall ASN1_item_d2i_bio(__int64 a1, __int64 a2, __int64 *a3)
{
size_t *v6; // x19
__int64 v7; // x20
unsigned __int64 v9; // x20
char *v10; // x22
int v11; // w26
__int64 v12; // x28
int v13; // w0
unsigned __int64 v14; // x0
char *v15; // x27
char object; // w28
char *v17; // x2
char *v18; // x27
unsigned __int64 v19; // d11
unsigned __int64 v20; // x1
unsigned __int64 v21; // d12
unsigned __int64 v22; // x28
int v23; // w0
__int64 v24; // x0
int v25; // [xsp+98h] [xbp+98h] BYREF
int v26; // [xsp+9Ch] [xbp+9Ch] BYREF
char *v27; // [xsp+A0h] [xbp+A0h] BYREF
unsigned __int64 v28; // [xsp+A8h] [xbp+A8h] BYREF
v6 = (size_t *)BUF_MEM_new();
if ( v6 )
{
ERR_clear_error();
v9 = 0;
v10 = nullptr;
v11 = 0;
while ( 1 )
{
LABEL_6:
v12 = v9 - (_QWORD)v10;
if ( v9 - (unsigned __int64)v10 > 8 )
goto LABEL_14;
LABEL_7:
if ( v9 > (unsigned __int64)(v10 + 8) || !BUF_MEM_grow_clean(v6, (unsigned __int64)(v10 + 8)) )
{
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 121);
goto LABEL_41;
}
v13 = BIO_read(a2, v6[1] + v9, (int)v10 + 8 - (int)v9);
if ( v13 < 0 && (char *)v9 == v10 )
{
ERR_put_error(13, 107, 142, (__int64)"crypto/asn1/a_d2i_fp.c", 126);
goto LABEL_41;
}
if ( v13 <= 0 )
goto LABEL_14;
v14 = v9 + v13;
if ( v9 > v14 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 131);
goto LABEL_41;
}
v12 = v14 - (_QWORD)v10;
v9 = v14;
while ( 1 )
{
LABEL_14:
v15 = &v10[v6[1]];
v27 = v15;
object = ASN1_get_object(&v27, (signed __int64 *)&v28, &v25, &v26, v12);
if ( object < 0 )
{
if ( (ERR_peek_error() & 0xFFF) != 0x9B )
goto LABEL_41;
ERR_clear_error();
}
v10 += (int)v27 - (int)v15;
if ( (object & 1) == 0 )
break;
if ( v11 == -1 )
{
ERR_put_error(13, 107, 123, (__int64)"crypto/asn1/a_d2i_fp.c", 157);
goto LABEL_41;
}
v12 = v9 - (_QWORD)v10;
++v11;
if ( v9 - (unsigned __int64)v10 <= 8 )
goto LABEL_7;
}
if ( !v11 || v28 )
break;
if ( !v25 && !--v11 )
{
v17 = v10;
goto LABEL_45;
}
}
v17 = &v10[v28];
if ( v28 > v9 - (unsigned __int64)v10 )
{
v18 = &v17[-v9];
if ( (unsigned __int64)&v17[-v9] > 0x7FFFFFFF || (unsigned __int64)v17 < v9 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 178);
goto LABEL_41;
}
v19 = 0x4000;
if ( v18 )
{
while ( 1 )
{
v20 = v19;
if ( v19 > (unsigned __int64)v18 )
v20 = (unsigned __int64)v18;
v21 = v20;
if ( !BUF_MEM_grow_clean(v6, v20 + v9) )
break;
v22 = v21;
do
{
v23 = BIO_read(a2, v6[1] + v9, v22);
if ( v23 <= 0 )
{
ERR_put_error(13, 107, 142, (__int64)"crypto/asn1/a_d2i_fp.c", 199);
goto LABEL_41;
}
v22 -= v23;
v9 += v23;
}
while ( v22 );
v24 = 2 * v19;
if ( v19 > 0x3FFFFFFE )
v24 = v19;
v19 = v24;
v18 -= v21;
if ( !v18 )
{
v17 = &v10[v28];
goto LABEL_35;
}
}
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 191);
goto LABEL_41;
}
}
LABEL_35:
if ( v10 > v17 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 214);
goto LABEL_41;
}
if ( v11 )
{
v10 = v17;
goto LABEL_6;
}
LABEL_45:
if ( (unsigned __int64)v17 <= 0x7FFFFFFF )
{
v28 = v6[1];
v7 = ASN1_item_d2i(a3, (char **)&v28, (__int64)v17, a1);
goto LABEL_4;
}
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 226);
LABEL_41:
BUF_MEM_free((__int64)v6);
}
else
{
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 111);
}
v6 = nullptr;
v7 = 0;
LABEL_4:
BUF_MEM_free((__int64)v6);
return v7;
}