#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*/ buf;
typedef int /*<<< orphan*/ BIO;

/* Variables and functions */
scalar_t__ BIO_TYPE_CIPHER;
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_get_cipher_status(int /*<<< orphan*/ *);
scalar_t__ BIO_method_type(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int BIO_read(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ BIO_s_mem();
int /*<<< orphan*/ BIO_s_null();
int /*<<< orphan*/ BIO_set_mem_eof_return(int /*<<< orphan*/ *,
                                          int /*<<< orphan*/);
int BIO_write(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ CMS_F_CMS_COPY_CONTENT;
int /*<<< orphan*/ CMS_R_SMIME_TEXT_ERROR;
unsigned int CMS_TEXT;
int /*<<< orphan*/ CMSerr(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ ERR_R_MALLOC_FAILURE;
int /*<<< orphan*/ SMIME_text(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int cms_copy_content(BIO *out, BIO *in, unsigned int flags) {
  unsigned char buf[4096];
  int r = 0, i;
  BIO *tmpout = NULL;
  if (out == NULL)
    tmpout = BIO_new(BIO_s_null());
  else if (flags & CMS_TEXT) {
    tmpout = BIO_new(BIO_s_mem());
    BIO_set_mem_eof_return(tmpout, 0);
  } else
    tmpout = out;
  if (!tmpout) {
    CMSerr(CMS_F_CMS_COPY_CONTENT, ERR_R_MALLOC_FAILURE);
    goto err;
  }
  for (;;) {
    i = BIO_read(in, buf, sizeof(buf));
    if (i <= 0) {
      if (BIO_method_type(in) == BIO_TYPE_CIPHER) {
        if (!BIO_get_cipher_status(in))
          goto err;
      }
      if (i < 0)
        goto err;
      break;
    }
    if (tmpout && (BIO_write(tmpout, buf, i) != i))
      goto err;
  }
  if (flags & CMS_TEXT) {
    if (!SMIME_text(tmpout, out)) {
      CMSerr(CMS_F_CMS_COPY_CONTENT, CMS_R_SMIME_TEXT_ERROR);
      goto err;
    }
  }
  r = 1;
err:
  if (tmpout && (tmpout != out))
    BIO_free(tmpout);
  return r;
}


x86 assembly (clang, -O0):
<cms_copy_content>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x1024(%rbp)
movq   $0x0,-0x1030(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1200 <cms_copy_content+0x50>
mov    $0x0,%al
call   1060 <BIO_s_null@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x1030(%rbp)
jmp    124d <cms_copy_content+0x9d>
mov    -0x14(%rbp),%eax
mov    0x2dd6(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     123d <cms_copy_content+0x8d>
mov    $0x0,%al
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x1030(%rbp)
mov    -0x1030(%rbp),%rdi
xor    %esi,%esi
call   10b0 <BIO_set_mem_eof_return@plt>
jmp    1248 <cms_copy_content+0x98>
mov    -0x8(%rbp),%rax
mov    %rax,-0x1030(%rbp)
jmp    124d <cms_copy_content+0x9d>
cmpq   $0x0,-0x1030(%rbp)
jne    1277 <cms_copy_content+0xc7>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
jmp    1386 <cms_copy_content+0x1d6>
jmp    127c <cms_copy_content+0xcc>
mov    -0x10(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <BIO_read@plt>
mov    %eax,-0x1028(%rbp)
cmpl   $0x0,-0x1028(%rbp)
jg     12f0 <cms_copy_content+0x140>
mov    -0x10(%rbp),%rdi
call   1070 <BIO_method_type@plt>
mov    0x2d34(%rip),%rcx
cmp    (%rcx),%rax
jne    12d9 <cms_copy_content+0x129>
mov    -0x10(%rbp),%rdi
call   1080 <BIO_get_cipher_status@plt>
cmp    $0x0,%eax
jne    12d4 <cms_copy_content+0x124>
jmp    1386 <cms_copy_content+0x1d6>
jmp    12d9 <cms_copy_content+0x129>
cmpl   $0x0,-0x1028(%rbp)
jge    12eb <cms_copy_content+0x13b>
jmp    1386 <cms_copy_content+0x1d6>
jmp    132d <cms_copy_content+0x17d>
cmpq   $0x0,-0x1030(%rbp)
je     1328 <cms_copy_content+0x178>
mov    -0x1030(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
mov    -0x1028(%rbp),%edx
call   10c0 <BIO_write@plt>
cmp    -0x1028(%rbp),%eax
je     1328 <cms_copy_content+0x178>
jmp    1386 <cms_copy_content+0x1d6>
jmp    127c <cms_copy_content+0xcc>
mov    -0x14(%rbp),%eax
mov    0x2ca9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     137c <cms_copy_content+0x1cc>
mov    -0x1030(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <SMIME_text@plt>
cmp    $0x0,%eax
jne    1377 <cms_copy_content+0x1c7>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
mov    0x2c65(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
jmp    1386 <cms_copy_content+0x1d6>
jmp    137c <cms_copy_content+0x1cc>
movl   $0x1,-0x1024(%rbp)
cmpq   $0x0,-0x1030(%rbp)
je     13b1 <cms_copy_content+0x201>
mov    -0x1030(%rbp),%rax
cmp    -0x8(%rbp),%rax
je     13b1 <cms_copy_content+0x201>
mov    -0x1030(%rbp),%rdi
call   10a0 <BIO_free@plt>
mov    -0x1024(%rbp),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cms_copy_content>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %edx,%r15d
mov    %rsi,%r13
mov    %rdi,%r14
test   %rdi,%rdi
je     1248 <cms_copy_content+0x98>
mov    0x2e0a(%rip),%rax
mov    %r14,%r12
test   %r15d,(%rax)
je     11fe <cms_copy_content+0x4e>
xor    %eax,%eax
call   10d0 <BIO_s_mem@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%r12
mov    %rax,%rdi
xor    %esi,%esi
call   10b0 <BIO_set_mem_eof_return@plt>
test   %r12,%r12
je     125e <cms_copy_content+0xae>
mov    %rsp,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %rbp,%rsi
mov    $0x1000,%edx
call   1050 <BIO_read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    128b <cms_copy_content+0xdb>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    %ebx,%edx
call   10c0 <BIO_write@plt>
cmp    %ebx,%eax
je     1210 <cms_copy_content+0x60>
xor    %ebp,%ebp
cmp    %r14,%r12
je     1277 <cms_copy_content+0xc7>
mov    %r12,%rdi
call   10a0 <BIO_free@plt>
jmp    1277 <cms_copy_content+0xc7>
xor    %eax,%eax
call   1060 <BIO_s_null@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,%r12
test   %r12,%r12
jne    11fe <cms_copy_content+0x4e>
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,%rdi
call   1070 <BIO_method_type@plt>
mov    0x2d4e(%rip),%rcx
cmp    (%rcx),%rax
jne    12b3 <cms_copy_content+0x103>
mov    %r13,%rdi
call   1080 <BIO_get_cipher_status@plt>
xor    %ebp,%ebp
test   %eax,%eax
je     1239 <cms_copy_content+0x89>
test   %ebx,%ebx
jns    12b7 <cms_copy_content+0x107>
jmp    1239 <cms_copy_content+0x89>
test   %ebx,%ebx
js     1237 <cms_copy_content+0x87>
mov    0x2d22(%rip),%rax
mov    $0x1,%ebp
test   %r15d,(%rax)
je     1239 <cms_copy_content+0x89>
mov    %r12,%rdi
mov    %r14,%rsi
call   1040 <SMIME_text@plt>
test   %eax,%eax
jne    1239 <cms_copy_content+0x89>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%esi
call   1030 <CMSerr@plt>
jmp    1237 <cms_copy_content+0x87>

LLVM IR (-O0):
@CMS_TEXT = global i32 0
@CMS_F_CMS_COPY_CONTENT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@BIO_TYPE_CIPHER = global i64 0
@CMS_R_SMIME_TEXT_ERROR = global i32 0
define i32 @cms_copy_content(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca [4096 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32* %0, i32** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32* null, i32** %10
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = call i32 (...) @BIO_s_null()
%15 = call i32* @BIO_new(i32 %14)
store i32* %15, i32** %10
br label %29
16: ; preds = %3
%17 = load i32, i32* %6
%18 = load i32, i32* @CMS_TEXT
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %16
%22 = call i32 (...) @BIO_s_mem()
%23 = call i32* @BIO_new(i32 %22)
store i32* %23, i32** %10
%24 = load i32*, i32** %10
%25 = call i32 @BIO_set_mem_eof_return(i32* %24, i32 0)
br label %28
26: ; preds = %16
%27 = load i32*, i32** %4
store i32* %27, i32** %10
br label %28
28: ; preds = %26, %21
br label %29
29: ; preds = %28, %13
%30 = load i32*, i32** %10
%31 = icmp ne i32* %30, null
br i1 %31, label %36, label %32
32: ; preds = %29
%33 = load i32, i32* @CMS_F_CMS_COPY_CONTENT
%34 = load i32, i32* @ERR_R_MALLOC_FAILURE
%35 = call i32 @CMSerr(i32 %33, i32 %34)
br label %87
36: ; preds = %29
br label %37
37: ; preds = %70, %36
%38 = load i32*, i32** %5
%39 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%40 = call i32 @BIO_read(i32* %38, i8* %39, i32 4096)
store i32 %40, i32* %9
%41 = load i32, i32* %9
%42 = icmp sle i32 %41, 0
br i1 %42, label %43, label %59
43: ; preds = %37
%44 = load i32*, i32** %5
%45 = call i64 @BIO_method_type(i32* %44)
%46 = load i64, i64* @BIO_TYPE_CIPHER
%47 = icmp eq i64 %45, %46
br i1 %47, label %48, label %54
48: ; preds = %43
%49 = load i32*, i32** %5
%50 = call i32 @BIO_get_cipher_status(i32* %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %53, label %52
52: ; preds = %48
br label %87
53: ; preds = %48
br label %54
54: ; preds = %53, %43
%55 = load i32, i32* %9
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %54
br label %87
58: ; preds = %54
br label %71
59: ; preds = %37
%60 = load i32*, i32** %10
%61 = icmp ne i32* %60, null
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = load i32*, i32** %10
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%65 = load i32, i32* %9
%66 = call i32 @BIO_write(i32* %63, i8* %64, i32 %65)
%67 = load i32, i32* %9
%68 = icmp ne i32 %66, %67
br i1 %68, label %69, label %70
69: ; preds = %62
br label %87
70: ; preds = %62, %59
br label %37
71: ; preds = %58
%72 = load i32, i32* %6
%73 = load i32, i32* @CMS_TEXT
%74 = and i32 %72, %73
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %86
76: ; preds = %71
%77 = load i32*, i32** %10
%78 = load i32*, i32** %4
%79 = call i32 @SMIME_text(i32* %77, i32* %78)
%80 = icmp ne i32 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %76
%82 = load i32, i32* @CMS_F_CMS_COPY_CONTENT
%83 = load i32, i32* @CMS_R_SMIME_TEXT_ERROR
%84 = call i32 @CMSerr(i32 %82, i32 %83)
br label %87
85: ; preds = %76
br label %86
86: ; preds = %85, %71
store i32 1, i32* %8
br label %87
87: ; preds = %86, %81, %69, %57, %52, %32
%88 = load i32*, i32** %10
%89 = icmp ne i32* %88, null
br i1 %89, label %90, label %97
90: ; preds = %87
%91 = load i32*, i32** %10
%92 = load i32*, i32** %4
%93 = icmp ne i32* %91, %92
br i1 %93, label %94, label %97
94: ; preds = %90
%95 = load i32*, i32** %10
%96 = call i32 @BIO_free(i32* %95)
br label %97
97: ; preds = %94, %90, %87
%98 = load i32, i32* %8
ret i32 %98
}

LLVM IR (-O2):
@CMS_TEXT = global i32 0
@CMS_F_CMS_COPY_CONTENT = global i32 0
@ERR_R_MALLOC_FAILURE = global i32 0
@BIO_TYPE_CIPHER = global i64 0
@CMS_R_SMIME_TEXT_ERROR = global i32 0
define i32 @cms_copy_content(i32* %0, i32* %1, i32 %2) {
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%6 = icmp eq i32* %0, null
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = tail call i32 (...) @BIO_s_null()
%9 = tail call i32* @BIO_new(i32 %8)
br label %18
10: ; preds = %3
%11 = load i32, i32* @CMS_TEXT
%12 = and i32 %11, %2
%13 = icmp eq i32 %12, 0
br i1 %13, label %21, label %14
14: ; preds = %10
%15 = tail call i32 (...) @BIO_s_mem()
%16 = tail call i32* @BIO_new(i32 %15)
%17 = tail call i32 @BIO_set_mem_eof_return(i32* %16, i32 0)
br label %18
18: ; preds = %14, %7
%19 = phi i32* [ %9, %7 ], [ %16, %14 ]
%20 = icmp eq i32* %19, null
br i1 %20, label %23, label %21
21: ; preds = %10, %18
%22 = phi i32* [ %19, %18 ], [ %0, %10 ]
br label %27
23: ; preds = %18
%24 = load i32, i32* @CMS_F_CMS_COPY_CONTENT
%25 = load i32, i32* @ERR_R_MALLOC_FAILURE
%26 = tail call i32 @CMSerr(i32 %24, i32 %25)
br label %60
27: ; preds = %21, %41
%28 = call i32 @BIO_read(i32* %1, i8* %5, i32 4096)
%29 = icmp slt i32 %28, 1
br i1 %29, label %30, label %41
30: ; preds = %27
%31 = call i64 @BIO_method_type(i32* %1)
%32 = load i64, i64* @BIO_TYPE_CIPHER
%33 = icmp eq i64 %31, %32
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = call i32 @BIO_get_cipher_status(i32* %1)
%36 = icmp eq i32 %35, 0
%37 = icmp slt i32 %28, 0
%38 = select i1 %36, i1 true, i1 %37
br i1 %38, label %55, label %44
39: ; preds = %30
%40 = icmp slt i32 %28, 0
br i1 %40, label %55, label %44
41: ; preds = %27
%42 = call i32 @BIO_write(i32* %22, i8* %5, i32 %28)
%43 = icmp eq i32 %42, %28
br i1 %43, label %27, label %55
44: ; preds = %34, %39
%45 = load i32, i32* @CMS_TEXT
%46 = and i32 %45, %2
%47 = icmp eq i32 %46, 0
br i1 %47, label %55, label %48
48: ; preds = %44
%49 = call i32 @SMIME_text(i32* %22, i32* %0)
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* @CMS_F_CMS_COPY_CONTENT
%53 = load i32, i32* @CMS_R_SMIME_TEXT_ERROR
%54 = call i32 @CMSerr(i32 %52, i32 %53)
br label %55
55: ; preds = %41, %44, %48, %39, %34, %51
%56 = phi i32 [ 0, %34 ], [ 0, %51 ], [ 0, %39 ], [ 1, %48 ], [ 1, %44 ], [ 0, %41 ]
%57 = icmp eq i32* %22, %0
br i1 %57, label %60, label %58
58: ; preds = %55
%59 = call i32 @BIO_free(i32* %22)
br label %60
60: ; preds = %23, %58, %55
%61 = phi i32 [ 0, %23 ], [ %56, %58 ], [ %56, %55 ]
ret i32 %61
}