#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;
  scalar_t__ revents;
  int /*<<< orphan*/ events;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ POLLOUT;
int /*<<< orphan*/ SIGTERM;
int ppoll(struct pollfd *, int, struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int main(void) {
  struct pollfd fds[(3)];
  struct timespec ts;
  sigset_t sigmask;
  int fd;
  for (fd = 0; fd < (3); fd++) {
    fds[fd].fd = fd;
    fds[fd].events = (fd == 0) ? POLLIN : POLLOUT;
    fds[fd].revents = 0;
  }
  ts.tv_sec = 1;
  ts.tv_nsec = 999999999;
  (void)sigemptyset(&sigmask);
  (void)sigaddset(&sigmask, SIGTERM);
  return ppoll(fds, 3, &ts, &sigmask);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x60(%rbp)
cmpl   $0x3,-0x60(%rbp)
jge    11c5 <main+0x95>
mov    -0x60(%rbp),%ecx
movslq -0x60(%rbp),%rdx
lea    -0x50(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
cmpl   $0x0,-0x60(%rbp)
jne    117f <main+0x4f>
mov    0x2e63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
jmp    118b <main+0x5b>
mov    0x2e72(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%ecx
movslq -0x60(%rbp),%rdx
lea    -0x50(%rbp),%rax
imul   $0x18,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,0x10(%rax)
movslq -0x60(%rbp),%rcx
lea    -0x50(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
movq   $0x0,0x8(%rax)
mov    -0x60(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x60(%rbp)
jmp    1146 <main+0x16>
movl   $0x1,-0x58(%rbp)
movl   $0x3b9ac9ff,-0x54(%rbp)
lea    -0x5c(%rbp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%esi
lea    -0x5c(%rbp),%rdi
call   1050 <sigaddset@plt>
lea    -0x50(%rbp),%rdi
mov    $0x3,%esi
lea    -0x58(%rbp),%rdx
lea    -0x5c(%rbp),%rcx
call   1030 <ppoll@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x60,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%eax
mov    0x2eb3(%rip),%rcx
mov    (%rcx),%ecx
movl   $0x0,0x10(%rsp)
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
movl   $0x1,0x28(%rsp)
mov    %ecx,0x38(%rsp)
movq   $0x0,0x30(%rsp)
movl   $0x2,0x40(%rsp)
mov    %ecx,0x50(%rsp)
movq   $0x0,0x48(%rsp)
movabs $0x3b9ac9ff00000001,%rax
c9 9a 3b
mov    %rax,(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1050 <sigaddset@plt>
lea    0x10(%rsp),%rdi
mov    %rsp,%rdx
mov    $0x3,%esi
mov    %rbx,%rcx
call   1030 <ppoll@plt>
add    $0x60,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i64, i32 }
%struct.timespec = type { i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x %struct.pollfd]
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %5
br label %6
6: ; preds = %31, %0
%7 = load i32, i32* %5
%8 = icmp slt i32 %7, 3
br i1 %8, label %9, label %34
9: ; preds = %6
%10 = load i32, i32* %5
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %2, i64 0, i64 %12
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %13, i32 0, i32 0
store i32 %10, i32* %14
%15 = load i32, i32* %5
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %9
%18 = load i32, i32* @POLLIN
br label %21
19: ; preds = %9
%20 = load i32, i32* @POLLOUT
br label %21
21: ; preds = %19, %17
%22 = phi i32 [ %18, %17 ], [ %20, %19 ]
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %2, i64 0, i64 %24
%26 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %25, i32 0, i32 2
store i32 %22, i32* %26
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %2, i64 0, i64 %28
%30 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %29, i32 0, i32 1
store i64 0, i64* %30
br label %31
31: ; preds = %21
%32 = load i32, i32* %5
%33 = add nsw i32 %32, 1
store i32 %33, i32* %5
br label %6
34: ; preds = %6
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 1, i32* %35
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i32 999999999, i32* %36
%37 = call i32 @sigemptyset(i32* %4)
%38 = load i32, i32* @SIGTERM
%39 = call i32 @sigaddset(i32* %4, i32 %38)
%40 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %2, i64 0, i64 0
%41 = call i32 @ppoll(%struct.pollfd* %40, i32 3, %struct.timespec* %3, i32* %4)
ret i32 %41
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i64, i32 }
%struct.timespec = type { i32, i32 }
@POLLIN = global i32 0
@POLLOUT = global i32 0
@SIGTERM = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.pollfd]
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = bitcast [3 x %struct.pollfd]* %1 to i8*
%5 = bitcast %struct.timespec* %2 to i8*
%6 = bitcast i32* %3 to i8*
%7 = load i32, i32* @POLLIN
%8 = load i32, i32* @POLLOUT
%9 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 0, i32* %9
%10 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 0, i32 2
store i32 %7, i32* %10
%11 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
store i64 0, i64* %11
%12 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 1, i32 0
store i32 1, i32* %12
%13 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 1, i32 2
store i32 %8, i32* %13
%14 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 1, i32 1
store i64 0, i64* %14
%15 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 2, i32 0
store i32 2, i32* %15
%16 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 2, i32 2
store i32 %8, i32* %16
%17 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 2, i32 1
store i64 0, i64* %17
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 1, i32* %18
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i32 999999999, i32* %19
%20 = call i32 @sigemptyset(i32* %3)
%21 = load i32, i32* @SIGTERM
%22 = call i32 @sigaddset(i32* %3, i32 %21)
%23 = getelementptr inbounds [3 x %struct.pollfd], [3 x %struct.pollfd]* %1, i64 0, i64 0
%24 = call i32 @ppoll(%struct.pollfd* %23, i32 3, %struct.timespec* %2, i32* %3)
ret i32 %24
}