#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 /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
char *status_get_file_path();
int /*<<< orphan*/ stderr;
FILE *status_get_file_ptr(char *mode) {
  char *path = NULL;
  FILE *fp = NULL;
  path = status_get_file_path();
  if (path == NULL)
    return NULL;
  fp = fopen(path, mode);
  if (fp == NULL) {
    fprintf(stderr, "Failed to open %s.\n", path);
    free(path);
    return NULL;
  }
  free(path);
  return fp;
}


x86 assembly (clang, -O0):
<status_get_file_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x0,%al
call   1050 <status_get_file_path@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    117f <status_get_file_ptr+0x3f>
movq   $0x0,-0x8(%rbp)
jmp    11db <status_get_file_ptr+0x9b>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ca <status_get_file_ptr+0x8a>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe51(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    11db <status_get_file_ptr+0x9b>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<status_get_file_ptr>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <status_get_file_path@plt>
test   %rax,%rax
je     118e <status_get_file_ptr+0x4e>
mov    %rax,%r14
mov    %rax,%rdi
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1186 <status_get_file_ptr+0x46>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe84(%rip),%rsi
mov    %r14,%rdx
call   1040 <fprintf@plt>
xor    %ebx,%ebx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [20 x i8] c"Failed to open %s.\0A\00"
define i32* @status_get_file_ptr(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i8* null, i8** %4
store i32* null, i32** %5
%6 = call i8* (...) @status_get_file_path()
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i32* null, i32** %2
br label %26
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %11, i8* %12)
store i32* %13, i32** %5
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %22
16: ; preds = %10
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %4
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = call i32 @free(i8* %20)
store i32* null, i32** %2
br label %26
22: ; preds = %10
%23 = load i8*, i8** %4
%24 = call i32 @free(i8* %23)
%25 = load i32*, i32** %5
store i32* %25, i32** %2
br label %26
26: ; preds = %22, %16, %9
%27 = load i32*, i32** %2
ret i32* %27
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"Failed to open %s.\0A\00"
define noalias i32* @status_get_file_ptr(i8* nocapture %0) {
%2 = tail call i8* (...) @status_get_file_path()
%3 = icmp eq i8* %2, null
br i1 %3, label %13, label %4
4: ; preds = %1
%5 = tail call i32* @fopen(i8* %2, i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %10
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %2)
br label %10
10: ; preds = %4, %7
%11 = phi i32* [ null, %7 ], [ %5, %4 ]
%12 = tail call i32 @free(i8* %2)
br label %13
13: ; preds = %10, %1
%14 = phi i32* [ null, %1 ], [ %11, %10 ]
ret i32* %14
}