#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_NOCLOSE;
int /*<<< orphan*/ BIO_f_base64();
int /*<<< orphan*/ BIO_f_cipher();
int BIO_flush(int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_free_all(int /*<<< orphan*/ *);
int /*<<< orphan*/ *BIO_new(int /*<<< orphan*/);
int /*<<< orphan*/ *BIO_new_fp(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ BIO_push(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ BIO_set_cipher(int /*<<< orphan*/ *, int /*<<< orphan*/,
                                  unsigned char *, unsigned char *, int);
int /*<<< orphan*/ BIO_should_retry(int /*<<< orphan*/ *);
scalar_t__ BIO_write(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ ERR_free_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ ERR_print_errors_fp(int /*<<< orphan*/);
int /*<<< orphan*/ EVP_aes_128_cbc();
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int strlen(char *);
int main(int argc, char **argv) {
  char plaintext[80];
  int plaintext_len;
  unsigned char key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                         0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  unsigned char iv[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
                        0x08, 0x09, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
  BIO *bio_encrypt, *bio_base64, *bio_stdout;
  ERR_load_crypto_strings();
  if (fgets(plaintext, 64, stdin) == NULL) {
    fprintf(stderr, "fgets() failed!\n");
    exit(EXIT_FAILURE);
  }
  plaintext_len = strlen(plaintext);
  fprintf(stdout, "Ciphertext: ");
  bio_encrypt = BIO_new(BIO_f_cipher());
  BIO_set_cipher(bio_encrypt, EVP_aes_128_cbc(), key, iv, 1);
  bio_base64 = BIO_new(BIO_f_base64());
  bio_stdout = BIO_new_fp(stdout, BIO_NOCLOSE);
  BIO_push(bio_encrypt, bio_base64);
  BIO_push(bio_base64, bio_stdout);
  if (BIO_write(bio_encrypt, plaintext, plaintext_len) <= 0) {
    if (!BIO_should_retry(bio_encrypt)) {
      ERR_print_errors_fp(stderr);
      exit(EXIT_FAILURE);
    }
  }
  if (BIO_flush(bio_encrypt) != 1) {
    ERR_print_errors_fp(stderr);
    exit(EXIT_FAILURE);
  }
  BIO_free_all(bio_encrypt);
  ERR_free_strings();
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xdc0(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    0xdbd(%rip),%rax
mov    %rax,-0x78(%rbp)
mov    0xdaa(%rip),%rax
mov    %rax,-0x90(%rbp)
mov    0xda4(%rip),%rax
mov    %rax,-0x88(%rbp)
mov    $0x0,%al
call   10f0 <ERR_load_crypto_strings@plt>
lea    -0x60(%rbp),%rdi
mov    0x2d63(%rip),%rax
mov    (%rax),%edx
mov    $0x40,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
jne    12b6 <main+0x96>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    0xd6d(%rip),%rsi
call   1080 <fprintf@plt>
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    -0x60(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xd4f(%rip),%rsi
call   1080 <fprintf@plt>
mov    $0x0,%al
call   10d0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0x98(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0xb0(%rbp)
mov    $0x0,%al
call   10c0 <EVP_aes_128_cbc@plt>
mov    -0xb0(%rbp),%rdi
mov    %eax,%esi
lea    -0x80(%rbp),%rdx
lea    -0x90(%rbp),%rcx
mov    $0x1,%r8d
call   10a0 <BIO_set_cipher@plt>
mov    $0x0,%al
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,-0xa0(%rbp)
mov    0x2c84(%rip),%rax
mov    (%rax),%edi
mov    0x2ca3(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    -0xa0(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
call   1040 <BIO_push@plt>
mov    -0x98(%rbp),%rdi
lea    -0x60(%rbp),%rsi
mov    -0x64(%rbp),%edx
call   1120 <BIO_write@plt>
cmp    $0x0,%rax
jg     13cc <main+0x1ac>
mov    -0x98(%rbp),%rdi
call   1110 <BIO_should_retry@plt>
cmp    $0x0,%eax
jne    13c7 <main+0x1a7>
mov    0x2c1e(%rip),%rax
mov    (%rax),%edi
call   1130 <ERR_print_errors_fp@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
jmp    13cc <main+0x1ac>
mov    -0x98(%rbp),%rdi
call   1140 <BIO_flush@plt>
cmp    $0x1,%eax
je     13fd <main+0x1dd>
mov    0x2be8(%rip),%rax
mov    (%rax),%edi
call   1130 <ERR_print_errors_fp@plt>
mov    0x2bd2(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    -0x98(%rbp),%rdi
call   10e0 <BIO_free_all@plt>
mov    $0x0,%al
call   1090 <ERR_free_strings@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x70,%rsp
movaps 0xdcd(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
xor    %eax,%eax
call   10f0 <ERR_load_crypto_strings@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
lea    0x20(%rsp),%rdi
mov    $0x40,%esi
call   1070 <fgets@plt>
test   %rax,%rax
jne    127a <main+0x5a>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xda0(%rip),%rsi
call   1080 <fprintf@plt>
jmp    1360 <main+0x140>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    0x2d2f(%rip),%rbx
mov    (%rbx),%edi
lea    0xd87(%rip),%rsi
call   1080 <fprintf@plt>
xor    %eax,%eax
call   10d0 <BIO_f_cipher@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%r12
xor    %eax,%eax
call   10c0 <EVP_aes_128_cbc@plt>
lea    0x10(%rsp),%rdx
mov    %rsp,%rcx
mov    %r12,%rdi
mov    %eax,%esi
mov    $0x1,%r8d
call   10a0 <BIO_set_cipher@plt>
xor    %eax,%eax
call   1060 <BIO_f_base64@plt>
mov    %eax,%edi
call   10b0 <BIO_new@plt>
mov    %rax,%rbp
mov    (%rbx),%edi
mov    0x2cff(%rip),%rax
mov    (%rax),%esi
call   1030 <BIO_new_fp@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rbp,%rsi
call   1040 <BIO_push@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <BIO_push@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1120 <BIO_write@plt>
test   %rax,%rax
jg     1328 <main+0x108>
mov    %r12,%rdi
call   1110 <BIO_should_retry@plt>
test   %eax,%eax
je     1352 <main+0x132>
mov    %r12,%rdi
call   1140 <BIO_flush@plt>
cmp    $0x1,%eax
jne    1352 <main+0x132>
mov    %r12,%rdi
call   10e0 <BIO_free_all@plt>
xor    %eax,%eax
call   1090 <ERR_free_strings@plt>
mov    0x2c6d(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   1130 <ERR_print_errors_fp@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@__const.main.key = [16 x i8] c"\00\01\02\03\04\05\06\07\08\09\00\01\02\03\04\05"
@__const.main.iv = [16 x i8] c"\00\01\02\03\04\05\06\07\08\09\00\01\02\03\04\05"
@stdin = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"fgets() failed!\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [13 x i8] c"Ciphertext: \00"
@BIO_NOCLOSE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [80 x i8]
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca [16 x i8]
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast [16 x i8]* %8 to i8*
%14 = bitcast [16 x i8]* %9 to i8*
%15 = call i32 (...) @ERR_load_crypto_strings()
%16 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%17 = load i32, i32* @stdin
%18 = call i32* @fgets(i8* %16, i32 64, i32 %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %25
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%27 = call i32 @strlen(i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* @stdout
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%30 = call i32 (...) @BIO_f_cipher()
%31 = call i32* @BIO_new(i32 %30)
store i32* %31, i32** %10
%32 = load i32*, i32** %10
%33 = call i32 (...) @EVP_aes_128_cbc()
%34 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%35 = getelementptr inbounds [16 x i8], [16 x i8]* %9, i64 0, i64 0
%36 = call i32 @BIO_set_cipher(i32* %32, i32 %33, i8* %34, i8* %35, i32 1)
%37 = call i32 (...) @BIO_f_base64()
%38 = call i32* @BIO_new(i32 %37)
store i32* %38, i32** %11
%39 = load i32, i32* @stdout
%40 = load i32, i32* @BIO_NOCLOSE
%41 = call i32* @BIO_new_fp(i32 %39, i32 %40)
store i32* %41, i32** %12
%42 = load i32*, i32** %10
%43 = load i32*, i32** %11
%44 = call i32 @BIO_push(i32* %42, i32* %43)
%45 = load i32*, i32** %11
%46 = load i32*, i32** %12
%47 = call i32 @BIO_push(i32* %45, i32* %46)
%48 = load i32*, i32** %10
%49 = getelementptr inbounds [80 x i8], [80 x i8]* %6, i64 0, i64 0
%50 = load i32, i32* %7
%51 = call i64 @BIO_write(i32* %48, i8* %49, i32 %50)
%52 = icmp sle i64 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %25
%54 = load i32*, i32** %10
%55 = call i32 @BIO_should_retry(i32* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = call i32 @ERR_print_errors_fp(i32 %58)
%60 = load i32, i32* @EXIT_FAILURE
%61 = call i32 @exit(i32 %60)
unreachable
62: ; preds = %53
br label %63
63: ; preds = %62, %25
%64 = load i32*, i32** %10
%65 = call i32 @BIO_flush(i32* %64)
%66 = icmp ne i32 %65, 1
br i1 %66, label %67, label %72
67: ; preds = %63
%68 = load i32, i32* @stderr
%69 = call i32 @ERR_print_errors_fp(i32 %68)
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %63
%73 = load i32*, i32** %10
%74 = call i32 @BIO_free_all(i32* %73)
%75 = call i32 (...) @ERR_free_strings()
%76 = load i32, i32* @EXIT_SUCCESS
%77 = call i32 @exit(i32 %76)
unreachable
}

LLVM IR (-O2):
@__const.main.iv = [16 x i8] c"\00\01\02\03\04\05\06\07\08\09\00\01\02\03\04\05"
@stdin = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"fgets() failed!\0A\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@.str.1 = [13 x i8] c"Ciphertext: \00"
@BIO_NOCLOSE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [80 x i8]
%4 = alloca [16 x i8]
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%9 = tail call i32 (...) @ERR_load_crypto_strings()
%10 = load i32, i32* @stdin
%11 = call i32* @fgets(i8* %6, i32 64, i32 %10)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = call i32 @strlen(i8* %6)
%20 = load i32, i32* @stdout
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = call i32 (...) @BIO_f_cipher()
%23 = call i32* @BIO_new(i32 %22)
%24 = call i32 (...) @EVP_aes_128_cbc()
%25 = call i32 @BIO_set_cipher(i32* %23, i32 %24, i8* %7, i8* %8, i32 1)
%26 = call i32 (...) @BIO_f_base64()
%27 = call i32* @BIO_new(i32 %26)
%28 = load i32, i32* @stdout
%29 = load i32, i32* @BIO_NOCLOSE
%30 = call i32* @BIO_new_fp(i32 %28, i32 %29)
%31 = call i32 @BIO_push(i32* %23, i32* %27)
%32 = call i32 @BIO_push(i32* %27, i32* %30)
%33 = call i64 @BIO_write(i32* %23, i8* %6, i32 %19)
%34 = icmp slt i64 %33, 1
br i1 %34, label %35, label %43
35: ; preds = %18
%36 = call i32 @BIO_should_retry(i32* %23)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @ERR_print_errors_fp(i32 %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %35, %18
%44 = call i32 @BIO_flush(i32* %23)
%45 = icmp eq i32 %44, 1
br i1 %45, label %51, label %46
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = call i32 @ERR_print_errors_fp(i32 %47)
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %43
%52 = call i32 @BIO_free_all(i32* %23)
%53 = call i32 (...) @ERR_free_strings()
%54 = load i32, i32* @EXIT_SUCCESS
%55 = call i32 @exit(i32 %54)
unreachable
}