#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int copyFile(char *destPath, char *srcPath) {
  FILE *fdDest, *fdSrc;
  int byte;
  if ((fdDest = fopen(destPath, "w")) && (fdSrc = fopen(srcPath, "r"))) {
    while ((byte = getc(fdSrc)) != EOF)
      putc(byte, fdDest);
    fclose(fdDest);
    fclose(fdSrc);
    return 0;
  }
  perror("File copy failed");
  printf("dest: %s\n", destPath);
  printf("src: %s\n", srcPath);
  return -1;
}


x86 assembly (clang, -O0):
<copyFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11fb <copyFile+0x9b>
mov    -0x18(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     11fb <copyFile+0x9b>
jmp    11b1 <copyFile+0x51>
mov    -0x28(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2e24(%rip),%rcx
cmp    (%rcx),%eax
je     11dd <copyFile+0x7d>
mov    -0x2c(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1050 <putc@plt>
jmp    11b1 <copyFile+0x51>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    122e <copyFile+0xce>
lea    0xe02(%rip),%rdi
call   1070 <perror@plt>
mov    -0x10(%rbp),%rsi
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xdfd(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copyFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e5 <copyFile+0x85>
mov    %rax,%r14
lea    0xe79(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e5 <copyFile+0x85>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <getc@plt>
mov    0x2e40(%rip),%r15
cmp    (%r15),%eax
je     11c7 <copyFile+0x67>
nopl   (%rax)
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <putc@plt>
mov    %rbx,%rdi
call   1080 <getc@plt>
cmp    (%r15),%eax
jne    11b0 <copyFile+0x50>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xe18(%rip),%rdi
call   1070 <perror@plt>
lea    0xe1d(%rip),%rdi
mov    %r12,%rsi
call   1040 <printf@plt>
lea    0xe18(%rip),%rdi
mov    %r15,%rsi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
jmp    11d9 <copyFile+0x79>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [17 x i8] c"File copy failed\00"
@.str.3 = [10 x i8] c"dest: %s\0A\00"
@.str.4 = [9 x i8] c"src: %s\0A\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
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %31
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %31
16: ; preds = %12
br label %17
17: ; preds = %22, %16
%18 = load i32*, i32** %7
%19 = call i32 @getc(i32* %18)
store i32 %19, i32* %8
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* %8
%24 = load i32*, i32** %6
%25 = call i32 @putc(i32 %23, i32* %24)
br label %17
26: ; preds = %17
%27 = load i32*, i32** %6
%28 = call i32 @fclose(i32* %27)
%29 = load i32*, i32** %7
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %3
br label %37
31: ; preds = %12, %2
%32 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %4
%34 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %5
%36 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %35)
store i32 -1, i32* %3
br label %37
37: ; preds = %31, %26
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.2 = [17 x i8] c"File copy failed\00"
@.str.3 = [10 x i8] c"dest: %s\0A\00"
@.str.4 = [9 x i8] c"src: %s\0A\00"
define i32 @copyFile(i8* %0, i8* %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 = icmp eq i32* %6, null
br i1 %7, label %21, label %8
8: ; preds = %5
%9 = tail call i32 @getc(i32* %6)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %18, label %12
12: ; preds = %8, %12
%13 = phi i32 [ %15, %12 ], [ %9, %8 ]
%14 = tail call i32 @putc(i32 %13, i32* %3)
%15 = tail call i32 @getc(i32* %6)
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %12
18: ; preds = %12, %8
%19 = tail call i32 @fclose(i32* %3)
%20 = tail call i32 @fclose(i32* %6)
br label %25
21: ; preds = %5, %2
%22 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%24 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %1)
br label %25
25: ; preds = %21, %18
%26 = phi i32 [ 0, %18 ], [ -1, %21 ]
ret i32 %26
}