#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ putc(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
main() {
  char in_name[25], out_name[25];
  FILE *in_file, *out_file, *fopen();
  int c;
  printf("File to be copied:\n");
  scanf("%24s", in_name);
  printf("Output filename:\n");
  scanf("%24s", out_name);
  in_file = fopen(in_name, "r");
  if (in_file == NULL)
    printf("Cannot open %s for reading.\n", in_name);
  else {
    out_file = fopen(out_name, "w");
    if (out_file == NULL)
      printf("Can't open %s for writing.\n", out_name);
    else {
      while (!feof(in_file)) {
        c = getc(in_file);
        putc(c, out_file);
      }
      printf("File has been copied.\n");
      fclose(out_file);
    }
    fclose(in_file);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x20(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe75(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe5e(%rip),%rdi
call   1070 <scanf@plt>
lea    -0x20(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11f1 <main+0x81>
lea    -0x20(%rbp),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1287 <main+0x117>
lea    -0x40(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    1227 <main+0xb7>
lea    -0x40(%rbp),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    127e <main+0x10e>
jmp    122c <main+0xbc>
mov    -0x48(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    124a <main+0xda>
jmp    1267 <main+0xf7>
mov    -0x48(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
call   1050 <putc@plt>
jmp    122c <main+0xbc>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0xeb4(%rip),%rdi
call   1030 <puts@plt>
lea    0xe66(%rip),%rbx
lea    0x20(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xea4(%rip),%rdi
call   1030 <puts@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1080 <scanf@plt>
lea    0xe3d(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1226 <main+0xa6>
mov    %rax,%rbx
lea    0xe45(%rip),%rsi
mov    %rsp,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     123b <main+0xbb>
mov    %rax,%r14
nop
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    1210 <main+0x90>
mov    %rbx,%rdi
call   10a0 <getc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1060 <putc@plt>
jmp    11f0 <main+0x70>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
jmp    124c <main+0xcc>
lea    0xdda(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1254 <main+0xd4>
lea    0xde4(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"File to be copied:\0A\00"
@.str.1 = [5 x i8] c"%24s\00"
@.str.2 = [18 x i8] c"Output filename:\0A\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [29 x i8] c"Cannot 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"
@.str.7 = [23 x i8] c"File has been copied.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [25 x i8]
%3 = alloca [25 x i8]
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [25 x i8], [25 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 ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [25 x i8], [25 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 [25 x i8], [25 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 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %18)
br label %47
20: ; preds = %0
%21 = getelementptr inbounds [25 x i8], [25 x i8]* %3, 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** %5
%23 = load i32*, i32** %5
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = getelementptr inbounds [25 x i8], [25 x i8]* %3, i64 0, i64 0
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %26)
br label %44
28: ; preds = %20
br label %29
29: ; preds = %34, %28
%30 = load i32*, i32** %4
%31 = call i32 @feof(i32* %30)
%32 = icmp ne i32 %31, 0
%33 = xor i1 %32, true
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i32*, i32** %4
%36 = call i32 @getc(i32* %35)
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = load i32*, i32** %5
%39 = call i32 @putc(i32 %37, i32* %38)
br label %29
40: ; preds = %29
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0))
%42 = load i32*, i32** %5
%43 = call i32 @fclose(i32* %42)
br label %44
44: ; preds = %40, %25
%45 = load i32*, i32** %4
%46 = call i32 @fclose(i32* %45)
br label %47
47: ; preds = %44, %17
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"%24s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [29 x i8] c"Cannot 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"
@str = [19 x i8] c"File to be copied:\00"
@str.8 = [17 x i8] c"Output filename:\00"
@str.9 = [22 x i8] c"File has been copied.\00"
define i32 @main() {
%1 = alloca [25 x i8]
%2 = alloca [25 x i8]
%3 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [25 x i8], [25 x i8]* %2, i64 0, i64 0
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 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 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, 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 ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* %3)
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 %19, label %16
16: ; preds = %13
%17 = call i32 @feof(i32* %9)
%18 = icmp eq i32 %17, 0
br i1 %18, label %21, label %26
19: ; preds = %13
%20 = 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 %29
21: ; preds = %16, %21
%22 = call i32 @getc(i32* %9)
%23 = call i32 @putc(i32 %22, i32* %14)
%24 = call i32 @feof(i32* %9)
%25 = icmp eq i32 %24, 0
br i1 %25, label %21, label %26
26: ; preds = %21, %16
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.9, i64 0, i64 0))
%28 = call i32 @fclose(i32* %14)
br label %29
29: ; preds = %26, %19
%30 = call i32 @fclose(i32* %9)
br label %31
31: ; preds = %29, %11
ret i32 0
}