#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 errno;
int /*<<< orphan*/ fn_log_f(char *, char const *, char const *, int);
int /*<<< orphan*/ *fopen(char const *, char const *);
int /*<<< orphan*/ perror(char *);
FILE *fn_f_open(const char *filename, const char *mode) {
  FILE *fptr = fopen(filename, mode);
  int err = errno;
  if ((fptr == NULL) && (err != 0)) {
    fn_log_f(
        "- I_ERR_FOP_X; error; fopen of %s with mode %s returned errno %d\n",
        filename, mode, err);
    perror("- I_ERR_FOP_X; error; ");
  }
  return fptr;
}


x86 assembly (clang, -O0):
<fn_f_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1195 <fn_f_open+0x65>
cmpl   $0x0,-0x1c(%rbp)
je     1195 <fn_f_open+0x65>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe7c(%rip),%rdi
call   1050 <fn_log_f@plt>
lea    0xeb2(%rip),%rdi
call   1040 <perror@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fn_f_open>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
call   1030 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1155 <fn_f_open+0x25>
mov    0x2e91(%rip),%rax
mov    (%rax),%ecx
test   %ecx,%ecx
jne    115e <fn_f_open+0x2e>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe9b(%rip),%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <fn_log_f@plt>
lea    0xecb(%rip),%rdi
call   1040 <perror@plt>
jmp    1155 <fn_f_open+0x25>

LLVM IR (-O0):
@errno = global i32 0
@.str = [66 x i8] c"- I_ERR_FOP_X; error; fopen of %s with mode %s returned errno %d\0A\00"
@.str.1 = [23 x i8] c"- I_ERR_FOP_X; error; \00"
define i32* @fn_f_open(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %7, i8* %8)
store i32* %9, i32** %5
%10 = load i32, i32* @errno
store i32 %10, i32* %6
%11 = load i32*, i32** %5
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %22
13: ; preds = %2
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %13
%17 = load i8*, i8** %3
%18 = load i8*, i8** %4
%19 = load i32, i32* %6
%20 = call i32 @fn_log_f(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18, i32 %19)
%21 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %16, %13, %2
%23 = load i32*, i32** %5
ret i32* %23
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [66 x i8] c"- I_ERR_FOP_X; error; fopen of %s with mode %s returned errno %d\0A\00"
@.str.1 = [23 x i8] c"- I_ERR_FOP_X; error; \00"
define noalias i32* @fn_f_open(i8* %0, i8* %1) {
%3 = tail call i32* @fopen(i8* %0, i8* %1)
%4 = load i32, i32* @errno
%5 = icmp eq i32* %3, null
%6 = icmp ne i32 %4, 0
%7 = select i1 %5, i1 %6, i1 false
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 @fn_log_f(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %4)
%10 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %2
ret i32* %3
}