#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_nsec;
  int /*<<< orphan*/ tv_sec;
};
struct pollfd {
  int fd;
  int events;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ fds;

/* Variables and functions */
int POLLIN;
int POLLOUT;
int POLLPRI;
int POLLRDBAND;
int POLLRDNORM;
int POLLWRBAND;
int POLLWRNORM;
int /*<<< orphan*/ SIGHUP;
int /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ SIGSTOP;
scalar_t__ ppoll(struct pollfd *, int, struct timespec const *,
                 int /*<<< orphan*/ *);
int /*<<< orphan*/ sigdelset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigfillset(int /*<<< orphan*/ *);
int test2(void) {
  sigset_t mask;
  const struct timespec timeout = {.tv_sec = 0, .tv_nsec = 999};
  struct pollfd fds[] = {
      {.fd = 1, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND},
      {.fd = 0, .events = POLLOUT | POLLWRNORM | POLLWRBAND}};
  sigfillset(&mask);
  sigdelset(&mask, SIGHUP);
  sigdelset(&mask, SIGKILL);
  sigdelset(&mask, SIGSTOP);
  return ppoll(fds, sizeof(fds) / sizeof(*fds), &timeout, &mask) == 0 ? 0 : 77;
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    0x2e86(%rip),%rcx
or     (%rcx),%eax
mov    0x2e65(%rip),%rcx
or     (%rcx),%eax
mov    0x2e3c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e50(%rip),%rcx
or     (%rcx),%eax
mov    0x2dff(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x14(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <sigfillset@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigdelset@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigdelset@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigdelset@plt>
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
lea    -0x10(%rbp),%rdx
lea    -0x4(%rbp),%rcx
call   1030 <ppoll@plt>
mov    %rax,%rdx
mov    $0x4d,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %rbx
sub    $0x20,%rsp
mov    0x2e84(%rip),%rax
mov    0x2e9d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e7a(%rip),%rax
or     (%rax),%ecx
movq   $0x3e7,0x10(%rsp)
mov    0x2e48(%rip),%rax
or     (%rax),%ecx
movl   $0x1,(%rsp)
mov    %ecx,0x4(%rsp)
movl   $0x0,0x8(%rsp)
mov    0x2e7c(%rip),%rax
mov    0x2e55(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e02(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0xc(%rsp)
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigfillset@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigdelset@plt>
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigdelset@plt>
mov    0x2dd6(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigdelset@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rdx
mov    $0x2,%esi
mov    %rbx,%rcx
call   1030 <ppoll@plt>
xor    %ecx,%ecx
test   %rax,%rax
mov    $0x4d,%eax
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.pollfd = type { i32, i32 }
@__const.test2.timeout = %struct.timespec { i32 999, i32 0 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
@POLLRDNORM = global i32 0
@POLLRDBAND = global i32 0
@POLLOUT = global i32 0
@POLLWRNORM = global i32 0
@POLLWRBAND = global i32 0
@SIGHUP = global i32 0
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
define i32 @test2() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca [2 x %struct.pollfd]
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 0
store i32 1, i32* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 1
%8 = load i32, i32* @POLLIN
%9 = load i32, i32* @POLLPRI
%10 = or i32 %8, %9
%11 = load i32, i32* @POLLRDNORM
%12 = or i32 %10, %11
%13 = load i32, i32* @POLLRDBAND
%14 = or i32 %12, %13
store i32 %14, i32* %7
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i64 1
%16 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %15, i32 0, i32 0
store i32 0, i32* %16
%17 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %15, i32 0, i32 1
%18 = load i32, i32* @POLLOUT
%19 = load i32, i32* @POLLWRNORM
%20 = or i32 %18, %19
%21 = load i32, i32* @POLLWRBAND
%22 = or i32 %20, %21
store i32 %22, i32* %17
%23 = call i32 @sigfillset(i32* %1)
%24 = load i32, i32* @SIGHUP
%25 = call i32 @sigdelset(i32* %1, i32 %24)
%26 = load i32, i32* @SIGKILL
%27 = call i32 @sigdelset(i32* %1, i32 %26)
%28 = load i32, i32* @SIGSTOP
%29 = call i32 @sigdelset(i32* %1, i32 %28)
%30 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %3, i64 0, i64 0
%31 = call i64 @ppoll(%struct.pollfd* %30, i32 2, %struct.timespec* %2, i32* %1)
%32 = icmp eq i64 %31, 0
%33 = zext i1 %32 to i64
%34 = select i1 %32, i32 0, i32 77
ret i32 %34
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.pollfd = type { i32, i32 }
@POLLIN = global i32 0
@POLLPRI = global i32 0
@POLLRDNORM = global i32 0
@POLLRDBAND = global i32 0
@POLLOUT = global i32 0
@POLLWRNORM = global i32 0
@POLLWRBAND = global i32 0
@SIGHUP = global i32 0
@SIGKILL = global i32 0
@SIGSTOP = global i32 0
define i32 @test2() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = alloca [2 x %struct.pollfd]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i64* %2 to i8*
store i64 999, i64* %2
%7 = bitcast [2 x %struct.pollfd]* %4 to i8*
%8 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%9 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 1, i32* %9
%10 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0, i32 1
%11 = load i32, i32* @POLLIN
%12 = load i32, i32* @POLLPRI
%13 = or i32 %12, %11
%14 = load i32, i32* @POLLRDNORM
%15 = or i32 %13, %14
%16 = load i32, i32* @POLLRDBAND
%17 = or i32 %15, %16
store i32 %17, i32* %10
%18 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
store i32 0, i32* %18
%19 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1, i32 1
%20 = load i32, i32* @POLLOUT
%21 = load i32, i32* @POLLWRNORM
%22 = or i32 %21, %20
%23 = load i32, i32* @POLLWRBAND
%24 = or i32 %22, %23
store i32 %24, i32* %19
%25 = call i32 @sigfillset(i32* %1)
%26 = load i32, i32* @SIGHUP
%27 = call i32 @sigdelset(i32* %1, i32 %26)
%28 = load i32, i32* @SIGKILL
%29 = call i32 @sigdelset(i32* %1, i32 %28)
%30 = load i32, i32* @SIGSTOP
%31 = call i32 @sigdelset(i32* %1, i32 %30)
%32 = call i64 @ppoll(%struct.pollfd* %8, i32 2, %struct.timespec* %3, i32* %1)
%33 = icmp eq i64 %32, 0
%34 = select i1 %33, i32 0, i32 77
ret i32 %34
}