#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*/ FILE;
typedef int /*<<< orphan*/ EVP_CIPHER_CTX;

/* Variables and functions */
int /*<<< orphan*/ EVP_EncryptFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                       int *);
int /*<<< orphan*/ EVP_EncryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_EncryptUpdate(int /*<<< orphan*/ *, unsigned char *,
                                     int *, unsigned char *, int);
int /*<<< orphan*/ EVP_MAX_IV_LENGTH;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ system(char *);
unsigned char *aes_encrypt(EVP_CIPHER_CTX *e) {
  int i, c_len, f_len = 0;
  char *filename = "/home/root/rnddata";
  unsigned char buffer[1024], temp[1024];
  unsigned char buffer_out[1024 + EVP_MAX_IV_LENGTH];
  FILE *fp, *fpout, *fprnd, *fptmp;
  int bytes;
  fp = fopen(filename, "rb");
  if (fp == NULL) {
    printf("%s can't be opened.\n", filename);
    printf("Creating 10M random data file (rnddata)\n");
    system("dd if=/dev/urandom of=/home/root/rnddata bs=1048576 count=10");
    fp = fopen(filename, "rb");
    if (fp == NULL) {
      printf("%s Error for file opening!\n", filename);
      return 0;
    }
  }
  fpout = fopen("/home/root/rnddata_enc", "wb");
  EVP_EncryptInit_ex(e, NULL, NULL, NULL, NULL);
  while ((bytes = fread(buffer, 1, 1024, fp)) != 0) {
    EVP_EncryptUpdate(e, buffer_out, &c_len, buffer, bytes);
    fwrite(buffer_out, c_len, 1, fpout);
  }
  EVP_EncryptFinal_ex(e, buffer_out, &c_len);
  fwrite(buffer_out, c_len, 1, fpout);
  fclose(fp);
  fclose(fpout);
  return 0;
}


