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

/* Variables and functions */
int EINVAL;
scalar_t__ FD_ISSET(int, int /*<<< orphan*/ *);
int native_pcm_select_result(int fd, fd_set *readfds, fd_set *writefds,
                             fd_set *exceptfds) {
  int result = 0;
  if (fd < 0)
    return -EINVAL;
  if (readfds && FD_ISSET(fd, readfds))
    result |= (1 << 0);
  if (writefds && FD_ISSET(fd, writefds))
    result |= (1 << 1);
  if (exceptfds && FD_ISSET(fd, exceptfds))
    result |= (1 << 2);
  return result;
}


x86 assembly (clang, -O0):
<native_pcm_select_result>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    114b <native_pcm_select_result+0x3b>
xor    %eax,%eax
mov    0x2e9f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11cf <native_pcm_select_result+0xbf>
cmpq   $0x0,-0x10(%rbp)
je     1175 <native_pcm_select_result+0x65>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     1175 <native_pcm_select_result+0x65>
mov    -0x24(%rbp),%eax
or     $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     119f <native_pcm_select_result+0x8f>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     119f <native_pcm_select_result+0x8f>
mov    -0x24(%rbp),%eax
or     $0x2,%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c9 <native_pcm_select_result+0xb9>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11c9 <native_pcm_select_result+0xb9>
mov    -0x24(%rbp),%eax
or     $0x4,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<native_pcm_select_result>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
js     116d <native_pcm_select_result+0x5d>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %edi,%ebp
test   %rsi,%rsi
je     1185 <native_pcm_select_result+0x75>
mov    %ebp,%edi
call   1030 <FD_ISSET@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
test   %r15,%r15
je     1151 <native_pcm_select_result+0x41>
mov    %ebp,%edi
mov    %r15,%rsi
call   1030 <FD_ISSET@plt>
lea    0x2(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
test   %r14,%r14
je     1178 <native_pcm_select_result+0x68>
mov    %ebp,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
lea    0x4(%rbx),%ecx
test   %rax,%rax
cmove  %ebx,%ecx
mov    %ecx,%ebx
jmp    1178 <native_pcm_select_result+0x68>
mov    0x2e6c(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
test   %r15,%r15
jne    113c <native_pcm_select_result+0x2c>
jmp    1151 <native_pcm_select_result+0x41>

LLVM IR (-O0):
@EINVAL = global i32 0
define i32 @native_pcm_select_result(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
store i32 0, i32* %10
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %4
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
store i32 %15, i32* %5
br label %51
16: ; preds = %4
%17 = load i32*, i32** %7
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %27
19: ; preds = %16
%20 = load i32, i32* %6
%21 = load i32*, i32** %7
%22 = call i64 @FD_ISSET(i32 %20, i32* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %10
%26 = or i32 %25, 1
store i32 %26, i32* %10
br label %27
27: ; preds = %24, %19, %16
%28 = load i32*, i32** %8
%29 = icmp ne i32* %28, null
br i1 %29, label %30, label %38
30: ; preds = %27
%31 = load i32, i32* %6
%32 = load i32*, i32** %8
%33 = call i64 @FD_ISSET(i32 %31, i32* %32)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i32, i32* %10
%37 = or i32 %36, 2
store i32 %37, i32* %10
br label %38
38: ; preds = %35, %30, %27
%39 = load i32*, i32** %9
%40 = icmp ne i32* %39, null
br i1 %40, label %41, label %49
41: ; preds = %38
%42 = load i32, i32* %6
%43 = load i32*, i32** %9
%44 = call i64 @FD_ISSET(i32 %42, i32* %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %41
%47 = load i32, i32* %10
%48 = or i32 %47, 4
store i32 %48, i32* %10
br label %49
49: ; preds = %46, %41, %38
%50 = load i32, i32* %10
store i32 %50, i32* %5
br label %51
51: ; preds = %49, %13
%52 = load i32, i32* %5
ret i32 %52
}

LLVM IR (-O2):
@EINVAL = global i32 0
define i32 @native_pcm_select_result(i32 %0, i32* %1, i32* %2, i32* %3) {
%5 = icmp slt i32 %0, 0
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
br label %31
9: ; preds = %4
%10 = icmp eq i32* %1, null
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = tail call i64 @FD_ISSET(i32 %0, i32* %1)
%13 = icmp ne i64 %12, 0
%14 = zext i1 %13 to i32
br label %15
15: ; preds = %11, %9
%16 = phi i32 [ 0, %9 ], [ %14, %11 ]
%17 = icmp eq i32* %2, null
br i1 %17, label %23, label %18
18: ; preds = %15
%19 = tail call i64 @FD_ISSET(i32 %0, i32* %2)
%20 = icmp eq i64 %19, 0
%21 = or i32 %16, 2
%22 = select i1 %20, i32 %16, i32 %21
br label %23
23: ; preds = %18, %15
%24 = phi i32 [ %16, %15 ], [ %22, %18 ]
%25 = icmp eq i32* %3, null
br i1 %25, label %31, label %26
26: ; preds = %23
%27 = tail call i64 @FD_ISSET(i32 %0, i32* %3)
%28 = icmp eq i64 %27, 0
%29 = or i32 %24, 4
%30 = select i1 %28, i32 %24, i32 %29
br label %31
31: ; preds = %26, %23, %6
%32 = phi i32 [ %8, %6 ], [ %24, %23 ], [ %30, %26 ]
ret i32 %32
}