#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 unsigned int time_t;
struct timespec {
  unsigned int tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int _error(char const *, char *, int);
int /*<<< orphan*/ printf(char *, char const *, char *, unsigned int);
scalar_t__ pselect(int /*<<< orphan*/, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   struct timespec *, int /*<<< orphan*/ *);
unsigned int time(int /*<<< orphan*/ *);
int _pselect2(char const *progname, unsigned int t) {
  struct timespec timeout;
  time_t before;
  time_t after;
  printf("%s: Testing %s() (sleeping %us)\n", progname, "pselect2", t);
  timeout.tv_sec = t;
  timeout.tv_nsec = 0;
  before = time(NULL);
  if (pselect(0, NULL, NULL, NULL, &timeout, NULL) != 0)
    return _error(progname, "pselect", 2);
  after = time(NULL);
  return (after - before == t) ? 0 : 2;
}


x86 assembly (clang, -O0):
<_pselect2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xea3(%rip),%rdi
lea    0xebd(%rip),%rdx
call   1040 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x2c(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%r9d
lea    -0x28(%rbp),%r8
mov    %r9,%rsi
mov    %r9,%rdx
mov    %r9,%rcx
call   1030 <pselect@plt>
cmp    $0x0,%rax
je     11c3 <_pselect2+0x83>
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
mov    $0x2,%edx
call   1060 <_error@plt>
mov    %eax,-0x4(%rbp)
jmp    11e7 <_pselect2+0xa7>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edx
sub    -0x2c(%rbp),%edx
mov    -0x14(%rbp),%esi
mov    $0x2,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pselect2>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
lea    0xeac(%rip),%rdi
lea    0xec6(%rip),%rdx
mov    %r14,%rsi
mov    %ebx,%ecx
call   1040 <printf@plt>
mov    %ebx,(%rsp)
movq   $0x0,0x8(%rsp)
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%ebp
mov    %rsp,%r8
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r9d,%r9d
call   1030 <pselect@plt>
test   %rax,%rax
je     11a8 <_pselect2+0x68>
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
mov    $0x2,%edx
call   1060 <_error@plt>
jmp    11bc <_pselect2+0x7c>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%ecx
sub    %ebp,%ecx
xor    %eax,%eax
cmp    %ebx,%ecx
setne  %al
add    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@.str = [33 x i8] c"%s: Testing %s() (sleeping %us)\0A\00"
@.str.1 = [9 x i8] c"pselect2\00"
@.str.2 = [8 x i8] c"pselect\00"
define i32 @_pselect2(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.timespec
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i8*, i8** %4
%10 = load i32, i32* %5
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %5
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
store i64 0, i64* %14
%15 = call i32 @time(i32* null)
store i32 %15, i32* %7
%16 = call i64 @pselect(i32 0, i32* null, i32* null, i32* null, %struct.timespec* %6, i32* null)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i8*, i8** %4
%20 = call i32 @_error(i8* %19, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i32 2)
store i32 %20, i32* %3
br label %30
21: ; preds = %2
%22 = call i32 @time(i32* null)
store i32 %22, i32* %8
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = sub i32 %23, %24
%26 = load i32, i32* %5
%27 = icmp eq i32 %25, %26
%28 = zext i1 %27 to i64
%29 = select i1 %27, i32 0, i32 2
store i32 %29, i32* %3
br label %30
30: ; preds = %21, %18
%31 = load i32, i32* %3
ret i32 %31
}

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