#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 void FILE;

/* Variables and functions */
void *fopen(char const *, char const *);
void *miniz_fopen(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):
<miniz_fopen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0xc(%rbp),%eax
and    $0x3,%eax
cmp    $0x1,%eax
jne    114e <miniz_fopen+0x3e>
lea    0xebb(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    1191 <miniz_fopen+0x81>
mov    -0xc(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     116d <miniz_fopen+0x5d>
lea    0xe9f(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    118c <miniz_fopen+0x7c>
mov    -0xc(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     1187 <miniz_fopen+0x77>
lea    0xe84(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    118c <miniz_fopen+0x7c>
jmp    1191 <miniz_fopen+0x81>
cmpq   $0x0,-0x8(%rbp)
je     11b8 <miniz_fopen+0xa8>
cmpq   $0x0,-0x20(%rbp)
je     11b8 <miniz_fopen+0xa8>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<miniz_fopen>:
mov    %esi,%edx
and    $0x3,%edx
mov    $0x1,%cl
cmp    $0x1,%edx
jne    112a <miniz_fopen+0x1a>
lea    0xedd(%rip),%rsi
test   %rdi,%rdi
jne    115a <miniz_fopen+0x4a>
jmp    1163 <miniz_fopen+0x53>
mov    %esi,%eax
test   $0x4,%al
jne    114e <miniz_fopen+0x3e>
and    $0x8,%eax
mov    %eax,%ecx
shr    $0x3,%ecx
xor    %esi,%esi
test   %eax,%eax
lea    0xec4(%rip),%rax
cmovne %rax,%rsi
test   %rdi,%rdi
jne    115a <miniz_fopen+0x4a>
jmp    1163 <miniz_fopen+0x53>
lea    0xeae(%rip),%rsi
test   %rdi,%rdi
je     1163 <miniz_fopen+0x53>
test   %cl,%cl
je     1163 <miniz_fopen+0x53>
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 i8* @miniz_fopen(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i8* null, i8** %5
store i8* null, i8** %6
%7 = load i32, i32* %4
%8 = and i32 %7, 3
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
br label %23
11: ; preds = %2
%12 = load i32, i32* %4
%13 = and i32 %12, 4
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %11
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %22
16: ; preds = %11
%17 = load i32, i32* %4
%18 = and i32 %17, 8
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %6
br label %21
21: ; preds = %20, %16
br label %22
22: ; preds = %21, %15
br label %23
23: ; preds = %22, %10
%24 = load i8*, i8** %3
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = load i8*, i8** %6
%28 = icmp ne i8* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = load i8*, i8** %6
%32 = call i8* @fopen(i8* %30, i8* %31)
store i8* %32, i8** %5
br label %33
33: ; preds = %29, %26, %23
%34 = load i8*, i8** %5
ret i8* %34
}

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 i8* @miniz_fopen(i8* %0, i32 %1) {
%3 = and i32 %1, 3
%4 = icmp eq i32 %3, 1
br i1 %4, label %13, label %5
5: ; preds = %2
%6 = and i32 %1, 4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = and i32 %1, 8
%10 = icmp eq i32 %9, 0
%11 = xor i1 %10, true
%12 = select i1 %10, i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0)
br label %13
13: ; preds = %8, %5, %2
%14 = phi i1 [ true, %2 ], [ true, %5 ], [ %11, %8 ]
%15 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %5 ], [ %12, %8 ]
%16 = icmp ne i8* %0, null
%17 = and i1 %16, %14
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i8* @fopen(i8* %0, i8* %15)
br label %20
20: ; preds = %18, %13
%21 = phi i8* [ %19, %18 ], [ null, %13 ]
ret i8* %21
}