#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__ EACCES;
char EOF;
int /*<<< orphan*/ F_OK;
int access(char const *, int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ print_log(char *);
int /*<<< orphan*/ strcat(char *, char const *);
void copy_file(const char *source_file, const char *destination_file) {
  char message[100];
  message[0] = '\0';
  print_log("copying file");
  strcat(message, "-- source: ");
  strcat(message, source_file);
  print_log(message);
  message[0] = '\0';
  strcat(message, "-- destination: ");
  strcat(message, destination_file);
  print_log(message);
  FILE *source, *destination;
  if (access(destination_file, F_OK) != -1) {
    print_log("-- file already exists");
    print_log("-- moving on...");
  } else {
    source = fopen(source_file, "r");
    if (EACCES == errno) {
      print_log("-- no permission to open source file");
      exit(1);
    } else if (source == NULL) {
      print_log("-- no such source file");
      exit(1);
    }
    destination = fopen(destination_file, "w");
    if (EACCES == errno) {
      print_log("-- no permission to open/create destination file");
      exit(1);
    } else if (destination == NULL) {
      print_log("-- couldn't open/create destination file");
      exit(1);
    } else {
      char character;
      while ((character = fgetc(source)) != EOF) {
        fputc(character, destination);
      }
      print_log("-- file copied");
    }
    fclose(source);
    fclose(destination);
  }
}


x86 assembly (clang, -O0):
<copy_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x80(%rbp)
lea    0xe62(%rip),%rdi
call   1030 <print_log@plt>
lea    -0x80(%rbp),%rdi
lea    0xe5f(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x80(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x80(%rbp),%rdi
call   1030 <print_log@plt>
movb   $0x0,-0x80(%rbp)
lea    -0x80(%rbp),%rdi
lea    0xe41(%rip),%rsi
call   1090 <strcat@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1090 <strcat@plt>
lea    -0x80(%rbp),%rdi
call   1030 <print_log@plt>
mov    -0x10(%rbp),%rdi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     122b <copy_file+0xab>
lea    0xe15(%rip),%rdi
call   1030 <print_log@plt>
lea    0xe20(%rip),%rdi
call   1030 <print_log@plt>
jmp    1375 <copy_file+0x1f5>
mov    -0x8(%rbp),%rdi
lea    0xe1b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x88(%rbp)
mov    0x2d97(%rip),%rax
mov    (%rax),%rax
mov    0x2d7d(%rip),%rcx
cmp    (%rcx),%rax
jne    1272 <copy_file+0xf2>
lea    0xdf0(%rip),%rdi
call   1030 <print_log@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x88(%rbp)
jne    1296 <copy_file+0x116>
lea    0xdf1(%rip),%rdi
call   1030 <print_log@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    129b <copy_file+0x11b>
mov    -0x10(%rbp),%rdi
lea    0xde9(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x90(%rbp)
mov    0x2d27(%rip),%rax
mov    (%rax),%rax
mov    0x2d0d(%rip),%rcx
cmp    (%rcx),%rax
jne    12e2 <copy_file+0x162>
lea    0xdbe(%rip),%rdi
call   1030 <print_log@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x90(%rbp)
jne    1306 <copy_file+0x186>
lea    0xdcb(%rip),%rdi
call   1030 <print_log@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    130b <copy_file+0x18b>
mov    -0x88(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,-0x91(%rbp)
movsbl %al,%eax
mov    0x2cc1(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     134c <copy_file+0x1cc>
mov    -0x91(%rbp),%al
mov    -0x90(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
jmp    130b <copy_file+0x18b>
lea    0xd98(%rip),%rdi
call   1030 <print_log@plt>
jmp    135d <copy_file+0x1dd>
mov    -0x88(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x90(%rbp),%rdi
call   1040 <fclose@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copy_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
movb   $0x0,(%rsp)
lea    0xe62(%rip),%rdi
call   1030 <print_log@plt>
lea    0xe63(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1030 <print_log@plt>
movb   $0x0,(%rsp)
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1090 <strcat@plt>
mov    %rbx,%rdi
call   1030 <print_log@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1070 <access@plt>
cmp    $0xffffffff,%eax
je     1221 <copy_file+0xa1>
lea    0xe1f(%rip),%rdi
call   1030 <print_log@plt>
lea    0xe2a(%rip),%rdi
call   1030 <print_log@plt>
jmp    12c4 <copy_file+0x144>
lea    0xe29(%rip),%rsi
mov    %r15,%rdi
call   1080 <fopen@plt>
mov    %rax,%r15
mov    0x2da6(%rip),%r12
mov    (%r12),%rax
mov    0x2d8b(%rip),%r13
cmp    0x0(%r13),%rax
je     12d2 <copy_file+0x152>
test   %r15,%r15
je     12db <copy_file+0x15b>
lea    0xe30(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     12e4 <copy_file+0x164>
test   %rbx,%rbx
je     12ed <copy_file+0x16d>
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    0x2d60(%rip),%r14
cmp    (%r14),%al
je     12a8 <copy_file+0x128>
nopl   (%rax)
movsbl %al,%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r15,%rdi
call   1050 <fgetc@plt>
cmp    (%r14),%al
jne    1290 <copy_file+0x110>
lea    0xe3c(%rip),%rdi
call   1030 <print_log@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x70,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xd7a(%rip),%rdi
jmp    12f4 <copy_file+0x174>
lea    0xd96(%rip),%rdi
jmp    12f4 <copy_file+0x174>
lea    0xda6(%rip),%rdi
jmp    12f4 <copy_file+0x174>
lea    0xdce(%rip),%rdi
call   1030 <print_log@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"copying file\00"
@.str.1 = [12 x i8] c"-- source: \00"
@.str.2 = [17 x i8] c"-- destination: \00"
@F_OK = global i32 0
@.str.3 = [23 x i8] c"-- file already exists\00"
@.str.4 = [16 x i8] c"-- moving on...\00"
@.str.5 = [2 x i8] c"r\00"
@EACCES = global i64 0
@errno = global i64 0
@.str.6 = [37 x i8] c"-- no permission to open source file\00"
@.str.7 = [23 x i8] c"-- no such source file\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [49 x i8] c"-- no permission to open/create destination file\00"
@.str.10 = [41 x i8] c"-- couldn't open/create destination file\00"
@EOF = global i8 0
@.str.11 = [15 x i8] c"-- file copied\00"
define void @copy_file(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [100 x i8]
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 0, i8* %9
%10 = call i32 @print_log(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%12 = call i32 @strcat(i8* %11, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 @strcat(i8* %13, i8* %14)
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%17 = call i32 @print_log(i8* %16)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
store i8 0, i8* %18
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%20 = call i32 @strcat(i8* %19, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%22 = load i8*, i8** %4
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%25 = call i32 @print_log(i8* %24)
%26 = load i8*, i8** %4
%27 = load i32, i32* @F_OK
%28 = call i32 @access(i8* %26, i32 %27)
%29 = icmp ne i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %2
%31 = call i32 @print_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @print_log(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %84
33: ; preds = %2
%34 = load i8*, i8** %3
%35 = call i32* @fopen(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %35, i32** %6
%36 = load i64, i64* @EACCES
%37 = load i64, i64* @errno
%38 = icmp eq i64 %36, %37
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @print_log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %33
%43 = load i32*, i32** %6
%44 = icmp eq i32* %43, null
br i1 %44, label %45, label %48
45: ; preds = %42
%46 = call i32 @print_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %42
br label %49
49: ; preds = %48
%50 = load i8*, i8** %4
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
store i32* %51, i32** %7
%52 = load i64, i64* @EACCES
%53 = load i64, i64* @errno
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %49
%56 = call i32 @print_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %49
%59 = load i32*, i32** %7
%60 = icmp eq i32* %59, null
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i32 @print_log(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %58
br label %65
65: ; preds = %72, %64
%66 = load i32*, i32** %6
%67 = call signext i8 @fgetc(i32* %66)
store i8 %67, i8* %8
%68 = sext i8 %67 to i32
%69 = load i8, i8* @EOF
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %68, %70
br i1 %71, label %72, label %76
72: ; preds = %65
%73 = load i8, i8* %8
%74 = load i32*, i32** %7
%75 = call i32 @fputc(i8 signext %73, i32* %74)
br label %65
76: ; preds = %65
%77 = call i32 @print_log(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %78
78: ; preds = %76
br label %79
79: ; preds = %78
%80 = load i32*, i32** %6
%81 = call i32 @fclose(i32* %80)
%82 = load i32*, i32** %7
%83 = call i32 @fclose(i32* %82)
br label %84
84: ; preds = %79, %30
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"copying file\00"
@.str.1 = [12 x i8] c"-- source: \00"
@.str.2 = [17 x i8] c"-- destination: \00"
@F_OK = global i32 0
@.str.3 = [23 x i8] c"-- file already exists\00"
@.str.4 = [16 x i8] c"-- moving on...\00"
@.str.5 = [2 x i8] c"r\00"
@EACCES = global i64 0
@errno = global i64 0
@.str.6 = [37 x i8] c"-- no permission to open source file\00"
@.str.7 = [23 x i8] c"-- no such source file\00"
@.str.8 = [2 x i8] c"w\00"
@.str.9 = [49 x i8] c"-- no permission to open/create destination file\00"
@.str.10 = [41 x i8] c"-- couldn't open/create destination file\00"
@EOF = global i8 0
@.str.11 = [15 x i8] c"-- file copied\00"
define void @copy_file(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
store i8 0, i8* %4
%5 = tail call i32 @print_log(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @strcat(i8* %4, i8* %0)
%8 = call i32 @print_log(i8* %4)
store i8 0, i8* %4
%9 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%10 = call i32 @strcat(i8* %4, i8* %1)
%11 = call i32 @print_log(i8* %4)
%12 = load i32, i32* @F_OK
%13 = call i32 @access(i8* %1, i32 %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = call i32 @print_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @print_log(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %58
18: ; preds = %2
%19 = call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%20 = load i64, i64* @EACCES
%21 = load i64, i64* @errno
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @print_log(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = icmp eq i32* %19, null
br i1 %27, label %28, label %31
28: ; preds = %26
%29 = call i32 @print_log(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %26
%32 = call i32* @fopen(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%33 = load i64, i64* @EACCES
%34 = load i64, i64* @errno
%35 = icmp eq i64 %33, %34
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = call i32 @print_log(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0))
%38 = call i32 @exit(i32 1)
unreachable
39: ; preds = %31
%40 = icmp eq i32* %32, null
br i1 %40, label %45, label %41
41: ; preds = %39
%42 = call signext i8 @fgetc(i32* %19)
%43 = load i8, i8* @EOF
%44 = icmp eq i8 %42, %43
br i1 %44, label %54, label %48
45: ; preds = %39
%46 = call i32 @print_log(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %41, %48
%49 = phi i8 [ %51, %48 ], [ %42, %41 ]
%50 = call i32 @fputc(i8 signext %49, i32* %32)
%51 = call signext i8 @fgetc(i32* %19)
%52 = load i8, i8* @EOF
%53 = icmp eq i8 %51, %52
br i1 %53, label %54, label %48
54: ; preds = %48, %41
%55 = call i32 @print_log(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
%56 = call i32 @fclose(i32* %19)
%57 = call i32 @fclose(i32* %32)
br label %58
58: ; preds = %54, %15
ret void
}