#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 FILENAME_MAX;
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(void) {
  int ch;
  FILE *sfp;
  FILE *dfp;
  char sname[FILENAME_MAX];
  char dname[FILENAME_MAX];
  printf("Source file: ");
  scanf("%s", sname);
  printf("Destination file: ");
  scanf("%s", dname);
  if ((sfp = fopen(sname, "r")) == NULL)
    printf("\a Failed to open the source file.\n");
  else {
    if ((dfp = fopen(dname, "w")) == NULL)
      printf("\a Failed to open the destination file.\n");
    else {
      while ((ch = fgetc(sfp)) != EOF)
        fputc(ch, dfp);
      fclose(dfp);
    }
    fclose(sfp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x38(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe3e(%rip),%rdi
call   1070 <scanf@plt>
lea    0xe35(%rip),%rdi
call   1040 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1220 <main+0xc0>
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
jmp    1292 <main+0x132>
mov    -0x40(%rbp),%rdi
lea    0xe1e(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    124f <main+0xef>
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
jmp    1289 <main+0x129>
jmp    1254 <main+0xf4>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%eax
je     1280 <main+0x120>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1060 <fputc@plt>
jmp    1254 <main+0xf4>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r14
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
lea    0xe5e(%rip),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <scanf@plt>
lea    0xe4b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     1241 <main+0xd1>
mov    %rax,%r15
lea    0xe36(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     124f <main+0xdf>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2dd9(%rip),%r14
cmp    (%r14),%eax
je     1237 <main+0xc7>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %eax,%edi
mov    %rbx,%rsi
call   1070 <fputc@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    1220 <main+0xb0>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    125b <main+0xeb>
lea    0xe07(%rip),%rdi
call   1030 <puts@plt>
jmp    1263 <main+0xf3>
lea    0xdd2(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [14 x i8] c"Source file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"Destination file: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [35 x i8] c"\07 Failed to open the source file.\0A\00"
@.str.5 = [2 x i8] c"w\00"
@.str.6 = [40 x i8] c"\07 Failed to open the destination file.\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i32 0, i32* %1
%8 = load i32, i32* @FILENAME_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i32, i32* @FILENAME_MAX
%13 = zext i32 %12 to i64
%14 = alloca i8, i64 %13
store i64 %13, i64* %7
%15 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%19 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %19, i32** %3
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %0
%22 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
br label %44
23: ; preds = %0
%24 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %24, i32** %4
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %28
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.6, i64 0, i64 0))
br label %41
28: ; preds = %23
br label %29
29: ; preds = %34, %28
%30 = load i32*, i32** %3
%31 = call i32 @fgetc(i32* %30)
store i32 %31, i32* %2
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* %2
%36 = load i32*, i32** %4
%37 = call i32 @fputc(i32 %35, i32* %36)
br label %29
38: ; preds = %29
%39 = load i32*, i32** %4
%40 = call i32 @fclose(i32* %39)
br label %41
41: ; preds = %38, %26
%42 = load i32*, i32** %3
%43 = call i32 @fclose(i32* %42)
br label %44
44: ; preds = %41, %21
store i32 0, i32* %1
%45 = load i8*, i8** %5
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [14 x i8] c"Source file: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [19 x i8] c"Destination file: \00"
@.str.3 = [2 x i8] c"r\00"
@.str.5 = [2 x i8] c"w\00"
@EOF = global i32 0
@str = [39 x i8] c"\07 Failed to open the destination file.\00"
@str.7 = [34 x i8] c"\07 Failed to open the source file.\00"
define i32 @main() {
%1 = load i32, i32* @FILENAME_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = alloca i8, i64 %2
%5 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 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 ([19 x i8], [19 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 %13
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.7, i64 0, i64 0))
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 @fgetc(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 ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %30
22: ; preds = %16, %22
%23 = phi i32 [ %25, %22 ], [ %17, %16 ]
%24 = call i32 @fputc(i32 %23, i32* %14)
%25 = call i32 @fgetc(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* %14)
br label %30
30: ; preds = %28, %20
%31 = call i32 @fclose(i32* %9)
br label %32
32: ; preds = %30, %11
ret i32 0
}