//
// ASN1_d2i_bio from 0x108632c to 0x10866f8 (972 bytes)
//
// 11 xrefs:
// > d2i_RSA_PUBKEY_bio @ 0x106e4b0
// > d2i_DSAPrivateKey_bio @ 0x106e554
// > d2i_DSA_PUBKEY_bio @ 0x106e584
// > d2i_EC_PUBKEY_bio @ 0x106e614
// > d2i_ECPrivateKey_bio @ 0x106e644
// > d2i_PKCS8_bio @ 0x106e784
// > d2i_PKCS8_PRIV_KEY_INFO_bio @ 0x106e898
// > d2i_PrivateKey_bio @ 0x106e930
// > d2i_PUBKEY_bio @ 0x106e960
// > ASN1_d2i_fp @ 0x108674c
// > ??> @ 0x54490
//
// 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_d2i_bio(
__int64 a1,
__int64 (__fastcall *a2)(__int64, unsigned __int64 *),
__int64 a3,
__int64 a4)
{
size_t *v7; // x19
__int64 v8; // x20
unsigned __int64 v10; // x20
unsigned __int64 v11; // x22
int v12; // w26
__int64 v13; // x28
int v14; // w0
unsigned __int64 v15; // x0
_BYTE *v16; // x27
char object; // w28
unsigned __int64 v18; // x2
unsigned __int64 v19; // x27
unsigned __int64 v20; // d11
unsigned __int64 v21; // x1
unsigned __int64 v22; // d12
unsigned __int64 v23; // x28
int v24; // w0
__int64 v25; // x0
int v26; // [xsp+98h] [xbp+98h] BYREF
int v27; // [xsp+9Ch] [xbp+9Ch] BYREF
_BYTE *v28; // [xsp+A0h] [xbp+A0h] BYREF
unsigned __int64 v29; // [xsp+A8h] [xbp+A8h] BYREF
v7 = (size_t *)BUF_MEM_new();
if ( v7 )
{
ERR_clear_error();
v10 = 0;
v11 = 0;
v12 = 0;
while ( 1 )
{
LABEL_6:
v13 = v10 - v11;
if ( v10 - v11 > 8 )
goto LABEL_14;
LABEL_7:
if ( v10 > v11 + 8 || !BUF_MEM_grow_clean(v7, v11 + 8) )
{
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 121);
goto LABEL_41;
}
v14 = BIO_read(a3, v7[1] + v10, (int)v11 + 8 - (int)v10);
if ( v14 < 0 && v10 == v11 )
{
ERR_put_error(13, 107, 142, (__int64)"crypto/asn1/a_d2i_fp.c", 126);
goto LABEL_41;
}
if ( v14 <= 0 )
goto LABEL_14;
v15 = v10 + v14;
if ( v10 > v15 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 131);
goto LABEL_41;
}
v13 = v15 - v11;
v10 = v15;
while ( 1 )
{
LABEL_14:
v16 = (_BYTE *)(v7[1] + v11);
v28 = v16;
object = ASN1_get_object(&v28, (signed __int64 *)&v29, &v26, &v27, v13);
if ( object < 0 )
{
if ( (ERR_peek_error() & 0xFFF) != 0x9B )
goto LABEL_41;
ERR_clear_error();
}
v11 += (int)v28 - (int)v16;
if ( (object & 1) == 0 )
break;
if ( v12 == -1 )
{
ERR_put_error(13, 107, 123, (__int64)"crypto/asn1/a_d2i_fp.c", 157);
goto LABEL_41;
}
v13 = v10 - v11;
++v12;
if ( v10 - v11 <= 8 )
goto LABEL_7;
}
if ( !v12 || v29 )
break;
if ( !v26 && !--v12 )
{
v18 = v11;
goto LABEL_45;
}
}
v18 = v29 + v11;
if ( v29 > v10 - v11 )
{
v19 = v18 - v10;
if ( v18 - v10 > 0x7FFFFFFF || v18 < v10 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 178);
goto LABEL_41;
}
v20 = 0x4000;
if ( v19 )
{
while ( 1 )
{
v21 = v20;
if ( v20 > v19 )
v21 = v19;
v22 = v21;
if ( !BUF_MEM_grow_clean(v7, v21 + v10) )
break;
v23 = v22;
do
{
v24 = BIO_read(a3, v7[1] + v10, v23);
if ( v24 <= 0 )
{
ERR_put_error(13, 107, 142, (__int64)"crypto/asn1/a_d2i_fp.c", 199);
goto LABEL_41;
}
v23 -= v24;
v10 += v24;
}
while ( v23 );
v25 = 2 * v20;
if ( v20 > 0x3FFFFFFE )
v25 = v20;
v20 = v25;
v19 -= v22;
if ( !v19 )
{
v18 = v11 + v29;
goto LABEL_35;
}
}
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 191);
goto LABEL_41;
}
}
LABEL_35:
if ( v11 > v18 )
{
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 214);
goto LABEL_41;
}
if ( v12 )
{
v11 = v18;
goto LABEL_6;
}
LABEL_45:
if ( v18 <= 0x7FFFFFFF )
{
v29 = v7[1];
v8 = a2(a4, &v29);
goto LABEL_4;
}
ERR_put_error(13, 107, 155, (__int64)"crypto/asn1/a_d2i_fp.c", 226);
LABEL_41:
BUF_MEM_free((__int64)v7);
}
else
{
ERR_put_error(13, 107, 65, (__int64)"crypto/asn1/a_d2i_fp.c", 111);
}
v7 = nullptr;
v8 = 0;
LABEL_4:
BUF_MEM_free((__int64)v7);
return v8;
}