#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*/ printf(char *);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  char in[64], out[64];
  FILE *inFile, *outFile;
  printf("Original file name: ");
  scanf("%63s", in);
  printf("Copy name: ");
  scanf("%63s", out);
  if ((inFile = fopen(in, "r")) == NULL) {
    printf("Error when opening file to read.\n");
    return 1;
  }
  if ((outFile = fopen(out, "w")) == NULL) {
    printf("Error when opening file to write.\n");
    return 2;
  }
  int c;
  while ((c = getc(inFile)) != EOF)
    putc(c, outFile);
  fclose(inFile);
  fclose(outFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe8c(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe85(%rip),%rdi
call   1040 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe6e(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11e6 <main+0x86>
lea    0xe53(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    127e <main+0x11e>
lea    -0x90(%rbp),%rdi
lea    0xe56(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
jne    1222 <main+0xc2>
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    127e <main+0x11e>
jmp    1227 <main+0xc7>
mov    -0x98(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0xa4(%rbp)
mov    0x2da8(%rip),%rcx
cmp    (%rcx),%eax
je     125f <main+0xff>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
call   1050 <putc@plt>
jmp    1227 <main+0xc7>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xa0(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0xe7d(%rip),%rdi
call   1050 <printf@plt>
lea    0xe86(%rip),%rbx
lea    0x40(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe69(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     122b <main+0xbb>
mov    %rax,%rbx
lea    0xe54(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     123e <main+0xce>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    0x2df5(%rip),%r15
cmp    (%r15),%eax
je     1217 <main+0xa7>
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <putc@plt>
mov    %rbx,%rdi
call   1090 <getc@plt>
cmp    (%r15),%eax
jne    1200 <main+0x90>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    124f <main+0xdf>
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%eax
jmp    124f <main+0xdf>
lea    0xde5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [21 x i8] c"Original file name: \00"
@.str.1 = [5 x i8] c"%63s\00"
@.str.2 = [12 x i8] c"Copy name: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [34 x i8] c"Error when opening file to read.\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [35 x i8] c"Error when opening file to write.\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [64 x i8]
%3 = alloca [64 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %14, i32** %4
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %18
16: ; preds = %0
%17 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %39
18: ; preds = %0
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %20, i32** %5
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
store i32 2, i32* %1
br label %39
24: ; preds = %18
br label %25
25: ; preds = %30, %24
%26 = load i32*, i32** %4
%27 = call i32 @getc(i32* %26)
store i32 %27, i32* %6
%28 = load i32, i32* @EOF
%29 = icmp ne i32 %27, %28
br i1 %29, label %30, label %34
30: ; preds = %25
%31 = load i32, i32* %6
%32 = load i32*, i32** %5
%33 = call i32 @putc(i32 %31, i32* %32)
br label %25
34: ; preds = %25
%35 = load i32*, i32** %4
%36 = call i32 @fclose(i32* %35)
%37 = load i32*, i32** %5
%38 = call i32 @fclose(i32* %37)
store i32 0, i32* %1
br label %39
39: ; preds = %34, %22, %16
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
@.str = [21 x i8] c"Original file name: \00"
@.str.1 = [5 x i8] c"%63s\00"
@.str.2 = [12 x i8] c"Copy name: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [34 x i8] c"Error when opening file to write.\00"
@str.7 = [33 x i8] c"Error when opening file to read.\00"
define i32 @main() {
%1 = alloca [64 x i8]
%2 = alloca [64 x i8]
%3 = getelementptr inbounds [64 x i8], [64 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%9 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
br label %31
13: ; preds = %0
%14 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = call i32 @getc(i32* %9)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %28, label %22
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %31
22: ; preds = %16, %22
%23 = phi i32 [ %25, %22 ], [ %17, %16 ]
%24 = call i32 @putc(i32 %23, i32* %14)
%25 = call i32 @getc(i32* %9)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %22
28: ; preds = %22, %16
%29 = call i32 @fclose(i32* %9)
%30 = call i32 @fclose(i32* %14)
br label %31
31: ; preds = %28, %20, %11
%32 = phi i32 [ 1, %11 ], [ 2, %20 ], [ 0, %28 ]
ret i32 %32
}