#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*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  FILE *fp;
  int ret;
  if (argv[1] == NULL) {
    printf("please input src file\n");
    return -1;
  }
  fp = fopen(argv[1], "r");
  if (fp == NULL) {
    printf("open file %s failure\n", argv[1]);
    return -2;
  }
  while (1) {
    ret = fgetc(fp);
    if (feof(fp)) {
      break;
    }
    fputc(ret, stdout);
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    119f <main+0x3f>
lea    0xe74(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1233 <main+0xd3>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe69(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e4 <main+0x84>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0xfffffffe,-0x4(%rbp)
jmp    1233 <main+0xd3>
jmp    11e9 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
je     120d <main+0xad>
jmp    1223 <main+0xc3>
mov    -0x1c(%rbp),%edi
mov    0x2dc9(%rip),%rax
mov    (%rax),%esi
call   1060 <fputc@plt>
jmp    11e9 <main+0x89>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x8(%rsi),%rdi
test   %rdi,%rdi
je     11ed <main+0x7d>
mov    %rsi,%rbp
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1200 <main+0x90>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
jne    11e1 <main+0x71>
mov    0x2e2e(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r14),%esi
mov    %ebp,%edi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1080 <feof@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
jmp    1217 <main+0xa7>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1217 <main+0xa7>
mov    0x8(%rbp),%rsi
lea    0xdf7(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0xfffffffe,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"open file %s failure\0A\00"
@stdout = global i32 0
@str = [22 x i8] c"please input src file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
br label %27
8: ; preds = %2
%9 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32 @fgetc(i32* %9)
%13 = tail call i64 @feof(i32* %9)
%14 = icmp eq i64 %13, 0
br i1 %14, label %18, label %25
15: ; preds = %8
%16 = load i8*, i8** %3
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %16)
br label %27
18: ; preds = %11, %18
%19 = phi i32 [ %22, %18 ], [ %12, %11 ]
%20 = load i32, i32* @stdout
%21 = tail call i32 @fputc(i32 %19, i32 %20)
%22 = tail call i32 @fgetc(i32* %9)
%23 = tail call i64 @feof(i32* %9)
%24 = icmp eq i64 %23, 0
br i1 %24, label %18, label %25
25: ; preds = %18, %11
%26 = tail call i32 @fclose(i32* %9)
br label %27
27: ; preds = %25, %15, %6
%28 = phi i32 [ -1, %6 ], [ -2, %15 ], [ 0, %25 ]
ret i32 %28
}