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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char const *, char const *);
voidpf fopen_file_func(voidpf opaque, const char *filename, int mode) {
  FILE *file = NULL;
  const char *mode_fopen = NULL;
  if ((mode & (3)) == (1))
    mode_fopen = "rb";
  else if (mode & (4))
    mode_fopen = "r+b";
  else if (mode & (8))
    mode_fopen = "wb";
  if ((filename != NULL) && (mode_fopen != NULL))
    file = fopen(filename, mode_fopen);
  return file;
}


x86 assembly (clang, -O0):
<fopen_file_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    1152 <fopen_file_func+0x42>
lea    0xeb7(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1195 <fopen_file_func+0x85>
mov    -0x14(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1171 <fopen_file_func+0x61>
lea    0xe9b(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <fopen_file_func+0x80>
mov    -0x14(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     118b <fopen_file_func+0x7b>
lea    0xe80(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1190 <fopen_file_func+0x80>
jmp    1195 <fopen_file_func+0x85>
cmpq   $0x0,-0x10(%rbp)
je     11bc <fopen_file_func+0xac>
cmpq   $0x0,-0x28(%rbp)
je     11bc <fopen_file_func+0xac>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fopen_file_func>:
mov    %edx,%eax
and    $0x3,%eax
mov    $0x1,%cl
cmp    $0x1,%eax
jne    112a <fopen_file_func+0x1a>
lea    0xedd(%rip),%rax
test   %rsi,%rsi
jne    1159 <fopen_file_func+0x49>
jmp    1168 <fopen_file_func+0x58>
test   $0x4,%dl
jne    114d <fopen_file_func+0x3d>
and    $0x8,%edx
mov    %edx,%ecx
shr    $0x3,%ecx
xor    %eax,%eax
test   %edx,%edx
lea    0xec5(%rip),%rdx
cmovne %rdx,%rax
test   %rsi,%rsi
jne    1159 <fopen_file_func+0x49>
jmp    1168 <fopen_file_func+0x58>
lea    0xeaf(%rip),%rax
test   %rsi,%rsi
je     1168 <fopen_file_func+0x58>
test   %cl,%cl
je     1168 <fopen_file_func+0x58>
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1030 <fopen@plt>
xor    %eax,%eax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [3 x i8] c"wb\00"
define i32* @fopen_file_func(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32* null, i32** %7
store i8* null, i8** %8
%9 = load i32, i32* %6
%10 = and i32 %9, 3
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %3
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %8
br label %25
13: ; preds = %3
%14 = load i32, i32* %6
%15 = and i32 %14, 4
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %8
br label %24
18: ; preds = %13
%19 = load i32, i32* %6
%20 = and i32 %19, 8
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %18
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %8
br label %23
23: ; preds = %22, %18
br label %24
24: ; preds = %23, %17
br label %25
25: ; preds = %24, %12
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %8
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i8*, i8** %5
%33 = load i8*, i8** %8
%34 = call i32* @fopen(i8* %32, i8* %33)
store i32* %34, i32** %7
br label %35
35: ; preds = %31, %28, %25
%36 = load i32*, i32** %7
ret i32* %36
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [4 x i8] c"r+b\00"
@.str.2 = [3 x i8] c"wb\00"
define noalias i32* @fopen_file_func(i32* nocapture readnone %0, i8* %1, i32 %2) {
%4 = and i32 %2, 3
%5 = icmp eq i32 %4, 1
br i1 %5, label %14, label %6
6: ; preds = %3
%7 = and i32 %2, 4
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = and i32 %2, 8
%11 = icmp eq i32 %10, 0
%12 = xor i1 %11, true
%13 = select i1 %11, i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %14
14: ; preds = %9, %6, %3
%15 = phi i1 [ true, %3 ], [ true, %6 ], [ %12, %9 ]
%16 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %6 ], [ %13, %9 ]
%17 = icmp ne i8* %1, null
%18 = and i1 %17, %15
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = tail call i32* @fopen(i8* %1, i8* %16)
br label %21
21: ; preds = %19, %14
%22 = phi i32* [ %20, %19 ], [ null, %14 ]
ret i32* %22
}