#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int _error(char const *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, char *);
scalar_t__ pselect(int /*<<< orphan*/, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   struct timespec *, int /*<<< orphan*/ *);
int _pselect(char const *progname) {
  fd_set rfds;
  fd_set wfds;
  fd_set efds;
  struct timespec timeout;
  printf("%s: Testing %s()\n", progname, "pselect");
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_ZERO(&efds);
  timeout.tv_sec = 0;
  timeout.tv_nsec = 0;
  if (pselect(0, &rfds, &wfds, &efds, &timeout, NULL) != 0)
    return _error(progname, "pselect", 2);
  return 0;
}


x86 assembly (clang, -O0):
<_pselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xea9(%rip),%rdi
lea    0xeb4(%rip),%rdx
call   1040 <printf@plt>
lea    -0x14(%rbp),%rdi
call   1050 <FD_ZERO@plt>
lea    -0x18(%rbp),%rdi
call   1050 <FD_ZERO@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <FD_ZERO@plt>
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x30(%rbp),%r8
xor    %eax,%eax
mov    %eax,%r9d
call   1030 <pselect@plt>
cmp    $0x0,%rax
je     11d1 <_pselect+0x91>
mov    -0x10(%rbp),%rdi
lea    0xe53(%rip),%rsi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11d8 <_pselect+0x98>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pselect>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%r14
lea    0xea9(%rip),%rdi
lea    0xeb4(%rip),%rdx
mov    %r14,%rsi
call   1040 <printf@plt>
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1050 <FD_ZERO@plt>
lea    0x8(%rsp),%r12
mov    %r12,%rdi
call   1050 <FD_ZERO@plt>
lea    0x4(%rsp),%r13
mov    %r13,%rdi
call   1050 <FD_ZERO@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
xor    %ebx,%ebx
lea    0x10(%rsp),%r8
xor    %edi,%edi
mov    %r15,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
xor    %r9d,%r9d
call   1030 <pselect@plt>
test   %rax,%rax
je     11ca <_pselect+0x8a>
lea    0xe57(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [18 x i8] c"%s: Testing %s()\0A\00"
@.str.1 = [8 x i8] c"pselect\00"
define i32 @_pselect(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timespec
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @FD_ZERO(i32* %4)
%11 = call i32 @FD_ZERO(i32* %5)
%12 = call i32 @FD_ZERO(i32* %6)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store i64 0, i64* %14
%15 = call i64 @pselect(i32 0, i32* %4, i32* %5, i32* %6, %struct.timespec* %7, i32* null)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i32 @_error(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2)
store i32 %19, i32* %2
br label %21
20: ; preds = %1
store i32 0, i32* %2
br label %21
21: ; preds = %20, %17
%22 = load i32, i32* %2
ret i32 %22
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [18 x i8] c"%s: Testing %s()\0A\00"
@.str.1 = [8 x i8] c"pselect\00"
define i32 @_pselect(i8* %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timespec
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast %struct.timespec* %5 to i8*
%10 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @FD_ZERO(i32* %2)
%12 = call i32 @FD_ZERO(i32* %3)
%13 = call i32 @FD_ZERO(i32* %4)
%14 = bitcast %struct.timespec* %5 to i8*
%15 = call i64 @pselect(i32 0, i32* %2, i32* %3, i32* %4, %struct.timespec* %5, i32* null)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %1
%18 = call i32 @_error(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %19
19: ; preds = %1, %17
%20 = phi i32 [ %18, %17 ], [ 0, %1 ]
ret i32 %20
}