#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 uint32_t;

/* Variables and functions */
int EPOLLERR;
int EPOLLHUP;
int EPOLLIN;
int EPOLLOUT;
int EPOLLRDHUP;
uint32_t epoll_event_to_fd_event(uint32_t epoll_event) {
  uint32_t event_mask = 0;
  if (epoll_event & EPOLLERR) {
    event_mask = 0x01;
  } else if ((epoll_event & EPOLLHUP) || (epoll_event & EPOLLRDHUP)) {
    event_mask = 0x02;
  } else {
    if (epoll_event & EPOLLIN)
      event_mask |= 0x04;
    if (epoll_event & EPOLLOUT)
      event_mask |= 0x08;
  }
  return event_mask;
}


x86 assembly (clang, -O0):
<epoll_event_to_fd_event>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ec0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     112f <epoll_event_to_fd_event+0x2f>
movl   $0x1,-0x8(%rbp)
jmp    11ab <epoll_event_to_fd_event+0xab>
mov    -0x4(%rbp),%eax
mov    0x2e87(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    1159 <epoll_event_to_fd_event+0x59>
mov    -0x4(%rbp),%eax
mov    0x2e7a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1165 <epoll_event_to_fd_event+0x65>
movl   $0x2,-0x8(%rbp)
jmp    11a6 <epoll_event_to_fd_event+0xa6>
mov    -0x4(%rbp),%eax
mov    0x2e79(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1183 <epoll_event_to_fd_event+0x83>
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e43(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     11a1 <epoll_event_to_fd_event+0xa1>
mov    -0x8(%rbp),%eax
or     $0x8,%eax
mov    %eax,-0x8(%rbp)
jmp    11a6 <epoll_event_to_fd_event+0xa6>
jmp    11ab <epoll_event_to_fd_event+0xab>
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<epoll_event_to_fd_event>:
mov    0x2ed1(%rip),%rcx
mov    $0x1,%eax
test   %edi,(%rcx)
je     1111 <epoll_event_to_fd_event+0x11>
ret
mov    0x2ea8(%rip),%rcx
mov    $0x2,%eax
test   %edi,(%rcx)
jne    1110 <epoll_event_to_fd_event+0x10>
mov    0x2ea0(%rip),%rcx
test   %edi,(%rcx)
jne    1110 <epoll_event_to_fd_event+0x10>
mov    0x2eb5(%rip),%rax
xor    %ecx,%ecx
test   %edi,(%rax)
setne  %cl
mov    0x2e8f(%rip),%rax
test   %edi,(%rax)
lea    0x0(,%rcx,4),%edx
lea    0x8(,%rcx,4),%eax
cmove  %edx,%eax
ret

LLVM IR (-O0):
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@EPOLLRDHUP = global i32 0
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
define i32 @epoll_event_to_fd_event(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* @EPOLLERR
%6 = and i32 %4, %5
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 1, i32* %3
br label %38
9: ; preds = %1
%10 = load i32, i32* %2
%11 = load i32, i32* @EPOLLHUP
%12 = and i32 %10, %11
%13 = icmp ne i32 %12, 0
br i1 %13, label %19, label %14
14: ; preds = %9
%15 = load i32, i32* %2
%16 = load i32, i32* @EPOLLRDHUP
%17 = and i32 %15, %16
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %14, %9
store i32 2, i32* %3
br label %37
20: ; preds = %14
%21 = load i32, i32* %2
%22 = load i32, i32* @EPOLLIN
%23 = and i32 %21, %22
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i32, i32* %3
%27 = or i32 %26, 4
store i32 %27, i32* %3
br label %28
28: ; preds = %25, %20
%29 = load i32, i32* %2
%30 = load i32, i32* @EPOLLOUT
%31 = and i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = load i32, i32* %3
%35 = or i32 %34, 8
store i32 %35, i32* %3
br label %36
36: ; preds = %33, %28
br label %37
37: ; preds = %36, %19
br label %38
38: ; preds = %37, %8
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@EPOLLRDHUP = global i32 0
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
define i32 @epoll_event_to_fd_event(i32 %0) {
%2 = load i32, i32* @EPOLLERR
%3 = and i32 %2, %0
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %23
5: ; preds = %1
%6 = load i32, i32* @EPOLLHUP
%7 = and i32 %6, %0
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = load i32, i32* @EPOLLRDHUP
%11 = and i32 %10, %0
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = load i32, i32* @EPOLLIN
%15 = and i32 %14, %0
%16 = icmp eq i32 %15, 0
%17 = select i1 %16, i32 0, i32 4
%18 = load i32, i32* @EPOLLOUT
%19 = and i32 %18, %0
%20 = icmp eq i32 %19, 0
%21 = or i32 %17, 8
%22 = select i1 %20, i32 %17, i32 %21
br label %23
23: ; preds = %13, %5, %9, %1
%24 = phi i32 [ 1, %1 ], [ 2, %9 ], [ 2, %5 ], [ %22, %13 ]
ret i32 %24
}