#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  int ch;
  FILE *fp;
  char fname[50];
  printf("输入文件名: ");
  scanf("%s", fname);
  fp = fopen(fname, "r");
  if (NULL == fp) {
    printf("error!\n");
    exit(1);
  }
  while ((ch = getc(fp)) != EOF) {
    putchar(ch);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
lea    -0x50(%rbp),%rsi
lea    0xe7c(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x50(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    11d1 <main+0x61>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11d6 <main+0x66>
mov    -0x10(%rbp),%rdi
call   1090 <getc@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dff(%rip),%rcx
cmp    (%rcx),%eax
je     11fe <main+0x8e>
mov    -0x8(%rbp),%edi
call   1030 <putchar@plt>
jmp    11d6 <main+0x66>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0xe72(%rip),%rdi
call   1060 <printf@plt>
lea    0xe78(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1070 <scanf@plt>
lea    0xe69(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f6 <main+0x76>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <getc@plt>
mov    0x2e1d(%rip),%r14
cmp    (%r14),%eax
je     11e4 <main+0x64>
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   10a0 <getc@plt>
cmp    (%r14),%eax
jne    11d0 <main+0x50>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"\E8\BE\93\E5\85\A5\E6\96\87\E4\BB\B6\E5\90\8D: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [8 x i8] c"error!\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [50 x i8]
store i32 0, i32* %1
%5 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [50 x i8], [50 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 [50 x i8], [50 x i8]* %4, i64 0, i64 0
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* null, %10
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
br label %16
16: ; preds = %21, %15
%17 = load i32*, i32** %3
%18 = call i32 @getc(i32* %17)
store i32 %18, i32* %2
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = load i32, i32* %2
%23 = call i32 @putchar(i32 %22)
br label %16
24: ; preds = %16
%25 = load i32*, i32** %3
%26 = call i32 @fclose(i32* %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [18 x i8] c"\E8\BE\93\E5\85\A5\E6\96\87\E4\BB\B6\E5\90\8D: \00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [7 x i8] c"error!\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%3 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 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 ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %11, label %7
7: ; preds = %0
%8 = call i32 @getc(i32* %5)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %20, label %14
11: ; preds = %0
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %7, %14
%15 = phi i32 [ %17, %14 ], [ %8, %7 ]
%16 = call i32 @putchar(i32 %15)
%17 = call i32 @getc(i32* %5)
%18 = load i32, i32* @EOF
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %14
20: ; preds = %14, %7
%21 = call i32 @fclose(i32* %5)
ret i32 0
}