#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
char getchar();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  FILE *copyfrom;
  FILE *copyto;
  char fname1[100];
  char fname2[100];
  int length;
  char temp;
  printf("\n\n\n\n\n\nThis program will copy your text file to another "
         "file\nPress ENTER to continue or 'q' to quit:\n");
  if (getchar() == 'q') {
    printf("\n\n\n\n\n\n\n\n\nGoodbye\n\n\n\n\n\n\n\n");
    exit(2);
  }
  printf("Enter Name of file you would like to copy from:\n");
  fgets(fname1, 100, stdin);
  length = strlen(fname1);
  fname1[length - 1] = '\0';
  copyfrom = fopen(fname1, "r");
  if (copyfrom == NULL) {
    printf("Error Opening the file you would like to copy from\n");
    exit(0);
  }
  printf("\nEnter Name of file you would like to copy to:\n!!!CAUTION: "
         "CONTENTS OF FILE WILL BE OVERWRITTEN!!!\n");
  fgets(fname2, 100, stdin);
  length = strlen(fname2);
  fname2[length - 1] = '\0';
  copyto = fopen(fname2, "w");
  if (copyto == NULL) {
    printf("Error Opening the file you would like to copy to\n");
    exit(0);
  }
  while ((temp = getc(copyfrom)) != EOF) {
    putc(temp, copyto);
  }
  fclose(copyfrom);
  fclose(copyto);
  printf("\n\n\n\n\n\n\n\n\n\n\nCopy Completed\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1080 <getchar@plt>
movsbl %al,%eax
cmp    $0x71,%eax
jne    11d7 <main+0x47>
lea    0xe9d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xea0(%rip),%rdi
call   1050 <printf@plt>
lea    -0x80(%rbp),%rdi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0x80(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    124b <main+0xbb>
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
lea    -0xf0(%rbp),%rdi
mov    0x2d83(%rip),%rax
mov    (%rax),%edx
mov    $0x64,%esi
call   1060 <fgets@plt>
lea    -0xf0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0xf4(%rbp)
mov    -0xf4(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0xf0(%rbp,%rax,1)
lea    -0xf0(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    12cb <main+0x13b>
lea    0xe8c(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    12d0 <main+0x140>
mov    -0x10(%rbp),%rdi
call   10b0 <getc@plt>
mov    %al,-0xf5(%rbp)
movsbl %al,%eax
mov    0x2cf7(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     130b <main+0x17b>
mov    -0xf5(%rbp),%al
mov    -0x18(%rbp),%rsi
movsbl %al,%edi
call   1070 <putc@plt>
jmp    12d0 <main+0x140>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe59(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x100,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xe0,%rsp
lea    0xe61(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
cmp    $0x71,%al
je     12b3 <main+0x123>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e1e(%rip),%r15
mov    (%r15),%edx
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xe0b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12c9 <main+0x139>
mov    %rax,%r14
lea    0xe88(%rip),%rdi
call   1030 <puts@plt>
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
lea    0xdc4(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     12d2 <main+0x142>
mov    %rax,%rbx
mov    %r14,%rdi
call   10b0 <getc@plt>
mov    0x2d7f(%rip),%r15
cmp    (%r15),%al
je     1288 <main+0xf8>
cs nopw 0x0(%rax,%rax,1)
movsbl %al,%edi
mov    %rbx,%rsi
call   1070 <putc@plt>
mov    %r14,%rdi
call   10b0 <getc@plt>
cmp    (%r15),%al
jne    1270 <main+0xe0>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xe5c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xebf(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
lea    0xe76(%rip),%rdi
jmp    12d9 <main+0x149>
lea    0xe3c(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [101 x i8] c"\0A\0A\0A\0A\0A\0AThis program will copy your text file to another file\0APress ENTER to continue or 'q' to quit:\0A\00"
@.str.1 = [25 x i8] c"\0A\0A\0A\0A\0A\0A\0A\0A\0AGoodbye\0A\0A\0A\0A\0A\0A\0A\0A\00"
@.str.2 = [49 x i8] c"Enter Name of file you would like to copy from:\0A\00"
@stdin = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [52 x i8] c"Error Opening the file you would like to copy from\0A\00"
@.str.5 = [100 x i8] c"\0AEnter Name of file you would like to copy to:\0A!!!CAUTION: CONTENTS OF FILE WILL BE OVERWRITTEN!!!\0A\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [50 x i8] c"Error Opening the file you would like to copy to\0A\00"
@EOF = global i8 0
@.str.8 = [27 x i8] c"\0A\0A\0A\0A\0A\0A\0A\0A\0A\0A\0ACopy Completed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca [100 x i8]
%6 = alloca i32
%7 = alloca i8
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str, i64 0, i64 0))
%9 = call signext i8 (...) @getchar()
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 113
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %0
%16 = call i32 @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i32 @fgets(i8* %17, i32 100, i32 %18)
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%21 = call i32 @strlen(i8* %20)
store i32 %21, i32* %6
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %24
store i8 0, i8* %25
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %27, i32** %2
%28 = load i32*, i32** %2
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %15
%31 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %15
%34 = call i32 @printf(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.5, i64 0, i64 0))
%35 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%36 = load i32, i32* @stdin
%37 = call i32 @fgets(i8* %35, i32 100, i32 %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = sub nsw i32 %40, 1
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %42
store i8 0, i8* %43
%44 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%45 = call i32* @fopen(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %45, i32** %3
%46 = load i32*, i32** %3
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %51
48: ; preds = %33
%49 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
51: ; preds = %33
br label %52
52: ; preds = %59, %51
%53 = load i32*, i32** %2
%54 = call signext i8 @getc(i32* %53)
store i8 %54, i8* %7
%55 = sext i8 %54 to i32
%56 = load i8, i8* @EOF
%57 = sext i8 %56 to i32
%58 = icmp ne i32 %55, %57
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = load i8, i8* %7
%61 = load i32*, i32** %3
%62 = call i32 @putc(i8 signext %60, i32* %61)
br label %52
63: ; preds = %52
%64 = load i32*, i32** %2
%65 = call i32 @fclose(i32* %64)
%66 = load i32*, i32** %3
%67 = call i32 @fclose(i32* %66)
%68 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str.3 = [2 x i8] c"r\00"
@.str.6 = [2 x i8] c"w\00"
@EOF = global i8 0
@str = [100 x i8] c"\0A\0A\0A\0A\0A\0AThis program will copy your text file to another file\0APress ENTER to continue or 'q' to quit:\00"
@str.9 = [48 x i8] c"Enter Name of file you would like to copy from:\00"
@str.10 = [99 x i8] c"\0AEnter Name of file you would like to copy to:\0A!!!CAUTION: CONTENTS OF FILE WILL BE OVERWRITTEN!!!\00"
@str.11 = [26 x i8] c"\0A\0A\0A\0A\0A\0A\0A\0A\0A\0A\0ACopy Completed\00"
@str.12 = [49 x i8] c"Error Opening the file you would like to copy to\00"
@str.13 = [51 x i8] c"Error Opening the file you would like to copy from\00"
@str.14 = [24 x i8] c"\0A\0A\0A\0A\0A\0A\0A\0A\0AGoodbye\0A\0A\0A\0A\0A\0A\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([100 x i8], [100 x i8]* @str, i64 0, i64 0))
%6 = tail call signext i8 (...) @getchar()
%7 = icmp eq i8 %6, 113
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.14, i64 0, i64 0))
%10 = tail call i32 @exit(i32 2)
unreachable
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.9, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fgets(i8* %3, i32 100, i32 %13)
%15 = call i32 @strlen(i8* %3)
%16 = add nsw i32 %15, -1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 %17
store i8 0, i8* %18
%19 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %11
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str.13, i64 0, i64 0))
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %11
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([99 x i8], [99 x i8]* @str.10, i64 0, i64 0))
%26 = load i32, i32* @stdin
%27 = call i32 @fgets(i8* %4, i32 100, i32 %26)
%28 = call i32 @strlen(i8* %4)
%29 = add nsw i32 %28, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %30
store i8 0, i8* %31
%32 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%33 = icmp eq i32* %32, null
br i1 %33, label %38, label %34
34: ; preds = %24
%35 = call signext i8 @getc(i32* %19)
%36 = load i8, i8* @EOF
%37 = icmp eq i8 %35, %36
br i1 %37, label %47, label %41
38: ; preds = %24
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.12, i64 0, i64 0))
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %34, %41
%42 = phi i8 [ %44, %41 ], [ %35, %34 ]
%43 = call i32 @putc(i8 signext %42, i32* %32)
%44 = call signext i8 @getc(i32* %19)
%45 = load i8, i8* @EOF
%46 = icmp eq i8 %44, %45
br i1 %46, label %47, label %41
47: ; preds = %41, %34
%48 = call i32 @fclose(i32* %19)
%49 = call i32 @fclose(i32* %32)
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.11, i64 0, i64 0))
ret i32 0
}