#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 scalar_t__ u_int8_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ *fopen(char *, char *);
FILE *open_file(char *fname, u_int8_t writeMode) {
  FILE *file;
  if (writeMode) {
    if ((file = fopen(fname, "wb")) == NULL)
      error("Error opening open input file.");
  } else {
    if ((file = fopen(fname, "rb")) == NULL)
      error("Error opening open output file.");
  }
  return file;
}


x86 assembly (clang, -O0):
<open_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116a <open_file+0x4a>
mov    -0x8(%rbp),%rdi
lea    0xeba(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1165 <open_file+0x45>
lea    0xea3(%rip),%rdi
call   1030 <error@plt>
jmp    1199 <open_file+0x79>
mov    -0x8(%rbp),%rdi
lea    0xead(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1194 <open_file+0x74>
lea    0xe96(%rip),%rdi
call   1030 <error@plt>
jmp    1199 <open_file+0x79>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<open_file>:
push   %rax
test   %rsi,%rsi
je     1139 <open_file+0x19>
lea    0xed3(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1153 <open_file+0x33>
pop    %rcx
ret
lea    0xee2(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
jne    1137 <open_file+0x17>
lea    0xed4(%rip),%rdi
jmp    115a <open_file+0x3a>
lea    0xea9(%rip),%rdi
call   1030 <error@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
@.str.1 = [31 x i8] c"Error opening open input file.\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [32 x i8] c"Error opening open output file.\00"
define i32* @open_file(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32*
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i64, i64* %4
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %2
%9 = load i8*, i8** %3
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @error(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
br label %22
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32* @fopen(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %5
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 @error(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %15
br label %22
22: ; preds = %21, %14
%23 = load i32*, i32** %5
ret i32* %23
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
@.str.1 = [31 x i8] c"Error opening open input file.\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [32 x i8] c"Error opening open output file.\00"
define noalias i32* @open_file(i8* nocapture %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %13
7: ; preds = %2
%8 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %7, %4
%11 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), %4 ], [ getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), %7 ]
%12 = tail call i32 @error(i8* %11)
br label %13
13: ; preds = %10, %7, %4
%14 = phi i32* [ %5, %4 ], [ %8, %7 ], [ null, %10 ]
ret i32* %14
}