#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_DecryptFinal_ex(int /*<<< orphan*/ *, unsigned char *,
                                       int *);
int /*<<< orphan*/ EVP_DecryptInit_ex(int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *,
                                      int /*<<< orphan*/ *);
int /*<<< orphan*/ EVP_DecryptUpdate(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 *, char *);
unsigned char *aes_decrypt(EVP_CIPHER_CTX *e) {
  int c_len, f_len = 0;
  char *filename = "/home/root/rnddata_enc";
  unsigned char buffer[1024];
  unsigned char buffer_out[1024 + EVP_MAX_IV_LENGTH];
  FILE *fp, *fpout;
  int bytes;
  fp = fopen(filename, "rb");
  if (fp == NULL) {
    printf("%s can't be opened.\n", filename);
    return 0;
  }
  fpout = fopen("/home/root/rnddata_dec", "wb");
  EVP_DecryptInit_ex(e, NULL, NULL, NULL, NULL);
  while ((bytes = fread(buffer, 1, 1024, fp)) != 0) {
    EVP_DecryptUpdate(e, buffer_out, &c_len, buffer, bytes);
    fwrite(buffer_out, c_len, 1, fpout);
  }
  EVP_DecryptFinal_ex(e, buffer_out, &c_len);
  fwrite(buffer_out, c_len, 1, fpout);
  fclose(fp);
  fclose(fpout);
  return 0;
}


