#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 R_OK;
int W_OK;
int X_OK;
int fuserl_access_mode_canonicalize(int mode) {
  int canonical = 0;
  if ((mode & X_OK) == X_OK) {
    canonical |= 1;
  }
  if ((mode & W_OK) == W_OK) {
    canonical |= 2;
  }
  if ((mode & R_OK) == R_OK) {
    canonical |= 4;
  }
  return canonical;
}


x86 assembly (clang, -O0):
<fuserl_access_mode_canonicalize>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ec8(%rip),%rcx
and    (%rcx),%eax
mov    0x2ebf(%rip),%rcx
cmp    (%rcx),%eax
jne    1132 <fuserl_access_mode_canonicalize+0x32>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2eac(%rip),%rcx
and    (%rcx),%eax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%eax
jne    1156 <fuserl_access_mode_canonicalize+0x56>
mov    -0x8(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e70(%rip),%rcx
and    (%rcx),%eax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%eax
jne    117a <fuserl_access_mode_canonicalize+0x7a>
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuserl_access_mode_canonicalize>:
mov    0x2ed9(%rip),%rax
not    %edi
xor    %ecx,%ecx
test   %edi,(%rax)
sete   %cl
mov    0x2ed1(%rip),%rax
lea    0x2(%rcx),%edx
test   %edi,(%rax)
cmovne %ecx,%edx
mov    0x2eaa(%rip),%rcx
lea    0x4(%rdx),%eax
test   %edi,(%rcx)
cmovne %edx,%eax
ret

LLVM IR (-O0):
@X_OK = global i32 0
@W_OK = global i32 0
@R_OK = global i32 0
define i32 @fuserl_access_mode_canonicalize(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%4 = load i32, i32* %2
%5 = load i32, i32* @X_OK
%6 = and i32 %4, %5
%7 = load i32, i32* @X_OK
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* %3
%11 = or i32 %10, 1
store i32 %11, i32* %3
br label %12
12: ; preds = %9, %1
%13 = load i32, i32* %2
%14 = load i32, i32* @W_OK
%15 = and i32 %13, %14
%16 = load i32, i32* @W_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = load i32, i32* %3
%20 = or i32 %19, 2
store i32 %20, i32* %3
br label %21
21: ; preds = %18, %12
%22 = load i32, i32* %2
%23 = load i32, i32* @R_OK
%24 = and i32 %22, %23
%25 = load i32, i32* @R_OK
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %3
%29 = or i32 %28, 4
store i32 %29, i32* %3
br label %30
30: ; preds = %27, %21
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
@X_OK = global i32 0
@W_OK = global i32 0
@R_OK = global i32 0
define i32 @fuserl_access_mode_canonicalize(i32 %0) {
%2 = load i32, i32* @X_OK
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, %2
%5 = zext i1 %4 to i32
%6 = load i32, i32* @W_OK
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, %6
%9 = or i32 %5, 2
%10 = select i1 %8, i32 %9, i32 %5
%11 = load i32, i32* @R_OK
%12 = and i32 %11, %0
%13 = icmp eq i32 %12, %11
%14 = or i32 %10, 4
%15 = select i1 %13, i32 %14, i32 %10
ret i32 %15
}