#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__ calloc(int, int);
int /*<<< orphan*/ cipher(unsigned char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int ciphCopy(char *src, char *dst) {
  int result = 0;
  FILE *f_dst;
  FILE *f_src;
  unsigned char *buf;
  f_src = fopen(src, "rb");
  if (f_src == NULL) {
    fprintf(stderr, "Failed to open '%s'\n", src);
    return 1;
  }
  f_dst = fopen(dst, "wb");
  if (f_dst == NULL) {
    fprintf(stderr, "Failed to create '%s'\n", dst);
    fclose(f_src);
    return 1;
  }
  buf = (unsigned char *)calloc((1 << 28), sizeof(unsigned char));
  while (result = fread(buf, sizeof(unsigned char), (1 << 28), f_src),
         result > 0) {
    if (result == -1) {
      fprintf(stderr, "Failed to read from '%s'\n", src);
      fclose(f_src);
      fclose(f_dst);
      return 1;
    }
    cipher(buf);
    result = fwrite(buf, sizeof(unsigned char), result, f_dst);
    fflush(f_dst);
    if (result == -1) {
      fprintf(stderr, "Failed to write to '%s'\n", dst);
      fclose(f_src);
      fclose(f_dst);
      return 1;
    }
  }
  free(buf);
  fclose(f_src);
  fclose(f_dst);
  return 0;
}


x86 assembly (clang, -O0):
<ciphCopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11eb <ciphCopy+0x5b>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe29(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <ciphCopy+0x1b2>
mov    -0x18(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1238 <ciphCopy+0xa8>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdfd(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <ciphCopy+0x1b2>
mov    $0x10000000,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
mov    $0x10000000,%edx
call   1040 <fread@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    1320 <ciphCopy+0x190>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12b0 <ciphCopy+0x120>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xda5(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <ciphCopy+0x1b2>
mov    -0x38(%rbp),%rdi
call   1090 <cipher@plt>
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   10b0 <fwrite@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <fflush@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    131b <ciphCopy+0x18b>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xd54(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1342 <ciphCopy+0x1b2>
jmp    124b <ciphCopy+0xbb>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ciphCopy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xe5b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     125d <ciphCopy+0xcd>
mov    %rax,%r15
lea    0xe5b(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     127c <ciphCopy+0xec>
mov    %rax,%r12
mov    $0x10000000,%edi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x10000000,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    12a3 <ciphCopy+0x113>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1090 <cipher@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
call   10b0 <fwrite@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1080 <fflush@plt>
cmp    $0xffffffff,%ebp
jne    11f0 <ciphCopy+0x60>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
jmp    1297 <ciphCopy+0x107>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    $0x1,%eax
jmp    12bd <ciphCopy+0x12d>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
lea    0xd8f(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    $0x1,%eax
jmp    12bd <ciphCopy+0x12d>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r12,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Failed to open '%s'\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [23 x i8] c"Failed to create '%s'\0A\00"
@.str.4 = [26 x i8] c"Failed to read from '%s'\0A\00"
@.str.5 = [25 x i8] c"Failed to write to '%s'\0A\00"
define i32 @ciphCopy(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 0, i32* %6
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %8
%12 = load i32*, i32** %8
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %16)
store i32 1, i32* %3
br label %76
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %7
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %5
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %8
%28 = call i32 @fclose(i32* %27)
store i32 1, i32* %3
br label %76
29: ; preds = %18
%30 = call i64 @calloc(i32 268435456, i32 1)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %9
br label %32
32: ; preds = %68, %29
%33 = load i8*, i8** %9
%34 = load i32*, i32** %8
%35 = call i32 @fread(i8* %33, i32 1, i32 268435456, i32* %34)
store i32 %35, i32* %6
%36 = load i32, i32* %6
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %69
38: ; preds = %32
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %4
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = load i32*, i32** %8
%46 = call i32 @fclose(i32* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
store i32 1, i32* %3
br label %76
49: ; preds = %38
%50 = load i8*, i8** %9
%51 = call i32 @cipher(i8* %50)
%52 = load i8*, i8** %9
%53 = load i32, i32* %6
%54 = load i32*, i32** %7
%55 = call i32 @fwrite(i8* %52, i32 1, i32 %53, i32* %54)
store i32 %55, i32* %6
%56 = load i32*, i32** %7
%57 = call i32 @fflush(i32* %56)
%58 = load i32, i32* %6
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %68
60: ; preds = %49
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %5
%63 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %62)
%64 = load i32*, i32** %8
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %7
%67 = call i32 @fclose(i32* %66)
store i32 1, i32* %3
br label %76
68: ; preds = %49
br label %32
69: ; preds = %32
%70 = load i8*, i8** %9
%71 = call i32 @free(i8* %70)
%72 = load i32*, i32** %8
%73 = call i32 @fclose(i32* %72)
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
store i32 0, i32* %3
br label %76
76: ; preds = %69, %60, %41, %23, %14
%77 = load i32, i32* %3
ret i32 %77
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [21 x i8] c"Failed to open '%s'\0A\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [23 x i8] c"Failed to create '%s'\0A\00"
@.str.5 = [25 x i8] c"Failed to write to '%s'\0A\00"
define i32 @ciphCopy(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %35
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* %1)
%14 = tail call i32 @fclose(i32* %3)
br label %35
15: ; preds = %8
%16 = tail call i64 @calloc(i32 268435456, i32 1)
%17 = inttoptr i64 %16 to i8*
br label %18
18: ; preds = %21, %15
%19 = tail call i32 @fread(i8* %17, i32 1, i32 268435456, i32* %3)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = tail call i32 @cipher(i8* %17)
%23 = tail call i32 @fwrite(i8* %17, i32 1, i32 %19, i32* %9)
%24 = tail call i32 @fflush(i32* %9)
%25 = icmp eq i32 %23, -1
br i1 %25, label %26, label %18
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0), i8* %1)
%29 = tail call i32 @fclose(i32* %3)
%30 = tail call i32 @fclose(i32* %9)
br label %35
31: ; preds = %18
%32 = tail call i32 @free(i8* %17)
%33 = tail call i32 @fclose(i32* %3)
%34 = tail call i32 @fclose(i32* %9)
br label %35
35: ; preds = %31, %26, %11, %5
%36 = phi i32 [ 1, %5 ], [ 1, %11 ], [ 1, %26 ], [ 0, %31 ]
ret i32 %36
}