#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 member_1;
  int /*<<< orphan*/ member_0;
};
struct pollfd {
  int /*<<< orphan*/ revents;
  int /*<<< orphan*/ events;
  int /*<<< orphan*/ fd;
};
typedef int /*<<< orphan*/ sigset_t;

/* Variables and functions */
int EINTR;
int /*<<< orphan*/ POLLIN;
int errno;
int ppoll(struct pollfd *, int, struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int main(void) {
  struct pollfd pfd = {.fd = 0, .events = POLLIN, .revents = 0};
  struct timespec pts = {0, 500000000};
  sigset_t st;
  sigemptyset(&st);
  int r = ppoll(&pfd, 1, &pts, &st);
  if (r < 0 && errno != EINTR)
    return -errno;
  else if (r >= 0)
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
mov    0x2eab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0xeb0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <sigemptyset@plt>
lea    -0x10(%rbp),%rdi
mov    $0x1,%esi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
call   1030 <ppoll@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    11ab <main+0x8b>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%eax
je     11ab <main+0x8b>
xor    %eax,%eax
mov    0x2e37(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11c8 <main+0xa8>
cmpl   $0x0,-0x20(%rbp)
jl     11c1 <main+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    11c8 <main+0xa8>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movl   $0x0,(%rsp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
movl   $0x0,0x8(%rsp)
movabs $0x1dcd650000000000,%rax
65 cd 1d
mov    %rax,0x10(%rsp)
lea    0x1c(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <sigemptyset@plt>
mov    %rsp,%rdi
lea    0x10(%rsp),%rdx
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <ppoll@plt>
test   %eax,%eax
jns    118a <main+0x6a>
mov    0x2e5b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e4a(%rip),%rdx
cmp    (%rdx),%ecx
jne    118f <main+0x6f>
sar    $0x1f,%eax
jmp    1193 <main+0x73>
neg    %ecx
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.pollfd = type { i32, i32, i32 }
@POLLIN = global i32 0
@__const.main.pts = %struct.timespec { i32 0, i32 500000000 }
@errno = global i32 0
@EINTR = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.pollfd
%3 = alloca %struct.timespec
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 0
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
%8 = load i32, i32* @POLLIN
store i32 %8, i32* %7
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 2
store i32 0, i32* %9
%10 = bitcast %struct.timespec* %3 to i8*
%11 = call i32 @sigemptyset(i32* %4)
%12 = call i32 @ppoll(%struct.pollfd* %2, i32 1, %struct.timespec* %3, i32* %4)
store i32 %12, i32* %5
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %0
%16 = load i32, i32* @errno
%17 = load i32, i32* @EINTR
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @errno
%21 = sub nsw i32 0, %20
store i32 %21, i32* %1
br label %27
22: ; preds = %15, %0
%23 = load i32, i32* %5
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 0, i32* %1
br label %27
26: ; preds = %22
store i32 -1, i32* %1
br label %27
27: ; preds = %26, %25, %19
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
%struct.timespec = type { i32, i32 }
@POLLIN = global i32 0
@errno = global i32 0
@EINTR = global i32 0
define i32 @main() {
%1 = alloca %struct.pollfd
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = alloca i32
%5 = bitcast %struct.pollfd* %1 to i8*
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 0
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 1
%8 = load i32, i32* @POLLIN
store i32 %8, i32* %7
%9 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 2
store i32 0, i32* %9
%10 = bitcast i64* %2 to i8*
store i64 2147483648000000000, i64* %2
%11 = bitcast i32* %4 to i8*
%12 = call i32 @sigemptyset(i32* %4)
%13 = call i32 @ppoll(%struct.pollfd* %1, i32 1, %struct.timespec* %3, i32* %4)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = load i32, i32* @errno
%17 = load i32, i32* @EINTR
%18 = icmp eq i32 %16, %17
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = sub nsw i32 0, %16
br label %23
21: ; preds = %15, %0
%22 = ashr i32 %13, 31
br label %23
23: ; preds = %21, %19
%24 = phi i32 [ %20, %19 ], [ %22, %21 ]
ret i32 %24
}