#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*/, char const *, 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(char *);
int main(void) {
  unsigned char *key = (unsigned char *)"01234567890123456789012345678901";
  unsigned char *iv = (unsigned char *)"01234567890123456";
  unsigned char *plaintext =
      (unsigned char *)"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((char *)plaintext), key, iv, ciphertext);
  printf("Ciphertext is:\n");
  BIO_dump_fp(stdout, (const char *)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    $0x130,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe47(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xe5d(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xe64(%rip),%rax
mov    %rax,-0x20(%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    -0x20(%rbp),%rax
mov    %rax,-0x130(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x130(%rbp),%rdi
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0xa0(%rbp),%r8
call   1070 <encrypt@plt>
mov    %eax,-0x128(%rbp)
lea    0xe37(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x128(%rbp),%edx
call   10b0 <BIO_dump_fp@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x128(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    -0x120(%rbp),%r8
call   1030 <decrypt@plt>
mov    %eax,-0x124(%rbp)
movslq -0x124(%rbp),%rax
movb   $0x0,-0x120(%rbp,%rax,1)
lea    0xde8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x120(%rbp),%rsi
lea    0xde7(%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    $0x130,%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() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8** %4
%9 = call i32 (...) @ERR_load_crypto_strings()
%10 = call i32 (...) @OpenSSL_add_all_algorithms()
%11 = call i32 @OPENSSL_config(i32* null)
%12 = load i8*, i8** %4
%13 = load i8*, i8** %4
%14 = call i32 @strlen(i8* %13)
%15 = load i8*, i8** %2
%16 = load i8*, i8** %3
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%18 = call i32 @encrypt(i8* %12, i32 %14, i8* %15, i8* %16, i8* %17)
store i32 %18, i32* %8
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = load i32, i32* %8
%23 = call i32 @BIO_dump_fp(i32 %20, i8* %21, i32 %22)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* %8
%26 = load i8*, i8** %2
%27 = load i8*, i8** %3
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%29 = call i32 @decrypt(i8* %24, i32 %25, i8* %26, i8* %27, i8* %28)
store i32 %29, i32* %7
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 %31
store i8 0, i8* %32
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = call i32 (...) @EVP_cleanup()
%37 = 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() {
%1 = alloca [128 x i8]
%2 = alloca [128 x i8]
%3 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (...) @ERR_load_crypto_strings()
%6 = tail call i32 (...) @OpenSSL_add_all_algorithms()
%7 = tail call i32 @OPENSSL_config(i32* null)
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @encrypt(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i32 %8, 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* %3)
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = call i32 @BIO_dump_fp(i32 %11, i8* %3, i32 %9)
%13 = call i32 @decrypt(i8* %3, i32 %9, 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* %4)
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %14
store i8 0, i8* %15
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%17 = call i32 @puts(i8* %4)
%18 = call i32 (...) @EVP_cleanup()
%19 = call i32 (...) @ERR_free_strings()
ret i32 0
}