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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ IPPROTO_UDP;
int /*<<< orphan*/ POLLHUP;
int /*<<< orphan*/ POLLIN;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
scalar_t__ ppoll(struct pollfd *, int, struct timespec *, int /*<<< orphan*/ *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(void) {
  int sock1, sock2;
  if ((sock1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    return (EXIT_FAILURE);
  if ((sock2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
    return (EXIT_FAILURE);
  struct pollfd pollfds[2];
  pollfds[0].fd = sock1;
  pollfds[0].events = POLLHUP;
  pollfds[1].fd = sock2;
  pollfds[1].events = POLLIN;
  struct timespec timeout;
  timeout.tv_sec = 1;
  timeout.tv_nsec = 1000;
  if (ppoll(pollfds, sizeof(pollfds) / sizeof(struct pollfd), &timeout, NULL) <
      0) {
    fprintf(stderr, "ppoll() failed: %s\n.", strerror(errno));
    return (EXIT_FAILURE);
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    118c <main+0x4c>
mov    0x2e2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2df3(%rip),%rax
mov    (%rax),%edx
call   1060 <socket@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    11c9 <main+0x89>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x3e8,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x2,%esi
lea    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1030 <ppoll@plt>
cmp    $0x0,%rax
jge    1258 <main+0x118>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xdbe(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1264 <main+0x124>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    0x2e8e(%rip),%r14
mov    (%r14),%edi
mov    0x2e7c(%rip),%r15
mov    (%r15),%esi
mov    0x2e32(%rip),%r12
mov    (%r12),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     1206 <main+0xc6>
mov    %eax,%ebx
mov    (%r14),%edi
mov    (%r15),%esi
mov    (%r12),%edx
call   1060 <socket@plt>
test   %eax,%eax
js     1206 <main+0xc6>
mov    %ebx,(%rsp)
mov    0x2e52(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,0x4(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
movabs $0x3e800000001,%rax
mov    %rax,0x10(%rsp)
mov    %rsp,%rdi
lea    0x10(%rsp),%rdx
mov    $0x2,%esi
xor    %ecx,%ecx
call   1030 <ppoll@plt>
test   %rax,%rax
js     11de <main+0x9e>
mov    0x2dcc(%rip),%rax
jmp    120d <main+0xcd>
mov    0x2ddb(%rip),%rax
mov    (%rax),%ebx
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe04(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@EXIT_FAILURE = global i32 0
@POLLHUP = global i32 0
@POLLIN = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ppoll() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [2 x %struct.pollfd]
%5 = alloca %struct.timespec
store i32 0, i32* %1
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_DGRAM
%8 = load i32, i32* @IPPROTO_UDP
%9 = call i32 @socket(i32 %6, i32 %7, i32 %8)
store i32 %9, i32* %2
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = load i32, i32* @EXIT_FAILURE
store i32 %12, i32* %1
br label %47
13: ; preds = %0
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_DGRAM
%16 = load i32, i32* @IPPROTO_UDP
%17 = call i32 @socket(i32 %14, i32 %15, i32 %16)
store i32 %17, i32* %3
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = load i32, i32* @EXIT_FAILURE
store i32 %20, i32* %1
br label %47
21: ; preds = %13
%22 = load i32, i32* %2
%23 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%24 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i32, i32* @POLLHUP
%26 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%27 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %26, i32 0, i32 1
store i32 %25, i32* %27
%28 = load i32, i32* %3
%29 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%30 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %29, i32 0, i32 0
store i32 %28, i32* %30
%31 = load i32, i32* @POLLIN
%32 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 1
%33 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %32, i32 0, i32 1
store i32 %31, i32* %33
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 1, i32* %34
%35 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i32 1000, i32* %35
%36 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %4, i64 0, i64 0
%37 = call i64 @ppoll(%struct.pollfd* %36, i32 2, %struct.timespec* %5, i32* null)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %21
%40 = load i32, i32* @stderr
%41 = load i32, i32* @errno
%42 = call i8* @strerror(i32 %41)
%43 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %42)
%44 = load i32, i32* @EXIT_FAILURE
store i32 %44, i32* %1
br label %47
45: ; preds = %21
%46 = load i32, i32* @EXIT_SUCCESS
store i32 %46, i32* %1
br label %47
47: ; preds = %45, %39, %19, %11
%48 = load i32, i32* %1
ret i32 %48
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@AF_INET = global i32 0
@SOCK_DGRAM = global i32 0
@IPPROTO_UDP = global i32 0
@EXIT_FAILURE = global i32 0
@POLLHUP = global i32 0
@POLLIN = global i32 0
@stderr = global i32 0
@.str = [21 x i8] c"ppoll() failed: %s\0A.\00"
@errno = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [2 x %struct.pollfd]
%2 = alloca %struct.timespec
%3 = load i32, i32* @AF_INET
%4 = load i32, i32* @SOCK_DGRAM
%5 = load i32, i32* @IPPROTO_UDP
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = load i32, i32* @EXIT_FAILURE
br label %40
10: ; preds = %0
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_DGRAM
%13 = load i32, i32* @IPPROTO_UDP
%14 = tail call i32 @socket(i32 %11, i32 %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = load i32, i32* @EXIT_FAILURE
br label %40
18: ; preds = %10
%19 = bitcast [2 x %struct.pollfd]* %1 to i8*
%20 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0
%21 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 0
store i32 %6, i32* %21
%22 = load i32, i32* @POLLHUP
%23 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 0
store i32 %14, i32* %24
%25 = load i32, i32* @POLLIN
%26 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %1, i64 0, i64 1, i32 1
store i32 %25, i32* %26
%27 = bitcast %struct.timespec* %2 to i8*
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 1, i32* %28
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i32 1000, i32* %29
%30 = call i64 @ppoll(%struct.pollfd* %20, i32 2, %struct.timespec* %2, i32* null)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %37
32: ; preds = %18
%33 = load i32, i32* @stderr
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %35)
br label %37
37: ; preds = %18, %32
%38 = phi i32* [ @EXIT_FAILURE, %32 ], [ @EXIT_SUCCESS, %18 ]
%39 = load i32, i32* %38
br label %40
40: ; preds = %37, %16, %8
%41 = phi i32 [ %9, %8 ], [ %17, %16 ], [ %39, %37 ]
ret i32 %41
}