#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 App_Read(int /*<<< orphan*/ *);
char *Files_GetAbsPath(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int App_Open(char *the_filename) {
  int opened = 0;
  FILE *file;
  char *full_filename;
  full_filename = Files_GetAbsPath(the_filename);
  printf("Opening file: %s\n", full_filename);
  file = fopen(full_filename, "rb");
  if (!file) {
    fprintf(stderr, "Could not open requested file!\n");
  } else {
    opened = App_Read(file);
    fclose(file);
    printf("...Done.\n");
  }
  free(full_filename);
  return opened;
}


x86 assembly (clang, -O0):
<App_Open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <Files_GetAbsPath@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11db <App_Open+0x6b>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
call   1070 <fprintf@plt>
jmp    11fe <App_Open+0x8e>
mov    -0x18(%rbp),%rdi
call   1090 <App_Read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<App_Open>:
push   %rbp
push   %r14
push   %rbx
call   1070 <Files_GetAbsPath@plt>
mov    %rax,%rbx
lea    0xe6d(%rip),%rdi
xor    %r14d,%r14d
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6b(%rip),%rsi
mov    %rbx,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11d8 <App_Open+0x58>
mov    %rax,%rbp
mov    %rax,%rdi
call   10a0 <App_Read@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1050 <fclose@plt>
lea    0xe64(%rip),%rdi
call   1040 <puts@plt>
jmp    11ed <App_Open+0x6d>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Opening file: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Could not open requested file!\0A\00"
@.str.3 = [10 x i8] c"...Done.\0A\00"
define i32 @App_Open(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
store i8* %0, i8** %2
store i32 0, i32* %3
%6 = load i8*, i8** %2
%7 = call i8* @Files_GetAbsPath(i8* %6)
store i8* %7, i8** %5
%8 = load i8*, i8** %5
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i8*, i8** %5
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %17, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %23
17: ; preds = %1
%18 = load i32*, i32** %4
%19 = call i32 @App_Read(i32* %18)
store i32 %19, i32* %3
%20 = load i32*, i32** %4
%21 = call i32 @fclose(i32* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %17, %14
%24 = load i8*, i8** %5
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [18 x i8] c"Opening file: %s\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.2 = [32 x i8] c"Could not open requested file!\0A\00"
@str = [9 x i8] c"...Done.\00"
define i32 @App_Open(i8* %0) {
%2 = tail call i8* @Files_GetAbsPath(i8* %0)
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
br label %13
9: ; preds = %1
%10 = tail call i32 @App_Read(i32* %4)
%11 = tail call i32 @fclose(i32* %4)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %13
13: ; preds = %9, %6
%14 = phi i32 [ %10, %9 ], [ 0, %6 ]
%15 = tail call i32 @free(i8* %2)
ret i32 %14
}