#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 */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(void *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ fwrite(void *, int, int, int /*<<< orphan*/ *);
void *malloc(int);
int copyFile(char *src, char *dest) {
  int readblocks;
  FILE *infile, *outfile;
  void *buffer;
  infile = fopen(src, "r");
  if (infile == NULL)
    return 1;
  outfile = fopen(dest, "w");
  buffer = malloc(1024 * sizeof(char));
  if (outfile == NULL)
    return 1;
  while (!feof(infile)) {
    readblocks = fread(buffer, sizeof(char), 1024, infile);
    fwrite(buffer, sizeof(char), readblocks, outfile);
  }
  free(buffer);
  fclose(infile);
  fclose(outfile);
  return 0;
}


x86 assembly (clang, -O0):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11ab <copyFile+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    125d <copyFile+0xed>
mov    -0x18(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11e4 <copyFile+0x74>
movl   $0x1,-0x4(%rbp)
jmp    125d <copyFile+0xed>
jmp    11e9 <copyFile+0x79>
mov    -0x28(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1207 <copyFile+0x97>
jmp    123b <copyFile+0xcb>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1090 <fwrite@plt>
jmp    11e9 <copyFile+0x79>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xe7f(%rip),%rsi
call   1080 <fopen@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     120f <copyFile+0x9f>
mov    %rax,%r15
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    $0x400,%edi
call   1070 <malloc@plt>
test   %r14,%r14
je     120f <copyFile+0x9f>
mov    %rax,%rbx
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    11f5 <copyFile+0x85>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r14,%rcx
call   1090 <fwrite@plt>
jmp    11c0 <copyFile+0x50>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @copyFile(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
%10 = load i8*, i8** %4
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %43
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %17, i32** %8
%18 = call i8* @malloc(i32 1024)
store i8* %18, i8** %9
%19 = load i32*, i32** %8
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 1, i32* %3
br label %43
22: ; preds = %15
br label %23
23: ; preds = %28, %22
%24 = load i32*, i32** %7
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
%27 = xor i1 %26, true
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = load i8*, i8** %9
%30 = load i32*, i32** %7
%31 = call i32 @fread(i8* %29, i32 1, i32 1024, i32* %30)
store i32 %31, i32* %6
%32 = load i8*, i8** %9
%33 = load i32, i32* %6
%34 = load i32*, i32** %8
%35 = call i32 @fwrite(i8* %32, i32 1, i32 %33, i32* %34)
br label %23
36: ; preds = %23
%37 = load i8*, i8** %9
%38 = call i32 @free(i8* %37)
%39 = load i32*, i32** %7
%40 = call i32 @fclose(i32* %39)
%41 = load i32*, i32** %8
%42 = call i32 @fclose(i32* %41)
store i32 0, i32* %3
br label %43
43: ; preds = %36, %21, %14
%44 = load i32, i32* %3
ret i32 %44
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @copyFile(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %21, label %5
5: ; preds = %2
%6 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%7 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%8 = icmp eq i32* %6, null
br i1 %8, label %21, label %9
9: ; preds = %5
%10 = tail call i32 @feof(i32* %3)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %9, %12
%13 = tail call i32 @fread(i8* %7, i32 1, i32 1024, i32* %3)
%14 = tail call i32 @fwrite(i8* %7, i32 1, i32 %13, i32* %6)
%15 = tail call i32 @feof(i32* %3)
%16 = icmp eq i32 %15, 0
br i1 %16, label %12, label %17
17: ; preds = %12, %9
%18 = tail call i32 @free(i8* %7)
%19 = tail call i32 @fclose(i32* %3)
%20 = tail call i32 @fclose(i32* %6)
br label %21
21: ; preds = %5, %2, %17
%22 = phi i32 [ 0, %17 ], [ 1, %2 ], [ 1, %5 ]
ret i32 %22
}