x86 assembly (clang, -O0):
<aes_encrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x870,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    0xe53(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
add    $0x400,%eax
mov    %rsp,%rcx
mov    %rcx,-0x838(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x870(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x840(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe1d(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
jne    128f <aes_encrypt+0xff>
mov    -0x28(%rbp),%rsi
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe02(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe1d(%rip),%rdi
call   1050 <system@plt>
mov    -0x28(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x848(%rbp)
cmpq   $0x0,-0x848(%rbp)
jne    128a <aes_encrypt+0xfa>
mov    -0x28(%rbp),%rsi
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x868(%rbp)
jmp    1387 <aes_encrypt+0x1f7>
jmp    128f <aes_encrypt+0xff>
lea    0xe17(%rip),%rdi
lea    0xe27(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x850(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1090 <EVP_EncryptInit_ex@plt>
lea    -0x430(%rbp),%rdi
mov    -0x848(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1030 <fread@plt>
mov    %eax,-0x864(%rbp)
cmp    $0x0,%eax
je     132e <aes_encrypt+0x19e>
mov    -0x870(%rbp),%rsi
mov    -0x10(%rbp),%rdi
lea    -0x430(%rbp),%rcx
mov    -0x864(%rbp),%r8d
lea    -0x18(%rbp),%rdx
call   1070 <EVP_EncryptUpdate@plt>
mov    -0x870(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x850(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
jmp    12c0 <aes_encrypt+0x130>
mov    -0x870(%rbp),%rsi
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rdx
call   1080 <EVP_EncryptFinal_ex@plt>
mov    -0x870(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x850(%rbp),%rcx
mov    $0x1,%edx
call   10b0 <fwrite@plt>
mov    -0x848(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x850(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x868(%rbp)
mov    -0x838(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_encrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r13
mov    %rsp,%r12
mov    0x2e27(%rip),%rax
mov    $0x400,%ecx
add    (%rax),%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    0xe20(%rip),%rdi
lea    0xe2c(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    123f <aes_encrypt+0x9f>
lea    0xe1b(%rip),%rdi
lea    0xdfe(%rip),%r14
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe8b(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0c(%rip),%rdi
call   1060 <system@plt>
lea    0xde8(%rip),%rsi
mov    %r14,%rdi
call   10b0 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
je     131b <aes_encrypt+0x17b>
mov    %r12,-0x38(%rbp)
lea    0xe3a(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r12
mov    %r13,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   10a0 <EVP_EncryptInit_ex@plt>
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     12d1 <aes_encrypt+0x131>
lea    -0x440(%rbp),%r14
xchg   %ax,%ax
mov    %r13,%rdi
mov    %rbx,%rsi
lea    -0x2c(%rbp),%rdx
mov    %r14,%rcx
mov    %eax,%r8d
call   1080 <EVP_EncryptUpdate@plt>
mov    -0x2c(%rbp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %r12,%rcx
call   10c0 <fwrite@plt>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1290 <aes_encrypt+0xf0>
lea    -0x2c(%rbp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1090 <EVP_EncryptFinal_ex@plt>
mov    -0x2c(%rbp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %r12,%rcx
call   10c0 <fwrite@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%r12
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd46(%rip),%rdi
lea    0xcd7(%rip),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1307 <aes_encrypt+0x167>

LLVM IR (-O0):
@.str = [19 x i8] c"/home/root/rnddata\00"
@EVP_MAX_IV_LENGTH = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"%s can't be opened.\0A\00"
@.str.3 = [41 x i8] c"Creating 10M random data file (rnddata)\0A\00"
@.str.4 = [61 x i8] c"dd if=/dev/urandom of=/home/root/rnddata bs=1048576 count=10\00"
@.str.5 = [28 x i8] c"%s Error for file opening!\0A\00"
@.str.6 = [23 x i8] c"/home/root/rnddata_enc\00"
@.str.7 = [3 x i8] c"wb\00"
define i8* @aes_encrypt(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca [1024 x i8]
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca i32
%17 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %6
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8** %7
%18 = load i32, i32* @EVP_MAX_IV_LENGTH
%19 = add nsw i32 1024, %18
%20 = zext i32 %19 to i64
%21 = call i8* @llvm.stacksave()
store i8* %21, i8** %10
%22 = alloca i8, i64 %20
store i64 %20, i64* %11
%23 = load i8*, i8** %7
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %24, i32** %12
%25 = load i32*, i32** %12
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %40
27: ; preds = %1
%28 = load i8*, i8** %7
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @system(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
%32 = load i8*, i8** %7
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %33, i32** %12
%34 = load i32*, i32** %12
%35 = icmp eq i32* %34, null
br i1 %35, label %36, label %39
36: ; preds = %27
%37 = load i8*, i8** %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* %37)
store i8* null, i8** %2
store i32 1, i32* %17
br label %67
39: ; preds = %27
br label %40
40: ; preds = %39, %1
%41 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
store i32* %41, i32** %13
%42 = load i32*, i32** %3
%43 = call i32 @EVP_EncryptInit_ex(i32* %42, i32* null, i32* null, i32* null, i32* null)
br label %44
44: ; preds = %49, %40
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%46 = load i32*, i32** %12
%47 = call i32 @fread(i8* %45, i32 1, i32 1024, i32* %46)
store i32 %47, i32* %16
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %57
49: ; preds = %44
%50 = load i32*, i32** %3
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%52 = load i32, i32* %16
%53 = call i32 @EVP_EncryptUpdate(i32* %50, i8* %22, i32* %5, i8* %51, i32 %52)
%54 = load i32, i32* %5
%55 = load i32*, i32** %13
%56 = call i32 @fwrite(i8* %22, i32 %54, i32 1, i32* %55)
br label %44
57: ; preds = %44
%58 = load i32*, i32** %3
%59 = call i32 @EVP_EncryptFinal_ex(i32* %58, i8* %22, i32* %5)
%60 = load i32, i32* %5
%61 = load i32*, i32** %13
%62 = call i32 @fwrite(i8* %22, i32 %60, i32 1, i32* %61)
%63 = load i32*, i32** %12
%64 = call i32 @fclose(i32* %63)
%65 = load i32*, i32** %13
%66 = call i32 @fclose(i32* %65)
store i8* null, i8** %2
store i32 1, i32* %17
br label %67
67: ; preds = %57, %36
%68 = load i8*, i8** %10
%69 = load i8*, i8** %2
ret i8* %69
}

LLVM IR (-O2):
@.str = [19 x i8] c"/home/root/rnddata\00"
@EVP_MAX_IV_LENGTH = global i32 0
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [21 x i8] c"%s can't be opened.\0A\00"
@.str.4 = [61 x i8] c"dd if=/dev/urandom of=/home/root/rnddata bs=1048576 count=10\00"
@.str.5 = [28 x i8] c"%s Error for file opening!\0A\00"
@.str.6 = [23 x i8] c"/home/root/rnddata_enc\00"
@.str.7 = [3 x i8] c"wb\00"
@str = [40 x i8] c"Creating 10M random data file (rnddata)\00"
define noalias i8* @aes_encrypt(i32* %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @EVP_MAX_IV_LENGTH
%7 = add nsw i32 %6, 1024
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %21
13: ; preds = %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%16 = tail call i32 @system(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %40
21: ; preds = %13, %1
%22 = phi i32* [ %17, %13 ], [ %11, %1 ]
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%24 = tail call i32 @EVP_EncryptInit_ex(i32* %0, i32* null, i32* null, i32* null, i32* null)
%25 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %22)
%26 = icmp eq i32 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %21, %27
%28 = phi i32 [ %32, %27 ], [ %25, %21 ]
%29 = call i32 @EVP_EncryptUpdate(i32* %0, i8* %10, i32* %2, i8* %5, i32 %28)
%30 = load i32, i32* %2
%31 = call i32 @fwrite(i8* %10, i32 %30, i32 1, i32* %23)
%32 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %22)
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %27
34: ; preds = %27, %21
%35 = call i32 @EVP_EncryptFinal_ex(i32* %0, i8* %10, i32* %2)
%36 = load i32, i32* %2
%37 = call i32 @fwrite(i8* %10, i32 %36, i32 1, i32* %23)
%38 = call i32 @fclose(i32* %22)
%39 = call i32 @fclose(i32* %23)
br label %40
40: ; preds = %34, %19
ret i8* null
}