#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 const *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, size_t, int /*<<< orphan*/ *);
void copy(const char *srcPath, const char *destPath) {
  FILE *srcFile = fopen(srcPath, "r");
  FILE *destFile = fopen(destPath, "w");
  char buffer[4096];
  while (!feof(srcFile)) {
    size_t readBytes = fread(buffer, 1, 4096, srcFile);
    fwrite(buffer, 1, readBytes, destFile);
  }
  fclose(destFile);
  fclose(srcFile);
}


x86 assembly (clang, -O0):
<copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11a9 <copy+0x59>
jmp    11eb <copy+0x9b>
lea    -0x1020(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1030 <fread@plt>
mov    %rax,-0x1028(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x1028(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1070 <fwrite@plt>
jmp    118b <copy+0x3b>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy>:
push   %r15
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%r14
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xe8d(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    11c4 <copy+0x74>
mov    %rsp,%r15
nop
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1190 <copy+0x40>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define void @copy(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca [4096 x i8]
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = load i8*, i8** %4
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %12, i32** %6
br label %13
13: ; preds = %18, %2
%14 = load i32*, i32** %5
%15 = call i32 @feof(i32* %14)
%16 = icmp ne i32 %15, 0
%17 = xor i1 %16, true
br i1 %17, label %18, label %26
18: ; preds = %13
%19 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%20 = load i32*, i32** %5
%21 = call i64 @fread(i8* %19, i32 1, i32 4096, i32* %20)
store i64 %21, i64* %8
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%23 = load i64, i64* %8
%24 = load i32*, i32** %6
%25 = call i32 @fwrite(i8* %22, i32 1, i64 %23, i32* %24)
br label %13
26: ; preds = %13
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define void @copy(i8* nocapture %0, i8* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%7 = tail call i32 @feof(i32* %4)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %2, %9
%10 = call i64 @fread(i8* %6, i32 1, i32 4096, i32* %4)
%11 = call i32 @fwrite(i8* %6, i32 1, i64 %10, i32* %5)
%12 = tail call i32 @feof(i32* %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %9, label %14
14: ; preds = %9, %2
%15 = tail call i32 @fclose(i32* %5)
%16 = tail call i32 @fclose(i32* %4)
ret void
}