//
// sub_8C4CA8 from 0x8c4ca8 to 0x8c4ee4 (572 bytes)
//
// 1 xrefs:
// > SMIME_read_ASN1 @ 0x8c5940
//
// 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_8C4CA8(_DWORD *a1, char *a2, int **a3)
{
size_t v6; // r6
int v7; // r5
int v8; // r10
int v9; // r4
size_t v10; // r11
int v12; // r11
char *v13; // r2
int v14; // r3
int v15; // t1
void *v16; // r0
_DWORD *v17; // r0
_DWORD *v18; // [sp+8h] [bp-414h]
int v19; // [sp+Ch] [bp-410h]
int *v20; // [sp+10h] [bp-40Ch]
__int16 *v21; // [sp+14h] [bp-408h]
char v22[2]; // [sp+18h] [bp-404h] BYREF
char v23[1026]; // [sp+1Ah] [bp-402h] BYREF
v6 = strlen(a2);
v20 = OPENSSL_sk_new_null();
*a3 = v20;
if ( !v20 )
return 0;
v7 = 0;
v21 = &word_9B1DDC;
v8 = 1;
v18 = nullptr;
v19 = 0;
while ( 1 )
{
while ( 1 )
{
v9 = BIO_gets(a1, (int)v22, 1024);
if ( v9 <= 0 )
{
BIO_free(v18);
return 0;
}
v10 = v6 == -1 ? strlen(a2) : v6;
if ( v9 > (int)(v10 + 1) && !strncmp(v22, "--", 2u) && !strncmp(v23, a2, v10) )
break;
if ( v7 )
{
v12 = 0;
v13 = &v22[v9];
do
{
while ( 1 )
{
v15 = (unsigned __int8)*--v13;
v14 = v15;
if ( v15 != 10 )
break;
--v9;
v12 = 1;
if ( !v9 )
goto LABEL_20;
}
if ( v14 != 13 )
break;
--v9;
}
while ( v9 );
LABEL_20:
if ( v8 )
{
if ( v18 && !OPENSSL_sk_push(v20, (int)v18) )
goto LABEL_32;
v16 = BIO_s_mem();
v17 = BIO_new((int)v16);
v18 = v17;
if ( !v17 )
return 0;
BIO_ctrl(v17, 130, 0, 0);
}
else if ( v19 )
{
BIO_write((int)v18, (int)v21, 2);
}
v19 = v12;
v8 = 0;
if ( v9 )
BIO_write((int)v18, (int)v22, v9);
}
}
if ( !strncmp(&v22[v10 + 2], "--", 2u) )
break;
v7 = (unsigned __int8)(v7 + 1);
v8 = 1;
}
if ( OPENSSL_sk_push(v20, (int)v18) )
return 1;
LABEL_32:
BIO_free(v18);
return 0;
}