#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 */
char EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int readFile(char *filePath) {
  if (NULL == filePath) {
    return -1;
  }
  FILE *fp = fopen(filePath, "r");
  if (NULL == fp) {
    perror("open file fail");
    return -1;
  }
  char c;
  while (EOF != (c = fgetc(fp))) {
    putc(c, stdout);
  }
  putc('\n', stdout);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
xor    %eax,%eax
cmp    -0x10(%rbp),%rax
jne    1174 <readFile+0x24>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <readFile+0xc6>
mov    -0x10(%rbp),%rdi
lea    0xe81(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    11ac <readFile+0x5c>
lea    0xe67(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1216 <readFile+0xc6>
jmp    11b1 <readFile+0x61>
mov    0x2e30(%rip),%rax
movsbl (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,%cl
mov    -0x20(%rbp),%eax
mov    %cl,-0x19(%rbp)
movsbl %cl,%ecx
cmp    %ecx,%eax
je     11f3 <readFile+0xa3>
mov    -0x19(%rbp),%al
mov    0x2df4(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1050 <putc@plt>
jmp    11b1 <readFile+0x61>
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
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):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%ebx
test   %rdi,%rdi
je     11d8 <readFile+0x88>
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11e5 <readFile+0x95>
mov    %rax,%rbp
mov    0x2e6c(%rip),%r14
mov    (%r14),%bl
mov    %rax,%rdi
call   1040 <fgetc@plt>
cmp    %al,%bl
je     11bb <readFile+0x6b>
mov    0x2e46(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%esi
movsbl %al,%edi
call   1050 <putc@plt>
movzbl (%r14),%ebx
mov    %rbp,%rdi
call   1040 <fgetc@plt>
cmp    %al,%bl
jne    11a0 <readFile+0x50>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1050 <putc@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe16(%rip),%rdi
call   1070 <perror@plt>
jmp    11d8 <readFile+0x88>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"open file fail\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @readFile(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = icmp eq i8* null, %6
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 -1, i32* %2
br label %33
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* null, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %33
16: ; preds = %9
br label %17
17: ; preds = %24, %16
%18 = load i8, i8* @EOF
%19 = sext i8 %18 to i32
%20 = load i32*, i32** %4
%21 = call signext i8 @fgetc(i32* %20)
store i8 %21, i8* %5
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %19, %22
br i1 %23, label %24, label %28
24: ; preds = %17
%25 = load i8, i8* %5
%26 = load i32, i32* @stdout
%27 = call i32 @putc(i8 signext %25, i32 %26)
br label %17
28: ; preds = %17
%29 = load i32, i32* @stdout
%30 = call i32 @putc(i8 signext 10, i32 %29)
%31 = load i32*, i32** %4
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %2
br label %33
33: ; preds = %28, %14, %8
%34 = load i32, i32* %2
ret i32 %34
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [15 x i8] c"open file fail\00"
@EOF = global i8 0
@stdout = global i32 0
define i32 @readFile(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %23, label %3
3: ; preds = %1
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %10, label %6
6: ; preds = %3
%7 = load i8, i8* @EOF
%8 = tail call signext i8 @fgetc(i32* %4)
%9 = icmp eq i8 %7, %8
br i1 %9, label %19, label %12
10: ; preds = %3
%11 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %23
12: ; preds = %6, %12
%13 = phi i8 [ %17, %12 ], [ %8, %6 ]
%14 = load i32, i32* @stdout
%15 = tail call i32 @putc(i8 signext %13, i32 %14)
%16 = load i8, i8* @EOF
%17 = tail call signext i8 @fgetc(i32* %4)
%18 = icmp eq i8 %16, %17
br i1 %18, label %19, label %12
19: ; preds = %12, %6
%20 = load i32, i32* @stdout
%21 = tail call i32 @putc(i8 signext 10, i32 %20)
%22 = tail call i32 @fclose(i32* %4)
br label %23
23: ; preds = %10, %19, %1
%24 = phi i32 [ -1, %1 ], [ -1, %10 ], [ 0, %19 ]
ret i32 %24
}