#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *inFile, *outFile;
  char infilename[40];
  char outfilename[40];
  int c;
  printf("Please enter an input file name -- ");
  scanf("%s", infilename);
  printf("Please enter an output file name -- ");
  scanf("%s", outfilename);
  inFile = fopen(infilename, "r");
  if (inFile == NULL) {
    printf("Cannot open input file - exiting!\n");
    exit(1);
  }
  if ((outFile = fopen(outfilename, "w")) == NULL) {
    printf("Cannot open output file - exiting!\n");
    exit(1);
  }
  while ((c = fgetc(inFile)) != EOF)
    fputc(c, outFile);
  fclose(inFile);
  fclose(outFile);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe82(%rip),%rdi
call   1040 <printf@plt>
lea    -0x70(%rbp),%rsi
lea    0xe6f(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ef <main+0x7f>
lea    0xe6e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    -0x70(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1223 <main+0xb3>
lea    0xe5f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1228 <main+0xb8>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x74(%rbp)
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%eax
je     1254 <main+0xe4>
mov    -0x74(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
jmp    1228 <main+0xb8>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
lea    0xe70(%rip),%rdi
call   1050 <printf@plt>
lea    0xe88(%rip),%rbx
lea    0x30(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe74(%rip),%rdi
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1243 <main+0xc3>
mov    %rax,%r14
lea    0xe6d(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     124c <main+0xcc>
mov    %rax,%rbx
mov    %r14,%rdi
call   1060 <fgetc@plt>
mov    0x2de8(%rip),%r15
cmp    (%r15),%eax
je     1227 <main+0xa7>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r14,%rdi
call   1060 <fgetc@plt>
cmp    (%r15),%eax
jne    1210 <main+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe29(%rip),%rdi
jmp    1253 <main+0xd3>
lea    0xdfd(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [36 x i8] c"Please enter an input file name -- \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [37 x i8] c"Please enter an output file name -- \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [35 x i8] c"Cannot open input file - exiting!\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [36 x i8] c"Cannot open output file - exiting!\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [40 x i8]
%5 = alloca [40 x i8]
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = call i32 @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %4, 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** %2
%15 = load i32*, i32** %2
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = getelementptr inbounds [40 x i8], [40 x i8]* %5, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %22, i32** %3
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %20
br label %28
28: ; preds = %33, %27
%29 = load i32*, i32** %2
%30 = call i32 @fgetc(i32* %29)
store i32 %30, i32* %6
%31 = load i32, i32* @EOF
%32 = icmp ne i32 %30, %31
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* %6
%35 = load i32*, i32** %3
%36 = call i32 @fputc(i32 %34, i32* %35)
br label %28
37: ; preds = %28
%38 = load i32*, i32** %2
%39 = call i32 @fclose(i32* %38)
%40 = load i32*, i32** %3
%41 = call i32 @fclose(i32* %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [36 x i8] c"Please enter an input file name -- \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [37 x i8] c"Please enter an output file name -- \00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [35 x i8] c"Cannot open output file - exiting!\00"
@str.7 = [34 x i8] c"Cannot open input file - exiting!\00"
define i32 @main() {
%1 = alloca [40 x i8]
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 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 %14
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %0
%15 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %21, label %17
17: ; preds = %14
%18 = call i32 @fgetc(i32* %9)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %30, label %24
21: ; preds = %14
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %17, %24
%25 = phi i32 [ %27, %24 ], [ %18, %17 ]
%26 = call i32 @fputc(i32 %25, i32* %15)
%27 = call i32 @fgetc(i32* %9)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %30, label %24
30: ; preds = %24, %17
%31 = call i32 @fclose(i32* %9)
%32 = call i32 @fclose(i32* %15)
ret i32 0
}