#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 */
scalar_t__ file_exists(char const *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
FILE *load_file(const char *path) {
  if (file_exists(path)) {
    fprintf(stdout, "File found: %s \n", path);
    FILE *tempfile = fopen(path, "r");
    return tempfile;
  } else {
    fprintf(stderr, "File not found: %s \n", path);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<load_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <file_exists@plt>
cmp    $0x0,%rax
je     1189 <load_file+0x59>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe9d(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
lea    0xe9e(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11aa <load_file+0x7a>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_file>:
push   %rbx
mov    %rdi,%rbx
call   1030 <file_exists@plt>
test   %rax,%rax
je     1166 <load_file+0x36>
mov    0x2e93(%rip),%rax
mov    (%rax),%edi
lea    0xeb2(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
lea    0xeb4(%rip),%rsi
mov    %rbx,%rdi
pop    %rbx
jmp    1050 <fopen@plt>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [17 x i8] c"File found: %s \0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"File not found: %s \0A\00"
define i32* @load_file(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i64 @file_exists(i8* %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stdout
%10 = load i8*, i8** %3
%11 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %13, i32** %4
%14 = load i32*, i32** %4
store i32* %14, i32** %2
br label %19
15: ; preds = %1
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %3
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %17)
store i32* null, i32** %2
br label %19
19: ; preds = %15, %8
%20 = load i32*, i32** %2
ret i32* %20
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [17 x i8] c"File found: %s \0A\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [21 x i8] c"File not found: %s \0A\00"
define noalias i32* @load_file(i8* %0) {
%2 = tail call i64 @file_exists(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %8, label %4
4: ; preds = %1
%5 = load i32, i32* @stdout
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %11
11: ; preds = %8, %4
%12 = phi i32* [ %7, %4 ], [ null, %8 ]
ret i32* %12
}