x86 assembly (clang, -O0):
<aes_decrypt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
add    $0x400,%eax
mov    %rsp,%rcx
mov    %rcx,-0x428(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x450(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x430(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    1227 <aes_decrypt+0xa7>
mov    -0x20(%rbp),%rsi
lea    0xe0f(%rip),%rdi
call   1060 <printf@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x448(%rbp)
jmp    131f <aes_decrypt+0x19f>
lea    0xe01(%rip),%rdi
lea    0xe11(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x440(%rbp)
mov    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rsi
mov    %r8,%rdx
mov    %r8,%rcx
call   1070 <EVP_DecryptInit_ex@plt>
lea    -0x420(%rbp),%rdi
mov    -0x438(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x444(%rbp)
cmp    $0x0,%eax
je     12c6 <aes_decrypt+0x146>
mov    -0x450(%rbp),%rsi
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rcx
mov    -0x444(%rbp),%r8d
lea    -0x14(%rbp),%rdx
call   1090 <EVP_DecryptUpdate@plt>
mov    -0x450(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x440(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
jmp    1258 <aes_decrypt+0xd8>
mov    -0x450(%rbp),%rsi
mov    -0x10(%rbp),%rdi
lea    -0x14(%rbp),%rdx
call   1030 <EVP_DecryptFinal_ex@plt>
mov    -0x450(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x440(%rbp),%rcx
mov    $0x1,%edx
call   10a0 <fwrite@plt>
mov    -0x438(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x440(%rbp),%rdi
call   1050 <fclose@plt>
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x448(%rbp)
mov    -0x428(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_decrypt>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rdi,%r14
mov    %rsp,%r12
mov    0x2e47(%rip),%rax
mov    $0x400,%ecx
add    (%rax),%ecx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rbx
sub    %rcx,%rbx
mov    %rbx,%rsp
lea    0xe40(%rip),%rdi
lea    0xe50(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a9 <aes_decrypt+0x129>
mov    %rax,%r15
mov    %r12,-0x38(%rbp)
lea    0xe4c(%rip),%rdi
lea    0xe5c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r12
mov    %r14,%rdi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1070 <EVP_DecryptInit_ex@plt>
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
je     1271 <aes_decrypt+0xf1>
lea    -0x440(%rbp),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
lea    -0x2c(%rbp),%rdx
mov    %r13,%rcx
mov    %eax,%r8d
call   1090 <EVP_DecryptUpdate@plt>
mov    -0x2c(%rbp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jne    1230 <aes_decrypt+0xb0>
lea    -0x2c(%rbp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <EVP_DecryptFinal_ex@plt>
mov    -0x2c(%rbp),%esi
mov    %rbx,%rdi
mov    $0x1,%edx
mov    %r12,%rcx
call   10a0 <fwrite@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%r12
jmp    12bc <aes_decrypt+0x13c>
lea    0xd6a(%rip),%rdi
lea    0xd49(%rip),%rsi
call   1060 <printf@plt>
mov    %r12,%rsp
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"/home/root/rnddata_enc\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 = [23 x i8] c"/home/root/rnddata_dec\00"
@.str.4 = [3 x i8] c"wb\00"
define i8* @aes_decrypt(i32* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32*
%11 = alloca i32*
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %3
store i32 0, i32* %5
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8** %6
%14 = load i32, i32* @EVP_MAX_IV_LENGTH
%15 = add nsw i32 1024, %14
%16 = zext i32 %15 to i64
%17 = call i8* @llvm.stacksave()
store i8* %17, i8** %8
%18 = alloca i8, i64 %16
store i64 %16, i64* %9
%19 = load i8*, i8** %6
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %10
%21 = load i32*, i32** %10
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %1
%24 = load i8*, i8** %6
%25 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %24)
store i8* null, i8** %2
store i32 1, i32* %13
br label %53
26: ; preds = %1
%27 = call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %27, i32** %11
%28 = load i32*, i32** %3
%29 = call i32 @EVP_DecryptInit_ex(i32* %28, i32* null, i32* null, i32* null, i32* null)
br label %30
30: ; preds = %35, %26
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %10
%33 = call i32 @fread(i8* %31, i32 1, i32 1024, i32* %32)
store i32 %33, i32* %12
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %30
%36 = load i32*, i32** %3
%37 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%38 = load i32, i32* %12
%39 = call i32 @EVP_DecryptUpdate(i32* %36, i8* %18, i32* %4, i8* %37, i32 %38)
%40 = load i32, i32* %4
%41 = load i32*, i32** %11
%42 = call i32 @fwrite(i8* %18, i32 %40, i32 1, i32* %41)
br label %30
43: ; preds = %30
%44 = load i32*, i32** %3
%45 = call i32 @EVP_DecryptFinal_ex(i32* %44, i8* %18, i32* %4)
%46 = load i32, i32* %4
%47 = load i32*, i32** %11
%48 = call i32 @fwrite(i8* %18, i32 %46, i32 1, i32* %47)
%49 = load i32*, i32** %10
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %11
%52 = call i32 @fclose(i32* %51)
store i8* null, i8** %2
store i32 1, i32* %13
br label %53
53: ; preds = %43, %23
%54 = load i8*, i8** %8
%55 = load i8*, i8** %2
ret i8* %55
}

LLVM IR (-O2):
@.str = [23 x i8] c"/home/root/rnddata_enc\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 = [23 x i8] c"/home/root/rnddata_dec\00"
@.str.4 = [3 x i8] c"wb\00"
define noalias i8* @aes_decrypt(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 ([23 x i8], [23 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 %15
13: ; preds = %1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %33
15: ; preds = %1
%16 = tail call i32* @fopen(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%17 = tail call i32 @EVP_DecryptInit_ex(i32* %0, i32* null, i32* null, i32* null, i32* null)
%18 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %11)
%19 = icmp eq i32 %18, 0
br i1 %19, label %27, label %20
20: ; preds = %15, %20
%21 = phi i32 [ %25, %20 ], [ %18, %15 ]
%22 = call i32 @EVP_DecryptUpdate(i32* %0, i8* %10, i32* %2, i8* %5, i32 %21)
%23 = load i32, i32* %2
%24 = call i32 @fwrite(i8* %10, i32 %23, i32 1, i32* %16)
%25 = call i32 @fread(i8* %5, i32 1, i32 1024, i32* %11)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %20
27: ; preds = %20, %15
%28 = call i32 @EVP_DecryptFinal_ex(i32* %0, i8* %10, i32* %2)
%29 = load i32, i32* %2
%30 = call i32 @fwrite(i8* %10, i32 %29, i32 1, i32* %16)
%31 = call i32 @fclose(i32* %11)
%32 = call i32 @fclose(i32* %16)
br label %33
33: ; preds = %27, %13
ret i8* null
}