#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*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ scanf(char *, char *);
int main(void) {
  int ch;
  FILE *fp;
  char fname[FILENAME_MAX];
  printf("Filename: ");
  scanf("%s", fname);
  if ((fp = fopen(fname, "r")) == NULL)
    printf("\aFiled to open the file.\n");
  else {
    while ((ch = fgetc(fp)) != EOF)
      putchar(ch);
    fclose(fp);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e6a(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe59(%rip),%rdi
call   1070 <scanf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe4c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11e6 <main+0x86>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
jmp    121c <main+0xbc>
jmp    11eb <main+0x8b>
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%eax
je     1213 <main+0xb3>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11eb <main+0x8b>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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   %r14
push   %rbx
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe68(%rip),%rdi
call   1060 <printf@plt>
lea    0xe67(%rip),%rdi
mov    %rbx,%rsi
call   1080 <scanf@plt>
lea    0xe5b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11fe <main+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <fgetc@plt>
mov    0x2e16(%rip),%r14
cmp    (%r14),%eax
je     11f4 <main+0x84>
nopw   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <fgetc@plt>
cmp    (%r14),%eax
jne    11e0 <main+0x70>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    120a <main+0x9a>
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@FILENAME_MAX = global i32 0
@.str = [11 x i8] c"Filename: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"\07Filed to open the file.\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i32 0, i32* %1
%6 = load i32, i32* @FILENAME_MAX
%7 = zext i32 %6 to i64
%8 = call i8* @llvm.stacksave()
store i8* %8, i8** %4
%9 = alloca i8, i64 %7
store i64 %7, i64* %5
%10 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %3
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %0
%15 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
br label %28
16: ; preds = %0
br label %17
17: ; preds = %22, %16
%18 = load i32*, i32** %3
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %2
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* %2
%24 = call i32 @putchar(i32 %23)
br label %17
25: ; preds = %17
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
br label %28
28: ; preds = %25, %14
store i32 0, i32* %1
%29 = load i8*, i8** %4
%30 = load i32, i32* %1
ret i32 %30
}

LLVM IR (-O2):
@FILENAME_MAX = global i32 0
@.str = [11 x i8] c"Filename: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [25 x i8] c"\07Filed to open the file.\00"
define i32 @main() {
%1 = load i32, i32* @FILENAME_MAX
%2 = zext i32 %1 to i64
%3 = alloca i8, i64 %2
%4 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%6 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %12, label %8
8: ; preds = %0
%9 = call i32 @fgetc(i32* %6)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %20, label %14
12: ; preds = %0
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
br label %22
14: ; preds = %8, %14
%15 = phi i32 [ %17, %14 ], [ %9, %8 ]
%16 = call i32 @putchar(i32 %15)
%17 = call i32 @fgetc(i32* %6)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %8
%21 = call i32 @fclose(i32* %6)
br label %22
22: ; preds = %20, %12
ret i32 0
}