#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;
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int O_ACCMODE;
int O_RDONLY;
int O_WRONLY;
int native_pcm_select_prepare(int fd, int fmode, fd_set *readfds,
                              fd_set *writefds, fd_set *exceptfds) {
  if (fd < 0)
    return -EINVAL;
  if ((fmode & O_ACCMODE) != O_WRONLY && readfds) {
    FD_SET(fd, readfds);
    if (exceptfds)
      FD_SET(fd, exceptfds);
  }
  if ((fmode & O_ACCMODE) != O_RDONLY && writefds) {
    FD_SET(fd, writefds);
    if (exceptfds)
      FD_SET(fd, exceptfds);
  }
  return fd;
}


x86 assembly (clang, -O0):
<native_pcm_select_prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1147 <native_pcm_select_prepare+0x37>
xor    %eax,%eax
mov    0x2e93(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e9 <native_pcm_select_prepare+0xd9>
mov    -0xc(%rbp),%eax
mov    0x2e9f(%rip),%rcx
and    (%rcx),%eax
mov    0x2e66(%rip),%rcx
cmp    (%rcx),%eax
je     1195 <native_pcm_select_prepare+0x85>
cmpq   $0x0,-0x18(%rbp)
je     1195 <native_pcm_select_prepare+0x85>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   1030 <FD_SET@plt>
cmpq   $0x0,-0x28(%rbp)
je     1190 <native_pcm_select_prepare+0x80>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <FD_SET@plt>
jmp    1195 <native_pcm_select_prepare+0x85>
mov    -0xc(%rbp),%eax
mov    0x2e51(%rip),%rcx
and    (%rcx),%eax
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%eax
je     11e3 <native_pcm_select_prepare+0xd3>
cmpq   $0x0,-0x20(%rbp)
je     11e3 <native_pcm_select_prepare+0xd3>
mov    -0x8(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   1030 <FD_SET@plt>
cmpq   $0x0,-0x28(%rbp)
je     11de <native_pcm_select_prepare+0xce>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1030 <FD_SET@plt>
jmp    11e3 <native_pcm_select_prepare+0xd3>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<native_pcm_select_prepare>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %edi,%edi
js     118b <native_pcm_select_prepare+0x7b>
mov    %r8,%r14
mov    %rcx,%r15
mov    %esi,%ebp
mov    %edi,%ebx
mov    0x2ec3(%rip),%r12
test   %rdx,%rdx
je     115c <native_pcm_select_prepare+0x4c>
mov    (%r12),%eax
and    %ebp,%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
je     115c <native_pcm_select_prepare+0x4c>
mov    %ebx,%edi
mov    %rdx,%rsi
call   1030 <FD_SET@plt>
test   %r14,%r14
je     115c <native_pcm_select_prepare+0x4c>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <FD_SET@plt>
test   %r15,%r15
je     1196 <native_pcm_select_prepare+0x86>
and    (%r12),%ebp
mov    0x2e74(%rip),%rax
cmp    (%rax),%ebp
je     1196 <native_pcm_select_prepare+0x86>
mov    %ebx,%edi
mov    %r15,%rsi
call   1030 <FD_SET@plt>
test   %r14,%r14
je     1196 <native_pcm_select_prepare+0x86>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <FD_SET@plt>
jmp    1196 <native_pcm_select_prepare+0x86>
mov    0x2e3e(%rip),%rax
xor    %ebx,%ebx
sub    (%rax),%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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