#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*/ EXIT_FAILURE;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ msg_Err(int /*<<< orphan*/ *, char *, char const *,
                           int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
FILE *OpenAuxFile(const char *psz_arg, bool b_read, bool b_append) {
  FILE *p_aux;
  if ((p_aux = fopen(psz_arg, b_read ? "rb" : (b_append ? "ab" : "wb"))) ==
      NULL) {
    msg_Err(NULL, "couldn't open file %s (%s)", psz_arg, strerror(errno));
    exit(EXIT_FAILURE);
  }
  return p_aux;
}


x86 assembly (clang, -O0):
<OpenAuxFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     1174 <OpenAuxFile+0x34>
lea    0xe95(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <OpenAuxFile+0x50>
mov    -0x10(%rbp),%edx
lea    0xe88(%rip),%rax
lea    0xe7e(%rip),%rcx
cmp    $0x0,%edx
cmovne %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e5 <OpenAuxFile+0xa5>
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x30(%rbp),%rdx
mov    %eax,%ecx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe37(%rip),%rsi
call   1030 <msg_Err@plt>
mov    0x2dfa(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<OpenAuxFile>:
push   %rbx
mov    %rdi,%rbx
test   %edx,%edx
lea    0xeb9(%rip),%rax
lea    0xeaf(%rip),%rcx
cmove  %rax,%rcx
test   %esi,%esi
lea    0xe9f(%rip),%rsi
cmove  %rcx,%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1171 <OpenAuxFile+0x31>
pop    %rbx
ret
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe83(%rip),%rsi
xor    %edi,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
call   1030 <msg_Err@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [27 x i8] c"couldn't open file %s (%s)\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i32* @OpenAuxFile(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i8*, i8** %4
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
br label %17
12: ; preds = %3
%13 = load i32, i32* %6
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %17
17: ; preds = %12, %11
%18 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %11 ], [ %16, %12 ]
%19 = call i32* @fopen(i8* %8, i8* %18)
store i32* %19, i32** %7
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i8*, i8** %4
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %22, i32 %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %17
%29 = load i32*, i32** %7
ret i32* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"ab\00"
@.str.2 = [3 x i8] c"wb\00"
@.str.3 = [27 x i8] c"couldn't open file %s (%s)\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define noalias i32* @OpenAuxFile(i8* %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%7 = select i1 %4, i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0)
%8 = tail call i32* @fopen(i8* %0, i8* %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %16
10: ; preds = %3
%11 = load i32, i32* @errno
%12 = tail call i32 @strerror(i32 %11)
%13 = tail call i32 @msg_Err(i32* null, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %3
ret i32* %8
}