#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 inName[64], outName[64];
  FILE *in, *out;
  int c;
  printf("Enter name of file to be copied: ");
  scanf("%63s", inName);
  printf("Enter name of output file: ");
  scanf("%63s", outName);
  if ((in = fopen(inName, "r")) == NULL) {
    printf("Can't open %s for reading.\n", inName);
    return 1;
  }
  if ((out = fopen(outName, "w")) == NULL) {
    printf("Can't open %s for writing.\n", outName);
    return 2;
  }
  while ((c = getc(in)) != EOF)
    putc(c, out);
  fclose(in);
  fclose(out);
  printf("File has been copied.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe97(%rip),%rdi
call   1060 <scanf@plt>
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x90(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    11f0 <main+0x90>
lea    -0x50(%rbp),%rsi
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x13f>
lea    -0x90(%rbp),%rdi
lea    0xe63(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmp    $0x0,%rax
jne    1235 <main+0xd5>
lea    -0x90(%rbp),%rsi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    129f <main+0x13f>
jmp    123a <main+0xda>
mov    -0x98(%rbp),%rdi
call   1080 <getc@plt>
mov    %eax,-0xa4(%rbp)
mov    0x2d95(%rip),%rcx
cmp    (%rcx),%eax
je     1272 <main+0x112>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
call   1050 <putc@plt>
jmp    123a <main+0xda>
mov    -0x98(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xa0(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@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
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe91(%rip),%rbx
lea    0x40(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <scanf@plt>
lea    0xe7f(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <scanf@plt>
lea    0xe82(%rip),%rsi
mov    %r14,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1237 <main+0xc7>
mov    %rax,%rbx
lea    0xe89(%rip),%rsi
mov    %rsp,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     1251 <main+0xe1>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <getc@plt>
mov    0x2df1(%rip),%r15
cmp    (%r15),%eax
je     1217 <main+0xa7>
nopl   0x0(%rax)
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>
lea    0xe51(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1267 <main+0xf7>
lea    0xe07(%rip),%rdi
lea    0x40(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    1267 <main+0xf7>
lea    0xe0b(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Enter name of file to be copied: \00"
@.str.1 = [5 x i8] c"%63s\00"
@.str.2 = [28 x i8] c"Enter name of output file: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [28 x i8] c"Can't open %s for reading.\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [28 x i8] c"Can't open %s for writing.\0A\00"
@EOF = global i32 0
@.str.7 = [23 x i8] c"File has been copied.\0A\00"
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 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 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 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 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 %19
16: ; preds = %0
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %17)
store i32 1, i32* %1
br label %42
19: ; preds = %0
%20 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %21, i32** %5
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %26
23: ; preds = %19
%24 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %24)
store i32 2, i32* %1
br label %42
26: ; preds = %19
br label %27
27: ; preds = %32, %26
%28 = load i32*, i32** %4
%29 = call i32 @getc(i32* %28)
store i32 %29, i32* %6
%30 = load i32, i32* @EOF
%31 = icmp ne i32 %29, %30
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* %6
%34 = load i32*, i32** %5
%35 = call i32 @putc(i32 %33, i32* %34)
br label %27
36: ; preds = %27
%37 = load i32*, i32** %4
%38 = call i32 @fclose(i32* %37)
%39 = load i32*, i32** %5
%40 = call i32 @fclose(i32* %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %42
42: ; preds = %36, %23, %16
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str = [34 x i8] c"Enter name of file to be copied: \00"
@.str.1 = [5 x i8] c"%63s\00"
@.str.2 = [28 x i8] c"Enter name of output file: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [28 x i8] c"Can't open %s for reading.\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [28 x i8] c"Can't open %s for writing.\0A\00"
@EOF = global i32 0
@str = [22 x i8] c"File has been copied.\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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i8* %3)
br label %32
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 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %4)
br label %32
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)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %32
32: ; preds = %28, %20, %11
%33 = phi i32 [ 1, %11 ], [ 2, %20 ], [ 0, %28 ]
ret i32 %33
}