#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*/ ciphertext;

/* Variables and functions */
int /*<<< orphan*/ BIO_dump_fp(int /*<<< orphan*/, unsigned char *, int);
int /*<<< orphan*/ ERR_free_strings();
int /*<<< orphan*/ ERR_load_crypto_strings();
int /*<<< orphan*/ EVP_cleanup();
int /*<<< orphan*/ OPENSSL_config(int /*<<< orphan*/ *);
int /*<<< orphan*/ OpenSSL_add_all_algorithms();
char *base64(unsigned char *, int);
int decrypt(unsigned char *, int, unsigned char *, unsigned char *,
            unsigned char *);
int encrypt(unsigned char *, int /*<<< orphan*/, unsigned char *,
            unsigned char *, unsigned char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strlen(unsigned char *);
int main(int arc, char *argv[]) {
  unsigned char *key = "01234567890123456789012345678901";
  unsigned char *iv = "01234567890123456";
  unsigned char *plaintext = "The quick brown fox jumps over the lazy dog";
  unsigned char ciphertext[128];
  unsigned char decryptedtext[128];
  int decryptedtext_len, ciphertext_len;
  ERR_load_crypto_strings();
  OpenSSL_add_all_algorithms();
  OPENSSL_config(NULL);
  ciphertext_len = encrypt(plaintext, strlen(plaintext), key, iv, ciphertext);
  printf("Ciphertext is:\n");
  char *output = base64(ciphertext, sizeof(ciphertext));
  BIO_dump_fp(stdout, ciphertext, ciphertext_len);
  printf("Base64: *%s*\n", output);
  decryptedtext_len =
      decrypt(ciphertext, ciphertext_len, key, iv, decryptedtext);
  decryptedtext[decryptedtext_len] = '\0';
  printf("Decrypted text is:\n");
  printf("%s\n", decryptedtext);
  EVP_cleanup();
  ERR_free_strings();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe46(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe4d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10d0 <ERR_load_crypto_strings@plt>
mov    $0x0,%al
call   1090 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <OPENSSL_config@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x148(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x148(%rbp),%rdi
mov    %eax,%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0xb0(%rbp),%r8
call   1070 <encrypt@plt>
mov    %eax,-0x138(%rbp)
lea    0xe20(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    $0x80,%esi
call   1080 <base64@plt>
mov    %rax,-0x140(%rbp)
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    -0xb0(%rbp),%rsi
mov    -0x138(%rbp),%edx
call   10c0 <BIO_dump_fp@plt>
mov    -0x140(%rbp),%rsi
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x138(%rbp),%esi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    -0x130(%rbp),%r8
call   1030 <decrypt@plt>
mov    %eax,-0x134(%rbp)
movslq -0x134(%rbp),%rax
movb   $0x0,-0x130(%rbp,%rax,1)
lea    0xdb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   10a0 <EVP_cleanup@plt>
mov    $0x0,%al
call   10b0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   10e0 <ERR_load_crypto_strings@plt>
xor    %eax,%eax
call   10a0 <OpenSSL_add_all_algorithms@plt>
xor    %edi,%edi
call   1040 <OPENSSL_config@plt>
lea    0xe48(%rip),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
lea    0xe06(%rip),%r15
lea    0xe20(%rip),%r14
lea    0x80(%rsp),%r12
mov    %rbp,%rdi
mov    %eax,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %r12,%r8
call   1080 <encrypt@plt>
mov    %eax,%ebp
lea    0xe48(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    $0x80,%esi
call   1090 <base64@plt>
mov    %rax,%rbx
mov    0x2d9f(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   10d0 <BIO_dump_fp@plt>
lea    0xe0b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rsp,%rbx
mov    %r12,%rdi
mov    %ebp,%esi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rbx,%r8
call   1030 <decrypt@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xdfb(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   10b0 <EVP_cleanup@plt>
xor    %eax,%eax
call   10c0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [33 x i8] c"01234567890123456789012345678901\00"
@.str.1 = [18 x i8] c"01234567890123456\00"
@.str.2 = [44 x i8] c"The quick brown fox jumps over the lazy dog\00"
@.str.3 = [16 x i8] c"Ciphertext is:\0A\00"
@stdout = global i32 0
@.str.4 = [14 x i8] c"Base64: *%s*\0A\00"
@.str.5 = [20 x i8] c"Decrypted text is:\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [128 x i8]
%10 = alloca [128 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8** %8
%14 = call i32 (...) @ERR_load_crypto_strings()
%15 = call i32 (...) @OpenSSL_add_all_algorithms()
%16 = call i32 @OPENSSL_config(i32* null)
%17 = load i8*, i8** %8
%18 = load i8*, i8** %8
%19 = call i32 @strlen(i8* %18)
%20 = load i8*, i8** %6
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%23 = call i32 @encrypt(i8* %17, i32 %19, i8* %20, i8* %21, i8* %22)
store i32 %23, i32* %12
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = call i8* @base64(i8* %25, i32 128)
store i8* %26, i8** %13
%27 = load i32, i32* @stdout
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %12
%30 = call i32 @BIO_dump_fp(i32 %27, i8* %28, i32 %29)
%31 = load i8*, i8** %13
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %12
%35 = load i8*, i8** %6
%36 = load i8*, i8** %7
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%38 = call i32 @decrypt(i8* %33, i32 %34, i8* %35, i8* %36, i8* %37)
store i32 %38, i32* %11
%39 = load i32, i32* %11
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 %40
store i8 0, i8* %41
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%43 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %43)
%45 = call i32 (...) @EVP_cleanup()
%46 = call i32 (...) @ERR_free_strings()
ret i32 0
}

LLVM IR (-O2):
@.str = [33 x i8] c"01234567890123456789012345678901\00"
@.str.1 = [18 x i8] c"01234567890123456\00"
@.str.2 = [44 x i8] c"The quick brown fox jumps over the lazy dog\00"
@stdout = global i32 0
@.str.4 = [14 x i8] c"Base64: *%s*\0A\00"
@str = [15 x i8] c"Ciphertext is:\00"
@str.7 = [19 x i8] c"Decrypted text is:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = tail call i32 (...) @ERR_load_crypto_strings()
%8 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%9 = tail call i32 @OPENSSL_config(i32* null)
%10 = tail call i32 @strlen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%11 = call i32 @encrypt(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%13 = call i8* @base64(i8* %5, i32 128)
%14 = load i32, i32* @stdout
%15 = call i32 @BIO_dump_fp(i32 %14, i8* %5, i32 %11)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %13)
%17 = call i32 @decrypt(i8* %5, i32 %11, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%21 = call i32 @puts(i8* %6)
%22 = call i32 (...) @EVP_cleanup()
%23 = call i32 (...) @ERR_free_strings()
ret i32 0
}