#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;

/* Variables and functions */
int /*<<< orphan*/ BIO_f_buffer();
int /*<<< orphan*/ BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free(int /*<<< orphan*/ *);
int BIO_gets(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ BIO_pop(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_printf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ *BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int BIO_read(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ BIO_write(int /*<<< orphan*/ *, char *, int);
int SMIME_BINARY;
int SMIME_TEXT;
char strip_eol(char *, int *);
int SMIME_crlf_copy(BIO *in, BIO *out, int flags) {
  BIO *bf;
  char eol;
  int len;
  char linebuf[1024];
  bf = BIO_new(BIO_f_buffer());
  if (!bf)
    return 0;
  out = BIO_push(bf, out);
  if (flags & SMIME_BINARY) {
    while ((len = BIO_read(in, linebuf, 1024)) > 0)
      BIO_write(out, linebuf, len);
  } else {
    if (flags & SMIME_TEXT)
      BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
    while ((len = BIO_gets(in, linebuf, 1024)) > 0) {
      eol = strip_eol(linebuf, &len);
      if (len)
        BIO_write(out, linebuf, len);
      if (eol)
        BIO_write(out, "\r\n", 2);
    }
  }
  (void)BIO_flush(out);
  BIO_pop(out);
  BIO_free(bf);
  return 1;
}


x86 assembly (clang, -O0):
<SMIME_crlf_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    $0x0,%al
call   1060 <BIO_f_buffer@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ef <SMIME_crlf_copy+0x3f>
movl   $0x0,-0x4(%rbp)
jmp    131e <SMIME_crlf_copy+0x16e>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <BIO_push@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dce(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1258 <SMIME_crlf_copy+0xa8>
jmp    121a <SMIME_crlf_copy+0x6a>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    1253 <SMIME_crlf_copy+0xa3>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   10c0 <BIO_write@plt>
jmp    121a <SMIME_crlf_copy+0x6a>
jmp    12fc <SMIME_crlf_copy+0x14c>
mov    -0x1c(%rbp),%eax
mov    0x2d86(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     127d <SMIME_crlf_copy+0xcd>
mov    -0x18(%rbp),%rdi
lea    0xd88(%rip),%rsi
call   1050 <BIO_printf@plt>
jmp    1282 <SMIME_crlf_copy+0xd2>
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   10b0 <BIO_gets@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jle    12f7 <SMIME_crlf_copy+0x147>
lea    -0x430(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1070 <strip_eol@plt>
mov    %al,-0x29(%rbp)
cmpl   $0x0,-0x30(%rbp)
je     12d3 <SMIME_crlf_copy+0x123>
mov    -0x18(%rbp),%rdi
lea    -0x430(%rbp),%rsi
mov    -0x30(%rbp),%edx
call   10c0 <BIO_write@plt>
cmpb   $0x0,-0x29(%rbp)
je     12f2 <SMIME_crlf_copy+0x142>
mov    -0x18(%rbp),%rdi
lea    0xd32(%rip),%rsi
mov    $0x2,%edx
call   10c0 <BIO_write@plt>
jmp    1282 <SMIME_crlf_copy+0xd2>
jmp    12fc <SMIME_crlf_copy+0x14c>
mov    -0x18(%rbp),%rdi
call   10d0 <BIO_flush@plt>
mov    -0x18(%rbp),%rdi
call   1080 <BIO_pop@plt>
mov    -0x28(%rbp),%rdi
call   10a0 <BIO_free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SMIME_crlf_copy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <BIO_f_buffer@plt>
mov    %eax,%edi
call   1090 <BIO_new@plt>
test   %rax,%rax
je     131f <SMIME_crlf_copy+0x16f>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <BIO_push@plt>
mov    %rax,%rbx
mov    0x2ddd(%rip),%rax
test   %r12d,(%rax)
mov    %rbp,0x8(%rsp)
je     125a <SMIME_crlf_copy+0xaa>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jle    1300 <SMIME_crlf_copy+0x150>
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   10c0 <BIO_write@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1040 <BIO_read@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jg     1230 <SMIME_crlf_copy+0x80>
jmp    1300 <SMIME_crlf_copy+0x150>
mov    0x2d87(%rip),%rax
test   %r12d,(%rax)
je     1275 <SMIME_crlf_copy+0xc5>
lea    0xd93(%rip),%rsi
mov    %rbx,%rdi
call   1050 <BIO_printf@plt>
lea    0x10(%rsp),%rsi
mov    %r15,%rdi
mov    $0x400,%edx
call   10b0 <BIO_gets@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jle    1300 <SMIME_crlf_copy+0x150>
lea    0x10(%rsp),%r12
lea    0x4(%rsp),%r13
lea    0xd7a(%rip),%rbp
jmp    12c8 <SMIME_crlf_copy+0x118>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x400,%edx
call   10b0 <BIO_gets@plt>
mov    %eax,0x4(%rsp)
test   %eax,%eax
jle    1300 <SMIME_crlf_copy+0x150>
mov    %r12,%rdi
mov    %r13,%rsi
call   1070 <strip_eol@plt>
mov    %eax,%r14d
mov    0x4(%rsp),%edx
test   %edx,%edx
je     12e9 <SMIME_crlf_copy+0x139>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10c0 <BIO_write@plt>
test   %r14b,%r14b
je     12b0 <SMIME_crlf_copy+0x100>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   10c0 <BIO_write@plt>
jmp    12b0 <SMIME_crlf_copy+0x100>
mov    %rbx,%rdi
call   10d0 <BIO_flush@plt>
mov    %rbx,%rdi
call   1080 <BIO_pop@plt>
mov    0x8(%rsp),%rdi
call   10a0 <BIO_free@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@SMIME_BINARY = global i32 0
@SMIME_TEXT = global i32 0
@.str = [29 x i8] c"Content-Type: text/plain\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define i32 @SMIME_crlf_copy(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i32
%11 = alloca [1024 x i8]
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
%12 = call i32 (...) @BIO_f_buffer()
%13 = call i32* @BIO_new(i32 %12)
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp ne i32* %14, null
br i1 %15, label %17, label %16
16: ; preds = %3
store i32 0, i32* %4
br label %76
17: ; preds = %3
%18 = load i32*, i32** %8
%19 = load i32*, i32** %6
%20 = call i32* @BIO_push(i32* %18, i32* %19)
store i32* %20, i32** %6
%21 = load i32, i32* %7
%22 = load i32, i32* @SMIME_BINARY
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %17
br label %26
26: ; preds = %31, %25
%27 = load i32*, i32** %5
%28 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%29 = call i32 @BIO_read(i32* %27, i8* %28, i32 1024)
store i32 %29, i32* %10
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %26
%32 = load i32*, i32** %6
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%34 = load i32, i32* %10
%35 = call i32 @BIO_write(i32* %32, i8* %33, i32 %34)
br label %26
36: ; preds = %26
br label %69
37: ; preds = %17
%38 = load i32, i32* %7
%39 = load i32, i32* @SMIME_TEXT
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %37
%43 = load i32*, i32** %6
%44 = call i32 @BIO_printf(i32* %43, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %45
45: ; preds = %42, %37
br label %46
46: ; preds = %67, %45
%47 = load i32*, i32** %5
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%49 = call i32 @BIO_gets(i32* %47, i8* %48, i32 1024)
store i32 %49, i32* %10
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %68
51: ; preds = %46
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%53 = call signext i8 @strip_eol(i8* %52, i32* %10)
store i8 %53, i8* %9
%54 = load i32, i32* %10
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i32*, i32** %6
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%59 = load i32, i32* %10
%60 = call i32 @BIO_write(i32* %57, i8* %58, i32 %59)
br label %61
61: ; preds = %56, %51
%62 = load i8, i8* %9
%63 = icmp ne i8 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32*, i32** %6
%66 = call i32 @BIO_write(i32* %65, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %67
67: ; preds = %64, %61
br label %46
68: ; preds = %46
br label %69
69: ; preds = %68, %36
%70 = load i32*, i32** %6
%71 = call i32 @BIO_flush(i32* %70)
%72 = load i32*, i32** %6
%73 = call i32 @BIO_pop(i32* %72)
%74 = load i32*, i32** %8
%75 = call i32 @BIO_free(i32* %74)
store i32 1, i32* %4
br label %76
76: ; preds = %69, %16
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@SMIME_BINARY = global i32 0
@SMIME_TEXT = global i32 0
@.str = [29 x i8] c"Content-Type: text/plain\0D\0A\0D\0A\00"
@.str.1 = [3 x i8] c"\0D\0A\00"
define i32 @SMIME_crlf_copy(i32* %0, i32* %1, i32 %2) {
%4 = alloca i32
%5 = alloca [1024 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%8 = tail call i32 (...) @BIO_f_buffer()
%9 = tail call i32* @BIO_new(i32 %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %50, label %11
11: ; preds = %3
%12 = tail call i32* @BIO_push(i32* %9, i32* %1)
%13 = load i32, i32* @SMIME_BINARY
%14 = and i32 %13, %2
%15 = icmp eq i32 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %11
%17 = call i32 @BIO_read(i32* %0, i8* %7, i32 1024)
store i32 %17, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %46
19: ; preds = %16, %19
%20 = phi i32 [ %22, %19 ], [ %17, %16 ]
%21 = call i32 @BIO_write(i32* %12, i8* %7, i32 %20)
%22 = call i32 @BIO_read(i32* %0, i8* %7, i32 1024)
store i32 %22, i32* %4
%23 = icmp sgt i32 %22, 0
br i1 %23, label %19, label %46
24: ; preds = %11
%25 = load i32, i32* @SMIME_TEXT
%26 = and i32 %25, %2
%27 = icmp eq i32 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 @BIO_printf(i32* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = call i32 @BIO_gets(i32* %0, i8* %7, i32 1024)
store i32 %31, i32* %4
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %46
33: ; preds = %30, %43
%34 = call signext i8 @strip_eol(i8* %7, i32* %4)
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %39, label %37
37: ; preds = %33
%38 = call i32 @BIO_write(i32* %12, i8* %7, i32 %35)
br label %39
39: ; preds = %37, %33
%40 = icmp eq i8 %34, 0
br i1 %40, label %43, label %41
41: ; preds = %39
%42 = call i32 @BIO_write(i32* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %43
43: ; preds = %41, %39
%44 = call i32 @BIO_gets(i32* %0, i8* %7, i32 1024)
store i32 %44, i32* %4
%45 = icmp sgt i32 %44, 0
br i1 %45, label %33, label %46
46: ; preds = %19, %43, %16, %30
%47 = call i32 @BIO_flush(i32* %12)
%48 = call i32 @BIO_pop(i32* %12)
%49 = call i32 @BIO_free(i32* %9)
br label %50
50: ; preds = %3, %46
%51 = phi i32 [ 1, %46 ], [ 0, %3 ]
ret i32 %51
}