#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 */

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int O_RDWR;
int O_WRONLY;
int __mode_2_omode(int mode) {
  int omode = 0;
  if (mode & 0x0001)
    omode |= O_RDONLY;
  if (mode & 0x0002)
    omode |= O_WRONLY;
  if (mode & 0x0004)
    omode |= O_RDWR;
  if (mode & 0x0010)
    omode |= O_NONBLOCK;
  return omode;
}


x86 assembly (clang, -O0):
<__mode_2_omode>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     112c <__mode_2_omode+0x2c>
mov    0x2eb4(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     114a <__mode_2_omode+0x4a>
mov    0x2e7e(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1168 <__mode_2_omode+0x68>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     1186 <__mode_2_omode+0x86>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<__mode_2_omode>:
mov    %edi,%ecx
and    $0x1,%ecx
neg    %ecx
mov    0x2eca(%rip),%rax
and    (%rax),%ecx
mov    %edi,%edx
shl    $0x1e,%edx
sar    $0x1f,%edx
mov    0x2ea1(%rip),%rax
and    (%rax),%edx
mov    %edi,%eax
shl    $0x1d,%eax
sar    $0x1f,%eax
mov    0x2eb8(%rip),%rsi
and    (%rsi),%eax
or     %ecx,%edx
shl    $0x1b,%edi
sar    $0x1f,%edi
mov    0x2e9f(%rip),%rcx
and    (%rcx),%edi
or     %edi,%eax
or     %edx,%eax
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
define i32 @__mode_2_omode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = and i32 %4, 1
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = load i32, i32* @O_RDONLY
%9 = load i32, i32* %3
%10 = or i32 %9, %8
store i32 %10, i32* %3
br label %11
11: ; preds = %7, %1
%12 = load i32, i32* %2
%13 = and i32 %12, 2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i32, i32* @O_WRONLY
%17 = load i32, i32* %3
%18 = or i32 %17, %16
store i32 %18, i32* %3
br label %19
19: ; preds = %15, %11
%20 = load i32, i32* %2
%21 = and i32 %20, 4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i32, i32* @O_RDWR
%25 = load i32, i32* %3
%26 = or i32 %25, %24
store i32 %26, i32* %3
br label %27
27: ; preds = %23, %19
%28 = load i32, i32* %2
%29 = and i32 %28, 16
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @O_NONBLOCK
%33 = load i32, i32* %3
%34 = or i32 %33, %32
store i32 %34, i32* %3
br label %35
35: ; preds = %31, %27
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@O_WRONLY = global i32 0
@O_RDWR = global i32 0
@O_NONBLOCK = global i32 0
define i32 @__mode_2_omode(i32 %0) {
%2 = and i32 %0, 1
%3 = icmp eq i32 %2, 0
%4 = load i32, i32* @O_RDONLY
%5 = select i1 %3, i32 0, i32 %4
%6 = and i32 %0, 2
%7 = icmp eq i32 %6, 0
%8 = load i32, i32* @O_WRONLY
%9 = select i1 %7, i32 0, i32 %8
%10 = or i32 %9, %5
%11 = and i32 %0, 4
%12 = icmp eq i32 %11, 0
%13 = load i32, i32* @O_RDWR
%14 = select i1 %12, i32 0, i32 %13
%15 = or i32 %10, %14
%16 = and i32 %0, 16
%17 = icmp eq i32 %16, 0
%18 = load i32, i32* @O_NONBLOCK
%19 = select i1 %17, i32 0, i32 %18
%20 = or i32 %15, %19
ret i32 %20
}