#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;
};
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*/ SIGCHLD;
int /*<<< orphan*/ SIGUSR2;
int ppoll(struct pollfd *, int, struct timespec const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int test1(void) {
  sigset_t mask;
  const struct timespec timeout = {.tv_sec = 42, .tv_nsec = 999999999};
  struct pollfd fds[] = {
      {.fd = 0, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND},
      {.fd = 1, .events = POLLOUT | POLLWRNORM | POLLWRBAND},
      {.fd = 3, .events = POLLIN | POLLPRI},
      {.fd = 4, .events = POLLOUT}};
  sigemptyset(&mask);
  sigaddset(&mask, SIGUSR2);
  sigaddset(&mask, SIGCHLD);
  return ppoll(fds, sizeof(fds) / sizeof(*fds), &timeout, &mask) == 2 ? 0 : 77;
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0xec1(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x30(%rbp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%eax
mov    0x2e8e(%rip),%rcx
or     (%rcx),%eax
mov    0x2e6d(%rip),%rcx
or     (%rcx),%eax
mov    0x2e3c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x2c(%rbp)
movl   $0x1,-0x28(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    0x2e58(%rip),%rcx
or     (%rcx),%eax
mov    0x2e07(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x24(%rbp)
movl   $0x3,-0x20(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
mov    0x2e3b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x4,-0x18(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
lea    -0x4(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigaddset@plt>
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
lea    -0x4(%rbp),%rdi
call   1050 <sigaddset@plt>
lea    -0x30(%rbp),%rdi
mov    $0x4,%esi
lea    -0x10(%rbp),%rdx
lea    -0x4(%rbp),%rcx
call   1030 <ppoll@plt>
mov    %eax,%edx
mov    $0x4d,%eax
xor    %ecx,%ecx
cmp    $0x2,%edx
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rbx
sub    $0x30,%rsp
movabs $0x3b9ac9ff0000002a,%rax
c9 9a 3b
mov    %rax,0x20(%rsp)
mov    0x2e75(%rip),%rax
mov    0x2e96(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
or     %ecx,%eax
mov    0x2e40(%rip),%rdx
or     (%rdx),%eax
movl   $0x0,(%rsp)
mov    %eax,0x4(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2e74(%rip),%rax
mov    (%rax),%eax
mov    0x2e53(%rip),%rdx
mov    (%rdx),%edx
or     %eax,%edx
mov    0x2e00(%rip),%rsi
or     (%rsi),%edx
mov    %edx,0xc(%rsp)
movl   $0x3,0x10(%rsp)
mov    %ecx,0x14(%rsp)
movl   $0x4,0x18(%rsp)
mov    %eax,0x1c(%rsp)
lea    0x2c(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigaddset@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigaddset@plt>
mov    %rsp,%rdi
lea    0x20(%rsp),%rdx
mov    $0x4,%esi
mov    %rbx,%rcx
call   1030 <ppoll@plt>
xor    %ecx,%ecx
cmp    $0x2,%eax
mov    $0x4d,%eax
cmove  %ecx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.pollfd = type { i32, i32 }
@__const.test1.timeout = %struct.timespec { i32 42, i32 999999999 }
@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
@SIGUSR2 = global i32 0
@SIGCHLD = global i32 0
define i32 @test1() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = alloca [4 x %struct.pollfd]
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %3, i64 0, i64 0
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %5, i32 0, i32 0
store i32 0, 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 1, 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 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %15, i64 1
%24 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %23, i32 0, i32 0
store i32 3, i32* %24
%25 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %23, i32 0, i32 1
%26 = load i32, i32* @POLLIN
%27 = load i32, i32* @POLLPRI
%28 = or i32 %26, %27
store i32 %28, i32* %25
%29 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %23, i64 1
%30 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %29, i32 0, i32 0
store i32 4, i32* %30
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %29, i32 0, i32 1
%32 = load i32, i32* @POLLOUT
store i32 %32, i32* %31
%33 = call i32 @sigemptyset(i32* %1)
%34 = load i32, i32* @SIGUSR2
%35 = call i32 @sigaddset(i32* %1, i32 %34)
%36 = load i32, i32* @SIGCHLD
%37 = call i32 @sigaddset(i32* %1, i32 %36)
%38 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %3, i64 0, i64 0
%39 = call i32 @ppoll(%struct.pollfd* %38, i32 4, %struct.timespec* %2, i32* %1)
%40 = icmp eq i32 %39, 2
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 0, i32 77
ret i32 %42
}

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
@SIGUSR2 = global i32 0
@SIGCHLD = global i32 0
define i32 @test1() {
%1 = alloca i32
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = alloca [4 x %struct.pollfd]
%5 = bitcast i32* %1 to i8*
%6 = bitcast i64* %2 to i8*
store i64 4294967291705032746, i64* %2
%7 = bitcast [4 x %struct.pollfd]* %4 to i8*
%8 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 0
%9 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 0, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds [4 x %struct.pollfd], [4 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 [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 1, i32 0
store i32 1, i32* %18
%19 = getelementptr inbounds [4 x %struct.pollfd], [4 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 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 2, i32 0
store i32 3, i32* %25
%26 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 2, i32 1
store i32 %13, i32* %26
%27 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 3, i32 0
store i32 4, i32* %27
%28 = getelementptr inbounds [4 x %struct.pollfd], [4 x %struct.pollfd]* %4, i64 0, i64 3, i32 1
store i32 %20, i32* %28
%29 = call i32 @sigemptyset(i32* %1)
%30 = load i32, i32* @SIGUSR2
%31 = call i32 @sigaddset(i32* %1, i32 %30)
%32 = load i32, i32* @SIGCHLD
%33 = call i32 @sigaddset(i32* %1, i32 %32)
%34 = call i32 @ppoll(%struct.pollfd* %8, i32 4, %struct.timespec* %3, i32* %1)
%35 = icmp eq i32 %34, 2
%36 = select i1 %35, i32 0, i32 77
ret i32 %36
}