#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ putchar(int);
main() {
  FILE *fp;
  char *filePath = "/tmp/test/CMakeLists.txt";
  char *model = "r";
  fp = fopen(filePath, model);
  if (fp == NULL) {
    printf("open file failure！\n");
    return 0;
  }
  int c;
  while ((c = getc(fp)) != EOF) {
    putchar(c);
  }
  fclose(fp);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11a9 <main+0x59>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11df <main+0x8f>
jmp    11ae <main+0x5e>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x24(%rbp)
mov    0x2e27(%rip),%rcx
cmp    (%rcx),%eax
je     11d6 <main+0x86>
mov    -0x24(%rbp),%edi
call   1030 <putchar@plt>
jmp    11ae <main+0x5e>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
lea    0xeb7(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ae <main+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
mov    0x2e6a(%rip),%r14
cmp    (%r14),%eax
je     11a4 <main+0x54>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%eax
jne    1190 <main+0x40>
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    11ba <main+0x6a>
lea    0xe66(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"/tmp/test/CMakeLists.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [22 x i8] c"open file failure\EF\BC\81\0A\00"
@EOF = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %3
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4
%6 = load i8*, i8** %3
%7 = load i8*, i8** %4
%8 = call i32* @fopen(i8* %6, i8* %7)
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %1
br label %25
13: ; preds = %0
br label %14
14: ; preds = %19, %13
%15 = load i32*, i32** %2
%16 = call i32 @getc(i32* %15)
store i32 %16, i32* %5
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* %5
%21 = call i32 @putchar(i32 %20)
br label %14
22: ; preds = %14
%23 = load i32*, i32** %2
%24 = call i32 @fclose(i32* %23)
br label %25
25: ; preds = %22, %11
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@.str = [25 x i8] c"/tmp/test/CMakeLists.txt\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [21 x i8] c"open file failure\EF\BC\81\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %7, label %3
3: ; preds = %0
%4 = tail call i32 @getc(i32* %1)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %15, label %9
7: ; preds = %0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str, i64 0, i64 0))
br label %17
9: ; preds = %3, %9
%10 = phi i32 [ %12, %9 ], [ %4, %3 ]
%11 = tail call i32 @putchar(i32 %10)
%12 = tail call i32 @getc(i32* %1)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %9
15: ; preds = %9, %3
%16 = tail call i32 @fclose(i32* %1)
br label %17
17: ; preds = %15, %7
ret i32 0
}