#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ BIO;
typedef int /*<<< orphan*/ ASN1_VALUE;
typedef int /*<<< orphan*/ ASN1_ITEM;

/* Variables and functions */
int /*<<< orphan*/ ASN1_F_I2D_ASN1_BIO_STREAM;
int /*<<< orphan*/ ASN1_item_i2d_bio(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1err(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new_NDEF(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int /*<<< orphan*/ const *);
int /*<<< orphan*/ *BIO_pop(int /*<<< orphan*/ *);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int SMIME_STREAM;
int /*<<< orphan*/ SMIME_crlf_copy(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                   int);
int i2d_ASN1_bio_stream(BIO *out, ASN1_VALUE *val, BIO *in, int flags,
                        const ASN1_ITEM *it) {
  if (flags & SMIME_STREAM) {
    BIO *bio, *tbio;
    bio = BIO_new_NDEF(out, val, it);
    if (!bio) {
      ASN1err(ASN1_F_I2D_ASN1_BIO_STREAM, ERR_R_MALLOC_FAILURE);
      return 0;
    }
    SMIME_crlf_copy(in, bio, flags);
    (void)BIO_flush(bio);
    do {
      tbio = BIO_pop(bio);
      BIO_free(bio);
      bio = tbio;
    } while (bio != out);
  } else
    ASN1_item_i2d_bio(it, out, val);
  return 1;
}


x86 assembly (clang, -O0):
<i2d_ASN1_bio_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e4b(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     122d <i2d_ASN1_bio_stream+0xbd>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1050 <BIO_new_NDEF@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11e3 <i2d_ASN1_bio_stream+0x73>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
movl   $0x0,-0x4(%rbp)
jmp    1245 <i2d_ASN1_bio_stream+0xd5>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1080 <SMIME_crlf_copy@plt>
mov    -0x38(%rbp),%rdi
call   1090 <BIO_flush@plt>
mov    -0x38(%rbp),%rdi
call   1040 <BIO_pop@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <BIO_free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11fc <i2d_ASN1_bio_stream+0x8c>
jmp    123e <i2d_ASN1_bio_stream+0xce>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1070 <ASN1_item_i2d_bio@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<i2d_ASN1_bio_stream>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%rdx
mov    %rdi,%r14
mov    0x2e59(%rip),%rax
test   %ecx,(%rax)
je     11dd <i2d_ASN1_bio_stream+0x6d>
mov    %ecx,%ebp
mov    %r14,%rdi
mov    %rdx,%rsi
mov    %r8,%rdx
call   1050 <BIO_new_NDEF@plt>
test   %rax,%rax
je     11ef <i2d_ASN1_bio_stream+0x7f>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
mov    %ebp,%edx
call   1080 <SMIME_crlf_copy@plt>
mov    %rbx,%rdi
call   1090 <BIO_flush@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <BIO_pop@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1060 <BIO_free@plt>
mov    %rbp,%rbx
cmp    %r14,%rbp
jne    11c0 <i2d_ASN1_bio_stream+0x50>
jmp    11e8 <i2d_ASN1_bio_stream+0x78>
mov    %r8,%rdi
mov    %r14,%rsi
call   1070 <ASN1_item_i2d_bio@plt>
mov    $0x1,%eax
jmp    1208 <i2d_ASN1_bio_stream+0x98>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1030 <ASN1err@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SMIME_STREAM = global i32 0
@ASN1_F_I2D_ASN1_BIO_STREAM = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_ASN1_bio_stream(i32* %0, i32* %1, i32* %2, i32 %3, i32* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i32*
%12 = alloca i32*
%13 = alloca i32*
store i32* %0, i32** %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32 %3, i32* %10
store i32* %4, i32** %11
%14 = load i32, i32* %10
%15 = load i32, i32* @SMIME_STREAM
%16 = and i32 %14, %15
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %47
18: ; preds = %5
%19 = load i32*, i32** %7
%20 = load i32*, i32** %8
%21 = load i32*, i32** %11
%22 = call i32* @BIO_new_NDEF(i32* %19, i32* %20, i32* %21)
store i32* %22, i32** %12
%23 = load i32*, i32** %12
%24 = icmp ne i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* @ASN1_F_I2D_ASN1_BIO_STREAM
%27 = load i32, i32* @ERR_R_MALLOC_FAILURE
%28 = call i32 @ASN1err(i32 %26, i32 %27)
store i32 0, i32* %6
br label %53
29: ; preds = %18
%30 = load i32*, i32** %9
%31 = load i32*, i32** %12
%32 = load i32, i32* %10
%33 = call i32 @SMIME_crlf_copy(i32* %30, i32* %31, i32 %32)
%34 = load i32*, i32** %12
%35 = call i32 @BIO_flush(i32* %34)
br label %36
36: ; preds = %42, %29
%37 = load i32*, i32** %12
%38 = call i32* @BIO_pop(i32* %37)
store i32* %38, i32** %13
%39 = load i32*, i32** %12
%40 = call i32 @BIO_free(i32* %39)
%41 = load i32*, i32** %13
store i32* %41, i32** %12
br label %42
42: ; preds = %36
%43 = load i32*, i32** %12
%44 = load i32*, i32** %7
%45 = icmp ne i32* %43, %44
br i1 %45, label %36, label %46
46: ; preds = %42
br label %52
47: ; preds = %5
%48 = load i32*, i32** %11
%49 = load i32*, i32** %7
%50 = load i32*, i32** %8
%51 = call i32 @ASN1_item_i2d_bio(i32* %48, i32* %49, i32* %50)
br label %52
52: ; preds = %47, %46
store i32 1, i32* %6
br label %53
53: ; preds = %52, %25
%54 = load i32, i32* %6
ret i32 %54
}

LLVM IR (-O2):
@SMIME_STREAM = global i32 0
@ASN1_F_I2D_ASN1_BIO_STREAM = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
define i32 @i2d_ASN1_bio_stream(i32* %0, i32* %1, i32* %2, i32 %3, i32* %4) {
%6 = load i32, i32* @SMIME_STREAM
%7 = and i32 %6, %3
%8 = icmp eq i32 %7, 0
br i1 %8, label %24, label %9
9: ; preds = %5
%10 = tail call i32* @BIO_new_NDEF(i32* %0, i32* %1, i32* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = load i32, i32* @ASN1_F_I2D_ASN1_BIO_STREAM
%14 = load i32, i32* @ERR_R_MALLOC_FAILURE
%15 = tail call i32 @ASN1err(i32 %13, i32 %14)
br label %26
16: ; preds = %9
%17 = tail call i32 @SMIME_crlf_copy(i32* %2, i32* %10, i32 %3)
%18 = tail call i32 @BIO_flush(i32* %10)
br label %19
19: ; preds = %19, %16
%20 = phi i32* [ %10, %16 ], [ %21, %19 ]
%21 = tail call i32* @BIO_pop(i32* %20)
%22 = tail call i32 @BIO_free(i32* %20)
%23 = icmp eq i32* %21, %0
br i1 %23, label %26, label %19
24: ; preds = %5
%25 = tail call i32 @ASN1_item_i2d_bio(i32* %4, i32* %0, i32* %1)
br label %26
26: ; preds = %19, %24, %12
%27 = phi i32 [ 0, %12 ], [ 1, %24 ], [ 1, %19 ]
ret i32 %27
}