#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 /*<<< orphan*/ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  FILE *in, *out;
  char name[25];
  printf("Enter the input file name: ");
  scanf("%s", name);
  in = fopen(name, "rt");
  if (in == NULL) {
    printf("Failed to open the input file.");
    return 1;
  }
  printf("Enter the output file name: ");
  scanf("%s", name);
  out = fopen(name, "wt");
  if (out == NULL) {
    printf("Failed to open the output file.");
    return 1;
  }
  while (!feof(in)) {
    fputc(fgetc(in), out);
  }
  fclose(in);
  fclose(out);
  printf("File copied.\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe86(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d2 <main+0x62>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x116>
lea    0xe68(%rip),%rdi
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe33(%rip),%rdi
call   1080 <scanf@plt>
lea    -0x40(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1225 <main+0xb5>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1286 <main+0x116>
jmp    122a <main+0xba>
mov    -0x10(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1248 <main+0xd8>
jmp    1261 <main+0xf1>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
jmp    122a <main+0xba>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe07(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xe72(%rip),%rdi
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
lea    0xe73(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1240 <main+0xc0>
mov    %rax,%rbx
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe49(%rip),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   1090 <scanf@plt>
lea    0xe79(%rip),%rsi
mov    %r14,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1249 <main+0xc9>
mov    %rax,%r14
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %eax,%eax
jne    1220 <main+0xa0>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1070 <fputc@plt>
jmp    1200 <main+0x80>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    125a <main+0xda>
lea    0xddb(%rip),%rdi
jmp    1250 <main+0xd0>
lea    0xe11(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Enter the input file name: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rt\00"
@.str.3 = [31 x i8] c"Failed to open the input file.\00"
@.str.4 = [29 x i8] c"Enter the output file name: \00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [32 x i8] c"Failed to open the output file.\00"
@.str.7 = [14 x i8] c"File copied.\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [25 x i8]
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %2
%10 = load i32*, i32** %2
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %1
br label %41
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%16 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = getelementptr inbounds [25 x i8], [25 x i8]* %4, i64 0, i64 0
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
store i32* %19, i32** %3
%20 = load i32*, i32** %3
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %14
%23 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %1
br label %41
24: ; preds = %14
br label %25
25: ; preds = %30, %24
%26 = load i32*, i32** %2
%27 = call i32 @feof(i32* %26)
%28 = icmp ne i32 %27, 0
%29 = xor i1 %28, true
br i1 %29, label %30, label %35
30: ; preds = %25
%31 = load i32*, i32** %2
%32 = call i32 @fgetc(i32* %31)
%33 = load i32*, i32** %3
%34 = call i32 @fputc(i32 %32, i32* %33)
br label %25
35: ; preds = %25
%36 = load i32*, i32** %2
%37 = call i32 @fclose(i32* %36)
%38 = load i32*, i32** %3
%39 = call i32 @fclose(i32* %38)
%40 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %1
br label %41
41: ; preds = %35, %22, %12
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [28 x i8] c"Enter the input file name: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [3 x i8] c"rt\00"
@.str.3 = [31 x i8] c"Failed to open the input file.\00"
@.str.4 = [29 x i8] c"Enter the output file name: \00"
@.str.5 = [3 x i8] c"wt\00"
@.str.6 = [32 x i8] c"Failed to open the output file.\00"
@str = [13 x i8] c"File copied.\00"
define i32 @main() {
%1 = alloca [25 x i8]
%2 = getelementptr inbounds [25 x i8], [25 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %28
9: ; preds = %0
%10 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%12 = call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%13 = icmp eq i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %9
%15 = call i32 @feof(i32* %5)
%16 = icmp eq i32 %15, 0
br i1 %16, label %19, label %24
17: ; preds = %9
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %28
19: ; preds = %14, %19
%20 = call i32 @fgetc(i32* %5)
%21 = call i32 @fputc(i32 %20, i32* %12)
%22 = call i32 @feof(i32* %5)
%23 = icmp eq i32 %22, 0
br i1 %23, label %19, label %24
24: ; preds = %19, %14
%25 = call i32 @fclose(i32* %5)
%26 = call i32 @fclose(i32* %12)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %28
28: ; preds = %24, %17, %7
%29 = phi i32 [ 1, %7 ], [ 1, %17 ], [ 0, %24 ]
ret i32 %29
}