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

/* 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();
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");
  BIO_dump_fp(stdout, ciphertext, ciphertext_len);
  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    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe40(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe56(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    $0x0,%al
call   10c0 <ERR_load_crypto_strings@plt>
mov    $0x0,%al
call   1080 <OpenSSL_add_all_algorithms@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <OPENSSL_config@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x140(%rbp)
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x140(%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    0xe30(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    -0xb0(%rbp),%rsi
mov    -0x138(%rbp),%edx
call   10b0 <BIO_dump_fp@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    0xde1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x130(%rbp),%rsi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1090 <EVP_cleanup@plt>
mov    $0x0,%al
call   10a0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
xor    %eax,%eax
call   10c0 <ERR_load_crypto_strings@plt>
xor    %eax,%eax
call   1080 <OpenSSL_add_all_algorithms@plt>
xor    %edi,%edi
call   1040 <OPENSSL_config@plt>
lea    0xe67(%rip),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0xe25(%rip),%r14
lea    0xe3f(%rip),%r15
lea    0x80(%rsp),%r12
mov    %rbx,%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r12,%r8
call   1070 <encrypt@plt>
mov    %eax,%ebx
lea    0xe59(%rip),%rdi
call   1050 <puts@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   10b0 <BIO_dump_fp@plt>
mov    %rsp,%r13
mov    %r12,%rdi
mov    %ebx,%esi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %r13,%r8
call   1030 <decrypt@plt>
cltq
movb   $0x0,(%rsp,%rax,1)
lea    0xe2d(%rip),%rdi
call   1050 <puts@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1090 <EVP_cleanup@plt>
xor    %eax,%eax
call   10a0 <ERR_free_strings@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
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 = [20 x i8] c"Decrypted text is:\0A\00"
@.str.5 = [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
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
%13 = call i32 (...) @ERR_load_crypto_strings()
%14 = call i32 (...) @OpenSSL_add_all_algorithms()
%15 = call i32 @OPENSSL_config(i32* null)
%16 = load i8*, i8** %8
%17 = load i8*, i8** %8
%18 = call i32 @strlen(i8* %17)
%19 = load i8*, i8** %6
%20 = load i8*, i8** %7
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%22 = call i32 @encrypt(i8* %16, i32 %18, i8* %19, i8* %20, i8* %21)
store i32 %22, i32* %12
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @stdout
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%26 = load i32, i32* %12
%27 = call i32 @BIO_dump_fp(i32 %24, i8* %25, i32 %26)
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%29 = load i32, i32* %12
%30 = load i8*, i8** %6
%31 = load i8*, i8** %7
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%33 = call i32 @decrypt(i8* %28, i32 %29, i8* %30, i8* %31, i8* %32)
store i32 %33, i32* %11
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 %35
store i8 0, i8* %36
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = call i32 (...) @EVP_cleanup()
%41 = 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 = [15 x i8] c"Ciphertext is:\00"
@str.6 = [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 = load i32, i32* @stdout
%14 = call i32 @BIO_dump_fp(i32 %13, i8* %5, i32 %11)
%15 = 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)
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %16
store i8 0, i8* %17
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%19 = call i32 @puts(i8* %6)
%20 = call i32 (...) @EVP_cleanup()
%21 = call i32 (...) @ERR_free_strings()
ret i32 0
}