#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 */
char EOF;
int /*<<< orphan*/ F_OK;
int access(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int copy_file(const char *from, const char *to) {
  if (access(to, F_OK) != -1) {
    printf("File %s already exists! Please delete it and run again\n", to);
    return -1;
  }
  char ch;
  FILE *source, *target;
  source = fopen(from, "r");
  if (source == NULL) {
    return -1;
  }
  target = fopen(to, "w");
  if (target == NULL) {
    fclose(source);
    return -1;
  }
  while ((ch = fgetc(source)) != EOF) {
    fputc(ch, target);
  }
  printf("%s successfully backed up to %s\n", from, to);
  fclose(source);
  fclose(target);
  return 0;
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     11a9 <copy_file+0x49>
mov    -0x18(%rbp),%rsi
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <copy_file+0x111>
mov    -0x10(%rbp),%rdi
lea    0xe84(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d4 <copy_file+0x74>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <copy_file+0x111>
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1208 <copy_file+0xa8>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1271 <copy_file+0x111>
jmp    120d <copy_file+0xad>
mov    -0x28(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x19(%rbp)
movsbl %al,%eax
mov    0x2dc5(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     1242 <copy_file+0xe2>
mov    -0x19(%rbp),%al
mov    -0x30(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    120d <copy_file+0xad>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     119f <copy_file+0x3f>
lea    0xe75(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    1233 <copy_file+0xd3>
lea    0xe92(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     1233 <copy_file+0xd3>
mov    %rax,%rbx
lea    0xe78(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122b <copy_file+0xcb>
mov    %rax,%r12
mov    %rbx,%rdi
call   1050 <fgetc@plt>
mov    0x2e07(%rip),%rbp
cmp    0x0(%rbp),%al
je     1208 <copy_file+0xa8>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %r12,%rsi
call   1060 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    0x0(%rbp),%al
jne    11f0 <copy_file+0x90>
lea    0xe2d(%rip),%rdi
xor    %ebp,%ebp
mov    %r14,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r12,%rdi
jmp    122e <copy_file+0xce>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@F_OK = global i32 0
@.str = [56 x i8] c"File %s already exists! Please delete it and run again\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.3 = [33 x i8] c"%s successfully backed up to %s\0A\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8
%7 = alloca i32*
%8 = alloca i32*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = load i32, i32* @F_OK
%11 = call i32 @access(i8* %9, i32 %10)
%12 = icmp ne i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 -1, i32* %3
br label %50
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %22
21: ; preds = %16
store i32 -1, i32* %3
br label %50
22: ; preds = %16
%23 = load i8*, i8** %5
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %24, i32** %8
%25 = load i32*, i32** %8
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %22
%28 = load i32*, i32** %7
%29 = call i32 @fclose(i32* %28)
store i32 -1, i32* %3
br label %50
30: ; preds = %22
br label %31
31: ; preds = %38, %30
%32 = load i32*, i32** %7
%33 = call signext i8 @fgetc(i32* %32)
store i8 %33, i8* %6
%34 = sext i8 %33 to i32
%35 = load i8, i8* @EOF
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %34, %36
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i8, i8* %6
%40 = load i32*, i32** %8
%41 = call i32 @fputc(i8 signext %39, i32* %40)
br label %31
42: ; preds = %31
%43 = load i8*, i8** %4
%44 = load i8*, i8** %5
%45 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %43, i8* %44)
%46 = load i32*, i32** %7
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
store i32 0, i32* %3
br label %50
50: ; preds = %42, %27, %21, %13
%51 = load i32, i32* %3
ret i32 %51
}

LLVM IR (-O2):
@F_OK = global i32 0
@.str = [56 x i8] c"File %s already exists! Please delete it and run again\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EOF = global i8 0
@.str.3 = [33 x i8] c"%s successfully backed up to %s\0A\00"
define i32 @copy_file(i8* %0, i8* %1) {
%3 = load i32, i32* @F_OK
%4 = tail call i32 @access(i8* %1, i32 %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %30
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %30, label %11
11: ; preds = %8
%12 = tail call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %18, label %14
14: ; preds = %11
%15 = tail call signext i8 @fgetc(i32* %9)
%16 = load i8, i8* @EOF
%17 = icmp eq i8 %15, %16
br i1 %17, label %26, label %20
18: ; preds = %11
%19 = tail call i32 @fclose(i32* %9)
br label %30
20: ; preds = %14, %20
%21 = phi i8 [ %23, %20 ], [ %15, %14 ]
%22 = tail call i32 @fputc(i8 signext %21, i32* %12)
%23 = tail call signext i8 @fgetc(i32* %9)
%24 = load i8, i8* @EOF
%25 = icmp eq i8 %23, %24
br i1 %25, label %26, label %20
26: ; preds = %20, %14
%27 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %1)
%28 = tail call i32 @fclose(i32* %9)
%29 = tail call i32 @fclose(i32* %12)
br label %30
30: ; preds = %18, %26, %8, %6
%31 = phi i32 [ -1, %6 ], [ -1, %18 ], [ 0, %26 ], [ -1, %8 ]
ret i32 %31
}