#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;

/* Variables and functions */
scalar_t__ EOF;
scalar_t__ aes_file(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char const *,
                    int);
int /*<<< orphan*/ errno;
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int aes_copy(const char *infile, const char *outfile, const char *password,
             int operation) {
  FILE *infid = fopen(infile, "r");
  if (infid == NULL) {
    fprintf(stderr, "ERROR: %s", strerror(errno));
    return -1;
  }
  FILE *outfid = fopen(outfile, "w");
  if (outfid == NULL) {
    fprintf(stderr, "ERROR: %s", strerror(errno));
    fclose(infid);
    return -1;
  }
  if (aes_file(infid, outfid, password, operation) < 0) {
    fclose(infid);
    fclose(outfid);
    return -1;
  }
  if (fclose(infid) == EOF) {
    fprintf(stderr, "ERROR: %s", strerror(errno));
    fclose(outfid);
    return -1;
  }
  if (fclose(outfid) == EOF) {
    fprintf(stderr, "ERROR: %s", strerror(errno));
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<aes_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11be <aes_copy+0x6e>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    %rax,%rdx
lea    0xe55(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <aes_copy+0x1bc>
mov    -0x18(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    121e <aes_copy+0xce>
mov    0x2df4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x40(%rbp),%edi
mov    %rax,%rdx
lea    0xdfe(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <aes_copy+0x1bc>
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x24(%rbp),%ecx
call   1040 <aes_file@plt>
cmp    $0x0,%rax
jge    125a <aes_copy+0x10a>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <aes_copy+0x1bc>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d7e(%rip),%rcx
cmp    (%rcx),%rax
jne    12b4 <aes_copy+0x164>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xd68(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <aes_copy+0x1bc>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2d24(%rip),%rcx
cmp    (%rcx),%rax
jne    1305 <aes_copy+0x1b5>
mov    0x2d04(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd0e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    130c <aes_copy+0x1bc>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aes_copy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rsi,%rbp
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1233 <aes_copy+0xe3>
mov    %rax,%rbx
lea    0xe8c(%rip),%rsi
mov    %rbp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ef <aes_copy+0x9f>
mov    %rax,%r14
mov    %rbx,%rdi
mov    %rax,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
call   1040 <aes_file@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %rbp,%rbp
js     11e5 <aes_copy+0x95>
mov    0x2e30(%rip),%rbx
cmp    (%rbx),%rax
jne    1221 <aes_copy+0xd1>
mov    0x2e14(%rip),%rax
mov    (%rax),%ebx
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe27(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    125b <aes_copy+0x10b>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebp
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdf5(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    125b <aes_copy+0x10b>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    (%rbx),%rcx
jne    1260 <aes_copy+0x110>
mov    0x2d9e(%rip),%rax
mov    (%rax),%ebx
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xdb1(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"ERROR: %s\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"w\00"
@EOF = global i64 0
define i32 @aes_copy(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
%11 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %6
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %10
%14 = load i32*, i32** %10
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %21
16: ; preds = %4
%17 = load i32, i32* @stderr
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %19)
store i32 -1, i32* %5
br label %68
21: ; preds = %4
%22 = load i8*, i8** %7
%23 = call i32* @fopen(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %23, i32** %11
%24 = load i32*, i32** %11
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %33
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = load i32, i32* @errno
%29 = call i8* @strerror(i32 %28)
%30 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %29)
%31 = load i32*, i32** %10
%32 = call i64 @fclose(i32* %31)
store i32 -1, i32* %5
br label %68
33: ; preds = %21
%34 = load i32*, i32** %10
%35 = load i32*, i32** %11
%36 = load i8*, i8** %8
%37 = load i32, i32* %9
%38 = call i64 @aes_file(i32* %34, i32* %35, i8* %36, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %33
%41 = load i32*, i32** %10
%42 = call i64 @fclose(i32* %41)
%43 = load i32*, i32** %11
%44 = call i64 @fclose(i32* %43)
store i32 -1, i32* %5
br label %68
45: ; preds = %33
%46 = load i32*, i32** %10
%47 = call i64 @fclose(i32* %46)
%48 = load i64, i64* @EOF
%49 = icmp eq i64 %47, %48
br i1 %49, label %50, label %57
50: ; preds = %45
%51 = load i32, i32* @stderr
%52 = load i32, i32* @errno
%53 = call i8* @strerror(i32 %52)
%54 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %53)
%55 = load i32*, i32** %11
%56 = call i64 @fclose(i32* %55)
store i32 -1, i32* %5
br label %68
57: ; preds = %45
%58 = load i32*, i32** %11
%59 = call i64 @fclose(i32* %58)
%60 = load i64, i64* @EOF
%61 = icmp eq i64 %59, %60
br i1 %61, label %62, label %67
62: ; preds = %57
%63 = load i32, i32* @stderr
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %65)
store i32 -1, i32* %5
br label %68
67: ; preds = %57
store i32 0, i32* %5
br label %68
68: ; preds = %67, %62, %50, %40, %26, %16
%69 = load i32, i32* %5
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [10 x i8] c"ERROR: %s\00"
@errno = global i32 0
@.str.2 = [2 x i8] c"w\00"
@EOF = global i64 0
define i32 @aes_copy(i8* nocapture %0, i8* nocapture %1, i8* %2, i32 %3) {
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %10)
br label %45
12: ; preds = %4
%13 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %12
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i8* @strerror(i32 %17)
%19 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = tail call i64 @fclose(i32* %5)
br label %45
21: ; preds = %12
%22 = tail call i64 @aes_file(i32* %5, i32* %13, i8* %2, i32 %3)
%23 = icmp slt i64 %22, 0
%24 = tail call i64 @fclose(i32* %5)
br i1 %23, label %25, label %27
25: ; preds = %21
%26 = tail call i64 @fclose(i32* %13)
br label %45
27: ; preds = %21
%28 = load i64, i64* @EOF
%29 = icmp eq i64 %24, %28
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i32, i32* @stderr
%32 = load i32, i32* @errno
%33 = tail call i8* @strerror(i32 %32)
%34 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = tail call i64 @fclose(i32* %13)
br label %45
36: ; preds = %27
%37 = tail call i64 @fclose(i32* %13)
%38 = load i64, i64* @EOF
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %45
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i32, i32* @errno
%43 = tail call i8* @strerror(i32 %42)
%44 = tail call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %15, %25, %30, %40, %36, %7
%46 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %25 ], [ -1, %30 ], [ -1, %40 ], [ 0, %36 ]
ret i32 %46
}