#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 */
struct timespec {
  int dummy;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int _NSIG;
int syscall_cp(int, int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
               int /*<<< orphan*/ *, struct timespec *, long *);
int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds,
            fd_set *restrict efds, const struct timespec *restrict ts,
            const sigset_t *restrict mask) {
  long data[2] = {(long)mask, _NSIG / 8};
  struct timespec ts_tmp;
  if (ts)
    ts_tmp = *ts;
  return syscall_cp(335, n, rfds, wfds, efds, ts ? &ts_tmp : 0, data);
}


x86 assembly (clang, -O0):
<pselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2eaf(%rip),%rax
mov    (%rax),%eax
mov    $0x8,%ecx
cltd
idiv   %ecx
cltq
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1165 <pselect+0x55>
mov    -0x28(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     119b <pselect+0x8b>
lea    -0x48(%rbp),%rax
mov    %rax,-0x70(%rbp)
jmp    11a6 <pselect+0x96>
xor    %eax,%eax
mov    %rax,-0x70(%rbp)
jmp    11a6 <pselect+0x96>
mov    -0x50(%rbp),%r8
mov    -0x58(%rbp),%rcx
mov    -0x60(%rbp),%rdx
mov    -0x64(%rbp),%esi
mov    -0x70(%rbp),%r9
lea    -0x40(%rbp),%rax
mov    $0x14f,%edi
mov    %rax,(%rsp)
call   1030 <syscall_cp@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pselect>:
sub    $0x28,%rsp
mov    %rcx,%r10
mov    %rdx,%rcx
mov    %rsi,%rdx
mov    %edi,%esi
mov    %r9,0x10(%rsp)
mov    0x2ec5(%rip),%rdi
mov    (%rdi),%edi
lea    0x7(%rdi),%eax
test   %edi,%edi
cmovns %edi,%eax
sar    $0x3,%eax
cltq
mov    %rax,0x18(%rsp)
test   %r8,%r8
je     1152 <pselect+0x42>
mov    (%r8),%eax
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%r9
jmp    1155 <pselect+0x45>
xor    %r9d,%r9d
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
mov    $0x14f,%edi
mov    %r10,%r8
call   1030 <syscall_cp@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
@_NSIG = global i32 0
define i32 @pselect(i32 %0, i32* noalias %1, i32* noalias %2, i32* noalias %3, %struct.timespec* noalias %4, i32* noalias %5) {
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca %struct.timespec*
%12 = alloca i32*
%13 = alloca [2 x i64]
%14 = alloca %struct.timespec
store i32 %0, i32* %7
store i32* %1, i32** %8
store i32* %2, i32** %9
store i32* %3, i32** %10
store %struct.timespec* %4, %struct.timespec** %11
store i32* %5, i32** %12
%15 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 0
%16 = load i32*, i32** %12
%17 = ptrtoint i32* %16 to i64
store i64 %17, i64* %15
%18 = getelementptr inbounds i64, i64* %15, i64 1
%19 = load i32, i32* @_NSIG
%20 = sdiv i32 %19, 8
%21 = sext i32 %20 to i64
store i64 %21, i64* %18
%22 = load %struct.timespec*, %struct.timespec** %11
%23 = icmp ne %struct.timespec* %22, null
br i1 %23, label %24, label %28
24: ; preds = %6
%25 = load %struct.timespec*, %struct.timespec** %11
%26 = bitcast %struct.timespec* %14 to i8*
%27 = bitcast %struct.timespec* %25 to i8*
br label %28
28: ; preds = %24, %6
%29 = load i32, i32* %7
%30 = load i32*, i32** %8
%31 = load i32*, i32** %9
%32 = load i32*, i32** %10
%33 = load %struct.timespec*, %struct.timespec** %11
%34 = icmp ne %struct.timespec* %33, null
br i1 %34, label %35, label %36
35: ; preds = %28
br label %37
36: ; preds = %28
br label %37
37: ; preds = %36, %35
%38 = phi %struct.timespec* [ %14, %35 ], [ null, %36 ]
%39 = getelementptr inbounds [2 x i64], [2 x i64]* %13, i64 0, i64 0
%40 = call i32 @syscall_cp(i32 335, i32 %29, i32* %30, i32* %31, i32* %32, %struct.timespec* %38, i64* %39)
ret i32 %40
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@_NSIG = global i32 0
define i32 @pselect(i32 %0, i32* noalias %1, i32* noalias %2, i32* noalias %3, %struct.timespec* noalias %4, i32* noalias %5) {
%7 = alloca [2 x i64]
%8 = alloca %struct.timespec
%9 = bitcast [2 x i64]* %7 to i8*
%10 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 0
%11 = ptrtoint i32* %5 to i64
store i64 %11, i64* %10
%12 = getelementptr inbounds [2 x i64], [2 x i64]* %7, i64 0, i64 1
%13 = load i32, i32* @_NSIG
%14 = sdiv i32 %13, 8
%15 = sext i32 %14 to i64
store i64 %15, i64* %12
%16 = bitcast %struct.timespec* %8 to i8*
%17 = icmp eq %struct.timespec* %4, null
br i1 %17, label %22, label %18
18: ; preds = %6
%19 = getelementptr %struct.timespec, %struct.timespec* %4, i64 0, i32 0
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%21 = load i32, i32* %19
store i32 %21, i32* %20
br label %22
22: ; preds = %18, %6
%23 = phi %struct.timespec* [ %8, %18 ], [ null, %6 ]
%24 = call i32 @syscall_cp(i32 335, i32 %0, i32* %1, i32* %2, i32* %3, %struct.timespec* %23, i64* %10)
ret i32 %24
}