#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*/ putchar(int);
int /*<<< orphan*/ puts(char *);
void readFile(char *filename) {
  FILE *fptr;
  fptr = fopen(filename, "r");
  if (fptr != NULL)
    puts("File opened successfully!");
  else
    puts("ERROR: Reading file");
  int cursor = getc(fptr);
  while (cursor != EOF) {
    putchar(cursor);
    cursor = getc(fptr);
  }
  fclose(fptr);
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     118c <readFile+0x3c>
lea    0xe80(%rip),%rdi
call   1040 <puts@plt>
jmp    1198 <readFile+0x48>
lea    0xe89(%rip),%rdi
call   1040 <puts@plt>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
je     11cf <readFile+0x7f>
mov    -0x14(%rbp),%edi
call   1030 <putchar@plt>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x14(%rbp)
jmp    11a4 <readFile+0x54>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
lea    0xeaf(%rip),%rax
lea    0xe8e(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
mov    0x2e5c(%rip),%r14
cmp    (%r14),%eax
je     11b4 <readFile+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %eax,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    (%r14),%eax
jne    11a0 <readFile+0x50>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"File opened successfully!\00"
@.str.2 = [20 x i8] c"ERROR: Reading file\00"
@EOF = global i32 0
define void @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @puts(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %1
%12 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %9
%14 = load i32*, i32** %3
%15 = call i32 @getc(i32* %14)
store i32 %15, i32* %4
br label %16
16: ; preds = %20, %13
%17 = load i32, i32* %4
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %25
20: ; preds = %16
%21 = load i32, i32* %4
%22 = call i32 @putchar(i32 %21)
%23 = load i32*, i32** %3
%24 = call i32 @getc(i32* %23)
store i32 %24, i32* %4
br label %16
25: ; preds = %16
%26 = load i32*, i32** %3
%27 = call i32 @fclose(i32* %26)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [26 x i8] c"File opened successfully!\00"
@.str.2 = [20 x i8] c"ERROR: Reading file\00"
@EOF = global i32 0
define void @readFile(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
%4 = select i1 %3, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0)
%5 = tail call i32 @puts(i8* dereferenceable(1) %4)
%6 = tail call i32 @getc(i32* %2)
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %6, %7
br i1 %8, label %15, label %9
9: ; preds = %1, %9
%10 = phi i32 [ %12, %9 ], [ %6, %1 ]
%11 = tail call i32 @putchar(i32 %10)
%12 = tail call i32 @getc(i32* %2)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %9
15: ; preds = %9, %1
%16 = tail call i32 @fclose(i32* %2)
ret void
}