//
// X509V3_add1_i2d from 0x857820 to 0x85799c (380 bytes)
//
// 10 xrefs:
// > OCSP_REQUEST_add1_ext_i2d @ 0x81e148
// > OCSP_ONEREQ_add1_ext_i2d @ 0x81e1a0
// > OCSP_BASICRESP_add1_ext_i2d @ 0x81e1f8
// > OCSP_SINGLERESP_add1_ext_i2d @ 0x81e250
// > OCSP_request_add1_nonce @ 0x81e314
// > OCSP_basic_add1_nonce @ 0x81e424
// > X509_CRL_add1_ext_i2d @ 0x83f280
// > X509_add1_ext_i2d @ 0x83f2f0
// > X509_REVOKED_add1_ext_i2d @ 0x83f348
// > ??> @ 0x649cc
//
// 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 X509V3_add1_i2d(int **a1, unsigned int a2, size_t *a3, int a4, char a5)
{
int v6; // r5
int ext_by_NID; // r10
const char ***v11; // r4
_DWORD *v12; // r0
__int16 v14; // r2
const char ***v15; // r1
int *v16; // r0
const char ***v17; // [sp+Ch] [bp-4h]
v6 = a5 & 0xF;
if ( v6 == 1 )
goto LABEL_15;
ext_by_NID = X509v3_get_ext_by_NID(*a1, a2, -1);
if ( ext_by_NID < 0 )
{
if ( ((v6 - 3) & 0xFFFFFFFD) == 0 )
{
v14 = 102;
goto LABEL_10;
}
LABEL_15:
v15 = X509V3_EXT_i2d(a2, a4, a3);
if ( !v15 )
{
LABEL_23:
ERR_put_error(34, 140, 144, (int)"crypto/x509v3/v3_lib.c", 335);
return 0;
}
v16 = *a1;
if ( *a1 || (v17 = v15, v16 = OPENSSL_sk_new_null(), v15 = v17, (*a1 = v16) != nullptr) )
{
if ( OPENSSL_sk_push(v16, (int)v15) )
return 1;
}
return -1;
}
if ( v6 == 4 )
return 1;
if ( (a5 & 0xF) != 0 )
{
if ( v6 != 5 )
{
v11 = X509V3_EXT_i2d(a2, a4, a3);
if ( v11 )
{
v12 = (_DWORD *)OPENSSL_sk_value(*a1, ext_by_NID);
X509_EXTENSION_free(v12);
if ( OPENSSL_sk_set(*a1, ext_by_NID, (int)v11) )
return 1;
return -1;
}
goto LABEL_23;
}
if ( OPENSSL_sk_delete(*a1, ext_by_NID) )
return 1;
return -1;
}
v14 = 145;
LABEL_10:
if ( (a5 & 0x10) == 0 )
ERR_put_error(34, 140, v14, (int)"crypto/x509v3/v3_lib.c", 358);
return 0;
}