#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 */
short POLLHUP;
short POLLIN;
short POLLOUT;
short POLLPRI;
short POLLWRBAND;
int pollfd_events_to_chan_flags(short pollfd_events) {
  int flags = 0;
  if ((pollfd_events & (POLLIN | POLLPRI)) != 0)
    flags |= (1 << 0);
  if ((pollfd_events & POLLHUP) != 0)
    flags |= (1 << 2);
  if ((pollfd_events & (POLLOUT | POLLWRBAND)) != 0)
    flags |= (1 << 1);
  return flags;
}


x86 assembly (clang, -O0):
<pollfd_events_to_chan_flags>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movl   $0x0,-0x8(%rbp)
movswl -0x2(%rbp),%eax
mov    0x2eb3(%rip),%rcx
movswl (%rcx),%ecx
mov    0x2ec1(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1140 <pollfd_events_to_chan_flags+0x40>
mov    -0x8(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x8(%rbp)
movswl -0x2(%rbp),%eax
mov    0x2e8d(%rip),%rcx
movswl (%rcx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1162 <pollfd_events_to_chan_flags+0x62>
mov    -0x8(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x8(%rbp)
movswl -0x2(%rbp),%eax
mov    0x2e8b(%rip),%rcx
movswl (%rcx),%ecx
mov    0x2e41(%rip),%rdx
movswl (%rdx),%edx
or     %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1190 <pollfd_events_to_chan_flags+0x90>
mov    -0x8(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<pollfd_events_to_chan_flags>:
mov    0x2ec9(%rip),%rax
mov    0x2eda(%rip),%rcx
movzwl (%rcx),%ecx
or     (%rax),%cx
xor    %eax,%eax
test   %di,%cx
setne  %al
mov    0x2eb5(%rip),%rcx
test   %di,(%rcx)
lea    0x4(%rax),%ecx
cmove  %eax,%ecx
mov    0x2ec5(%rip),%rax
mov    0x2e7e(%rip),%rdx
movzwl (%rdx),%edx
or     (%rax),%dx
lea    0x2(%rcx),%eax
test   %di,%dx
cmove  %ecx,%eax
ret

LLVM IR (-O0):
@POLLIN = global i16 0
@POLLPRI = global i16 0
@POLLHUP = global i16 0
@POLLOUT = global i16 0
@POLLWRBAND = global i16 0
define i32 @pollfd_events_to_chan_flags(i16 signext %0) {
%2 = alloca i16
%3 = alloca i32
store i16 %0, i16* %2
store i32 0, i32* %3
%4 = load i16, i16* %2
%5 = sext i16 %4 to i32
%6 = load i16, i16* @POLLIN
%7 = sext i16 %6 to i32
%8 = load i16, i16* @POLLPRI
%9 = sext i16 %8 to i32
%10 = or i32 %7, %9
%11 = and i32 %5, %10
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %1
%14 = load i32, i32* %3
%15 = or i32 %14, 1
store i32 %15, i32* %3
br label %16
16: ; preds = %13, %1
%17 = load i16, i16* %2
%18 = sext i16 %17 to i32
%19 = load i16, i16* @POLLHUP
%20 = sext i16 %19 to i32
%21 = and i32 %18, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %16
%24 = load i32, i32* %3
%25 = or i32 %24, 4
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %16
%27 = load i16, i16* %2
%28 = sext i16 %27 to i32
%29 = load i16, i16* @POLLOUT
%30 = sext i16 %29 to i32
%31 = load i16, i16* @POLLWRBAND
%32 = sext i16 %31 to i32
%33 = or i32 %30, %32
%34 = and i32 %28, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %26
%37 = load i32, i32* %3
%38 = or i32 %37, 2
store i32 %38, i32* %3
br label %39
39: ; preds = %36, %26
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@POLLIN = global i16 0
@POLLPRI = global i16 0
@POLLHUP = global i16 0
@POLLOUT = global i16 0
@POLLWRBAND = global i16 0
define i32 @pollfd_events_to_chan_flags(i16 signext %0) {
%2 = load i16, i16* @POLLIN
%3 = load i16, i16* @POLLPRI
%4 = or i16 %3, %2
%5 = and i16 %4, %0
%6 = icmp ne i16 %5, 0
%7 = zext i1 %6 to i32
%8 = load i16, i16* @POLLHUP
%9 = and i16 %8, %0
%10 = icmp eq i16 %9, 0
%11 = or i32 %7, 4
%12 = select i1 %10, i32 %7, i32 %11
%13 = load i16, i16* @POLLOUT
%14 = load i16, i16* @POLLWRBAND
%15 = or i16 %14, %13
%16 = and i16 %15, %0
%17 = icmp eq i16 %16, 0
%18 = or i32 %12, 2
%19 = select i1 %17, i32 %12, i32 %18
ret i32 %19
}