#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 /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ sigset_t;
typedef scalar_t__ int32_t;
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ pselect(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   int /*<<< orphan*/ *, struct timespec *,
                   int /*<<< orphan*/ *);
int /*<<< orphan*/ sec2nanosec(double);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void set_pselect(int32_t max_evtfd, fd_set *p_evtfd_set) {
  sigset_t sigset;
  sigemptyset(&sigset);
  sigaddset(&sigset, SIGINT);
  struct timespec ts = {0};
  ts.tv_nsec = sec2nanosec(0.5);
  int32_t ret = pselect(max_evtfd + 1, p_evtfd_set, NULL, NULL, &ts, &sigset);
  if (ret < 0) {
    fprintf(stderr, "pselect() failed\n");
  }
}


x86 assembly (clang, -O0):
<set_pselect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1070 <sigemptyset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1080 <sigaddset@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movsd  0xe5d(%rip),%xmm0
call   1050 <sec2nanosec@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
add    $0x1,%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
lea    -0x14(%rbp),%r9
mov    %rcx,%rdx
call   1030 <pselect@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    11ef <set_pselect+0x8f>
mov    0x2df7(%rip),%rax
mov    (%rax),%edi
lea    0xe1e(%rip),%rsi
call   1060 <fprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_pselect>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1060 <sigemptyset@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   1070 <sigaddset@plt>
movq   $0x0,(%rsp)
movsd  0xe73(%rip),%xmm0
call   1040 <sec2nanosec@plt>
mov    %eax,(%rsp)
add    $0x1,%rbx
mov    %rsp,%r8
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %r15,%r9
call   1030 <pselect@plt>
test   %rax,%rax
jns    11c8 <set_pselect+0x78>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe45(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"pselect() failed\0A\00"
define void @set_pselect(i64 %0, i32* %1) {
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32
%6 = alloca %struct.timespec
%7 = alloca i64
store i64 %0, i64* %3
store i32* %1, i32** %4
%8 = call i32 @sigemptyset(i32* %5)
%9 = load i32, i32* @SIGINT
%10 = call i32 @sigaddset(i32* %5, i32 %9)
%11 = bitcast %struct.timespec* %6 to i8*
%12 = call i32 @sec2nanosec(double 5.000000e-01)
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i64, i64* %3
%15 = add nsw i64 %14, 1
%16 = load i32*, i32** %4
%17 = call i64 @pselect(i64 %15, i32* %16, i32* null, i32* null, %struct.timespec* %6, i32* %5)
store i64 %17, i64* %7
%18 = load i64, i64* %7
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %20, %2
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@SIGINT = global i32 0
@stderr = global i32 0
@.str = [18 x i8] c"pselect() failed\0A\00"
define void @set_pselect(i64 %0, i32* %1) {
%3 = alloca i32
%4 = alloca i64
%5 = bitcast i64* %4 to %struct.timespec*
%6 = bitcast i32* %3 to i8*
%7 = call i32 @sigemptyset(i32* %3)
%8 = load i32, i32* @SIGINT
%9 = call i32 @sigaddset(i32* %3, i32 %8)
%10 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%11 = call i32 @sec2nanosec(double 5.000000e-01)
%12 = bitcast i64* %4 to i32*
store i32 %11, i32* %12
%13 = add nsw i64 %0, 1
%14 = call i64 @pselect(i64 %13, i32* %1, i32* null, i32* null, %struct.timespec* %5, i32* %3)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %16, %2
ret void
}