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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ SIGTERM;
int pselect(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
            int /*<<< orphan*/ *, struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int main(void) {
  static fd_set rfds, wfds;
  struct timespec ts;
  sigset_t sigmask;
  FD_ZERO(&rfds);
  FD_ZERO(&wfds);
  FD_SET(0, &rfds);
  FD_SET(1, &wfds);
  FD_SET(2, &wfds);
  ts.tv_sec = 1;
  ts.tv_nsec = 999999999;
  (void)sigemptyset(&sigmask);
  (void)sigaddset(&sigmask, SIGTERM);
  return pselect(3, &rfds, &wfds, NULL, &ts, &sigmask);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0x2ee6(%rip),%rdi
call   1050 <FD_ZERO@plt>
lea    0x2ede(%rip),%rdi
call   1050 <FD_ZERO@plt>
xor    %edi,%edi
lea    0x2ecc(%rip),%rsi
call   1060 <FD_SET@plt>
mov    $0x1,%edi
lea    0x2ebf(%rip),%rsi
call   1060 <FD_SET@plt>
mov    $0x2,%edi
lea    0x2eae(%rip),%rsi
call   1060 <FD_SET@plt>
movl   $0x1,-0x10(%rbp)
movl   $0x3b9ac9ff,-0xc(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
lea    -0x14(%rbp),%rdi
call   1070 <sigaddset@plt>
mov    $0x3,%edi
lea    0x2e70(%rip),%rsi
lea    0x2e6d(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
lea    -0x14(%rbp),%r9
call   1030 <pselect@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x2eec(%rip),%r14
mov    %r14,%rdi
call   1050 <FD_ZERO@plt>
lea    0x2ee1(%rip),%r15
mov    %r15,%rdi
call   1050 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
mov    $0x1,%edi
mov    %r15,%rsi
call   1060 <FD_SET@plt>
mov    $0x2,%edi
mov    %r15,%rsi
call   1060 <FD_SET@plt>
movabs $0x3b9ac9ff00000001,%rax
c9 9a 3b
mov    %rax,(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1070 <sigaddset@plt>
mov    %rsp,%r8
mov    $0x3,%edi
mov    %r14,%rsi
mov    %r15,%rdx
xor    %ecx,%ecx
mov    %rbx,%r9
call   1030 <pselect@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@main.rfds = internal global i32 0
@main.wfds = internal global i32 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @FD_ZERO(i32* @main.rfds)
%5 = call i32 @FD_ZERO(i32* @main.wfds)
%6 = call i32 @FD_SET(i32 0, i32* @main.rfds)
%7 = call i32 @FD_SET(i32 1, i32* @main.wfds)
%8 = call i32 @FD_SET(i32 2, i32* @main.wfds)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i32 1, i32* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
store i32 999999999, i32* %10
%11 = call i32 @sigemptyset(i32* %3)
%12 = load i32, i32* @SIGTERM
%13 = call i32 @sigaddset(i32* %3, i32 %12)
%14 = call i32 @pselect(i32 3, i32* @main.rfds, i32* @main.wfds, i32* null, %struct.timespec* %2, i32* %3)
ret i32 %14
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@main.rfds = internal global i32 0
@main.wfds = internal global i32 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @FD_ZERO(i32* @main.rfds)
%6 = tail call i32 @FD_ZERO(i32* @main.wfds)
%7 = tail call i32 @FD_SET(i32 0, i32* @main.rfds)
%8 = tail call i32 @FD_SET(i32 1, i32* @main.wfds)
%9 = tail call i32 @FD_SET(i32 2, i32* @main.wfds)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 1, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 999999999, i32* %11
%12 = call i32 @sigemptyset(i32* %2)
%13 = load i32, i32* @SIGTERM
%14 = call i32 @sigaddset(i32* %2, i32 %13)
%15 = call i32 @pselect(i32 3, i32* @main.rfds, i32* @main.wfds, i32* null, %struct.timespec* %1, i32* %2)
ret i32 %15
}