#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_item_i2d_bio(int /*<<< orphan*/ const *,
                                     int /*<<< orphan*/ *,
                                     int /*<<< orphan*/ *);
int /*<<< orphan*/ ASN1error(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) {
      ASN1error(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    0x2e53(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1224 <i2d_ASN1_bio_stream+0xb4>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1040 <BIO_new_NDEF@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11da <i2d_ASN1_bio_stream+0x6a>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
movl   $0x0,-0x4(%rbp)
jmp    123c <i2d_ASN1_bio_stream+0xcc>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   1070 <SMIME_crlf_copy@plt>
mov    -0x38(%rbp),%rdi
call   1090 <BIO_flush@plt>
mov    -0x38(%rbp),%rdi
call   1030 <BIO_pop@plt>
mov    %rax,-0x40(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <BIO_free@plt>
mov    -0x40(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    11f3 <i2d_ASN1_bio_stream+0x83>
jmp    1235 <i2d_ASN1_bio_stream+0xc5>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <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    0x2e61(%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   1040 <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   1070 <SMIME_crlf_copy@plt>
mov    %rbx,%rdi
call   1090 <BIO_flush@plt>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <BIO_pop@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1050 <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   1060 <ASN1_item_i2d_bio@plt>
mov    $0x1,%eax
jmp    11ff <i2d_ASN1_bio_stream+0x8f>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1080 <ASN1error@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SMIME_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 %46
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 %28, label %25
25: ; preds = %18
%26 = load i32, i32* @ERR_R_MALLOC_FAILURE
%27 = call i32 @ASN1error(i32 %26)
store i32 0, i32* %6
br label %52
28: ; preds = %18
%29 = load i32*, i32** %9
%30 = load i32*, i32** %12
%31 = load i32, i32* %10
%32 = call i32 @SMIME_crlf_copy(i32* %29, i32* %30, i32 %31)
%33 = load i32*, i32** %12
%34 = call i32 @BIO_flush(i32* %33)
br label %35
35: ; preds = %41, %28
%36 = load i32*, i32** %12
%37 = call i32* @BIO_pop(i32* %36)
store i32* %37, i32** %13
%38 = load i32*, i32** %12
%39 = call i32 @BIO_free(i32* %38)
%40 = load i32*, i32** %13
store i32* %40, i32** %12
br label %41
41: ; preds = %35
%42 = load i32*, i32** %12
%43 = load i32*, i32** %7
%44 = icmp ne i32* %42, %43
br i1 %44, label %35, label %45
45: ; preds = %41
br label %51
46: ; preds = %5
%47 = load i32*, i32** %11
%48 = load i32*, i32** %7
%49 = load i32*, i32** %8
%50 = call i32 @ASN1_item_i2d_bio(i32* %47, i32* %48, i32* %49)
br label %51
51: ; preds = %46, %45
store i32 1, i32* %6
br label %52
52: ; preds = %51, %25
%53 = load i32, i32* %6
ret i32 %53
}

LLVM IR (-O2):
@SMIME_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 %23, 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 %15
12: ; preds = %9
%13 = load i32, i32* @ERR_R_MALLOC_FAILURE
%14 = tail call i32 @ASN1error(i32 %13)
br label %25
15: ; preds = %9
%16 = tail call i32 @SMIME_crlf_copy(i32* %2, i32* %10, i32 %3)
%17 = tail call i32 @BIO_flush(i32* %10)
br label %18
18: ; preds = %18, %15
%19 = phi i32* [ %10, %15 ], [ %20, %18 ]
%20 = tail call i32* @BIO_pop(i32* %19)
%21 = tail call i32 @BIO_free(i32* %19)
%22 = icmp eq i32* %20, %0
br i1 %22, label %25, label %18
23: ; preds = %5
%24 = tail call i32 @ASN1_item_i2d_bio(i32* %4, i32* %0, i32* %1)
br label %25
25: ; preds = %18, %23, %12
%26 = phi i32 [ 0, %12 ], [ 1, %23 ], [ 1, %18 ]
ret i32 %26
}