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

/* Variables and functions */
#define R_OK 129
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
#define W_OK 128
int const X_OK;
int /*<<< orphan*/ assert(int);
int hasperm(int /*<<< orphan*/, int, int const);
bool hasopperm(mode_t mode, int op, int type) {
  switch (op) {
  case R_OK:
    if (S_ISDIR(mode)) {
      return hasperm(mode, type, R_OK | X_OK);
    }
    return hasperm(mode, type, R_OK);
  case W_OK:
    return hasperm(mode, type, W_OK);
  }
  assert(false);
}


x86 assembly (clang, -O0):
<hasopperm>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
sub    $0x80,%eax
je     11b5 <hasopperm+0x85>
jmp    1157 <hasopperm+0x27>
mov    -0x14(%rbp),%eax
sub    $0x81,%eax
jne    11cd <hasopperm+0x9d>
jmp    116a <hasopperm+0x3a>
mov    -0x8(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
je     119d <hasopperm+0x6d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    0x2e60(%rip),%rax
mov    (%rax),%edx
or     $0x81,%edx
call   1030 <hasperm@plt>
mov    %eax,-0x4(%rbp)
jmp    11d4 <hasopperm+0xa4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x81,%edx
call   1030 <hasperm@plt>
mov    %eax,-0x4(%rbp)
jmp    11d4 <hasopperm+0xa4>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%esi
mov    $0x80,%edx
call   1030 <hasperm@plt>
mov    %eax,-0x4(%rbp)
jmp    11d4 <hasopperm+0xa4>
xor    %edi,%edi
call   1050 <assert@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hasopperm>:
push   %rbp
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %edi,%ebp
cmp    $0x80,%esi
je     1159 <hasopperm+0x29>
cmp    $0x81,%esi
jne    116d <hasopperm+0x3d>
mov    %ebp,%edi
call   1040 <S_ISDIR@plt>
mov    %ebp,%edi
mov    %ebx,%esi
mov    $0x81,%edx
jmp    1162 <hasopperm+0x32>
mov    %ebp,%edi
mov    %ebx,%esi
mov    $0x80,%edx
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <hasperm@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <assert@plt>

LLVM IR (-O0):
@X_OK = constant i32 0
define i32 @hasopperm(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
switch i32 %8, label %27 [
i32 129, label %9
i32 128, label %23
]
9: ; preds = %3
%10 = load i32, i32* %5
%11 = call i32 @S_ISDIR(i32 %10)
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load i32, i32* %5
%15 = load i32, i32* %7
%16 = load i32, i32* @X_OK
%17 = or i32 129, %16
%18 = call i32 @hasperm(i32 %14, i32 %15, i32 %17)
store i32 %18, i32* %4
br label %29
19: ; preds = %9
%20 = load i32, i32* %5
%21 = load i32, i32* %7
%22 = call i32 @hasperm(i32 %20, i32 %21, i32 129)
store i32 %22, i32* %4
br label %29
23: ; preds = %3
%24 = load i32, i32* %5
%25 = load i32, i32* %7
%26 = call i32 @hasperm(i32 %24, i32 %25, i32 128)
store i32 %26, i32* %4
br label %29
27: ; preds = %3
%28 = call i32 @assert(i32 0)
br label %29
29: ; preds = %27, %23, %19, %13
%30 = load i32, i32* %4
ret i32 %30
}

LLVM IR (-O2):
@X_OK = constant i32 0
define i32 @hasopperm(i32 %0, i32 %1, i32 %2) {
switch i32 %1, label %9 [
i32 129, label %4
i32 128, label %7
]
4: ; preds = %3
%5 = tail call i32 @S_ISDIR(i32 %0)
%6 = tail call i32 @hasperm(i32 %0, i32 %2, i32 129)
br label %11
7: ; preds = %3
%8 = tail call i32 @hasperm(i32 %0, i32 %2, i32 128)
br label %11
9: ; preds = %3
%10 = tail call i32 @assert(i32 0)
br label %11
11: ; preds = %4, %9, %7
%12 = phi i32 [ undef, %9 ], [ %8, %7 ], [ %6, %4 ]
ret i32 %12
}