//
// SMIME_crlf_copy from 0xe71848 to 0xe71a78 (560 bytes)
//
// 4 xrefs:
// > i2d_ASN1_bio_stream @ 0xe71abc
// > SMIME_write_ASN1 @ 0xe71ee0
// > SMIME_write_ASN1 @ 0xe721ec
// > ??> @ 0xbbd70
//
// 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
//
__int64 __fastcall SMIME_crlf_copy(__int64 a1, __int64 a2, int a3)
{
void *v5; // x0
__int64 result; // x0
_QWORD *v7; // x28
__int64 v8; // x0
__int64 v9; // x23
int v10; // w27
int v11; // w24
signed int v12; // w19
unsigned __int8 *v13; // x3
int v14; // w20
int v15; // w4
signed int v16; // w2
unsigned int v17; // w4
int v18; // w21
__int64 v19; // [xsp+68h] [xbp+68h]
_BYTE v20[1024]; // [xsp+70h] [xbp+70h] BYREF
v19 = a2;
v5 = BIO_f_buffer();
result = BIO_new((__int64)v5);
v7 = (_QWORD *)result;
if ( result )
{
v8 = BIO_push(result, v19);
v9 = v8;
if ( (a3 & 0x80) == 0 )
{
if ( (a3 & 1) != 0 )
BIO_printf(v8, "Content-Type: text/plain\r\n\r\n");
v10 = a3 & 0x80000;
v11 = 0;
while ( 1 )
{
LABEL_6:
v12 = BIO_gets(a1, (__int64)v20, 0x400u);
if ( v12 <= 0 )
goto LABEL_15;
while ( 1 )
{
v13 = &v20[v12 - 1];
if ( v10 )
break;
v14 = 0;
do
{
while ( 1 )
{
v15 = *v13--;
if ( v15 != 10 )
break;
--v12;
v14 = 1;
if ( !v12 )
goto LABEL_13;
}
if ( v15 != 13 )
goto LABEL_27;
--v12;
}
while ( v12 );
LABEL_13:
if ( v14 )
goto LABEL_28;
v12 = BIO_gets(a1, (__int64)v20, 0x400u);
if ( v12 <= 0 )
goto LABEL_15;
}
v14 = 0;
while ( 1 )
{
while ( 1 )
{
v17 = *v13;
if ( v17 != 10 )
break;
--v12;
v14 = 1;
--v13;
if ( !v12 )
{
LABEL_31:
++v11;
goto LABEL_6;
}
}
if ( !v14 )
{
if ( v17 != 13 )
goto LABEL_24;
goto LABEL_30;
}
v14 = 1;
if ( v17 > 0x20 )
break;
LABEL_30:
--v12;
--v13;
if ( !v12 )
goto LABEL_31;
}
v14 = 1;
LABEL_24:
v18 = 0;
if ( v11 )
{
do
{
++v18;
BIO_write(v9, (__int64)&word_F203D8, 2u);
}
while ( v18 != v11 );
}
v11 = 0;
LABEL_27:
BIO_write(v9, (__int64)v20, v12);
if ( v14 )
LABEL_28:
BIO_write(v9, (__int64)&word_F203D8, 2u);
}
}
while ( 1 )
{
v16 = BIO_read(a1, (__int64)v20, 0x400u);
if ( v16 <= 0 )
break;
BIO_write(v9, (__int64)v20, v16);
}
LABEL_15:
BIO_ctrl(v9, 0xBu, 0, 0);
BIO_pop(v9);
BIO_free(v7);
return 1;
}
return result;
}