#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int main() {
  char ch;
  char source_file[255] =
      "/Users/timothybarnard/Documents/SystemSoftware/Assignment1/tim.txt";
  char target_file[255] = "/Users/timothybarnard/Documents/SystemSoftware/"
                          "Assignment1/folder/tim.txt";
  FILE *source, *target;
  printf("Enter name of file to copy\n");
  source = fopen(source_file, "r");
  if (source == NULL) {
    printf("Press any key to exit...\n");
    exit(EXIT_FAILURE);
  }
  target = fopen(target_file, "w");
  if (target == NULL) {
    fclose(source);
    printf("Press any key to exit...\n");
    exit(EXIT_FAILURE);
  }
  printf("File copied successfully.\n");
  fclose(source);
  fclose(target);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xe90(%rip),%rsi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    -0x210(%rbp),%rdi
lea    0xf78(%rip),%rsi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0x1066(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rdi
lea    0x106f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
jne    11e0 <main+0x90>
lea    0x1050(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    -0x210(%rbp),%rdi
lea    0x1049(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x220(%rbp)
cmpq   $0x0,-0x220(%rbp)
jne    122e <main+0xde>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
lea    0x1002(%rip),%rdi
call   1040 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0x1004(%rip),%rdi
call   1040 <printf@plt>
mov    -0x218(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x220(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x208,%rsp
lea    0xe9f(%rip),%rsi
lea    0x100(%rsp),%rbx
mov    $0xff,%edx
mov    %rbx,%rdi
call   1050 <memcpy@plt>
lea    0xf83(%rip),%rsi
mov    %rsp,%rdi
mov    $0xff,%edx
call   1050 <memcpy@plt>
lea    0x1072(%rip),%rdi
call   1030 <puts@plt>
lea    0x1062(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11f5 <main+0xa5>
mov    %rax,%r14
lea    0x104d(%rip),%rsi
mov    %rsp,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ed <main+0x9d>
mov    %rax,%rbx
lea    0x1053(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0x103c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@__const.main.source_file = [255 x i8] c"/Users/timothybarnard/Documents/SystemSoftware/Assignment1/tim.txt\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.target_file = [255 x i8] c"/Users/timothybarnard/Documents/SystemSoftware/Assignment1/folder/tim.txt\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str = [28 x i8] c"Enter name of file to copy\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Press any key to exit...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [27 x i8] c"File copied successfully.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca [255 x i8]
%4 = alloca [255 x i8]
%5 = alloca i32*
%6 = alloca i32*
store i32 0, i32* %1
%7 = bitcast [255 x i8]* %3 to i8*
%8 = bitcast [255 x i8]* %4 to i8*
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %5
%12 = load i32*, i32** %5
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = getelementptr inbounds [255 x i8], [255 x i8]* %4, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %20, i32** %6
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %18
%30 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%31 = load i32*, i32** %5
%32 = call i32 @fclose(i32* %31)
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
ret i32 0
}

LLVM IR (-O2):
@__const.main.source_file = [255 x i8] c"/Users/timothybarnard/Documents/SystemSoftware/Assignment1/tim.txt\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.target_file = [255 x i8] c"/Users/timothybarnard/Documents/SystemSoftware/Assignment1/folder/tim.txt\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@.str.1 = [2 x i8] c"r\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [2 x i8] c"w\00"
@str = [27 x i8] c"Enter name of file to copy\00"
@str.5 = [26 x i8] c"File copied successfully.\00"
@str.7 = [25 x i8] c"Press any key to exit...\00"
define i32 @main() {
%1 = alloca [255 x i8]
%2 = alloca [255 x i8]
%3 = getelementptr inbounds [255 x i8], [255 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str, i64 0, i64 0))
%6 = call i32* @fopen(i8* %3, 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 %8, label %12
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = tail call i32 @fclose(i32* %6)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.7, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %12
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.5, i64 0, i64 0))
%22 = tail call i32 @fclose(i32* %6)
%23 = tail call i32 @fclose(i32* %13)
ret i32 0
}