#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 {
  scalar_t__ events;
  scalar_t__ fd;
  scalar_t__ revents;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ POLLIN;
scalar_t__ open(char *, int /*<<< orphan*/);
scalar_t__ ppoll(struct pollfd *, int, struct timespec *, int /*<<< orphan*/);
int main(void) {
  struct pollfd x = {.events = POLLIN};
  struct timespec ts = {.tv_sec = 0, .tv_nsec = 10};
  x.fd = open("src/sysdeps/tryppoll.c", O_RDONLY);
  if (x.fd < 0)
    return 111;
  if (ppoll(&x, 1, &ts, 0) < 0)
    return 1;
  if (x.revents != POLLIN)
    return 1;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    0xeac(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
lea    0xea0(%rip),%rdi
call   1040 <open@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1188 <main+0x68>
movl   $0x6f,-0x4(%rbp)
jmp    11d9 <main+0xb9>
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
lea    -0x28(%rbp),%rdx
xor    %ecx,%ecx
call   1030 <ppoll@plt>
cmp    $0x0,%rax
jge    11b2 <main+0x92>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <main+0xb9>
mov    -0x10(%rbp),%rax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <main+0xb2>
movl   $0x1,-0x4(%rbp)
jmp    11d9 <main+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    0x2eb2(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x10(%rsp)
movq   $0x0,0x20(%rsp)
movq   $0xa,0x8(%rsp)
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1040 <open@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
js     1196 <main+0x76>
lea    0x10(%rsp),%rdi
mov    $0x1,%ebx
lea    0x8(%rsp),%rdx
mov    $0x1,%esi
xor    %ecx,%ecx
call   1030 <ppoll@plt>
test   %rax,%rax
js     119b <main+0x7b>
mov    0x20(%rsp),%rax
xor    %ebx,%ebx
cmp    (%r14),%rax
setne  %bl
jmp    119b <main+0x7b>
mov    $0x6f,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.pollfd = type { i64, i64, i64 }
@POLLIN = global i64 0
@__const.main.ts = %struct.timespec { i32 10, i32 0 }
@.str = [23 x i8] c"src/sysdeps/tryppoll.c\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.pollfd
%3 = alloca %struct.timespec
store i32 0, i32* %1
%4 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 0
%5 = load i64, i64* @POLLIN
store i64 %5, i64* %4
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 2
store i64 0, i64* %7
%8 = bitcast %struct.timespec* %3 to i8*
%9 = load i32, i32* @O_RDONLY
%10 = call i64 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
store i64 %10, i64* %11
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 1
%13 = load i64, i64* %12
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %0
store i32 111, i32* %1
br label %27
16: ; preds = %0
%17 = call i64 @ppoll(%struct.pollfd* %2, i32 1, %struct.timespec* %3, i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %16
store i32 1, i32* %1
br label %27
20: ; preds = %16
%21 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %2, i32 0, i32 2
%22 = load i64, i64* %21
%23 = load i64, i64* @POLLIN
%24 = icmp ne i64 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 1, i32* %1
br label %27
26: ; preds = %20
store i32 0, i32* %1
br label %27
27: ; preds = %26, %25, %19, %15
%28 = load i32, i32* %1
ret i32 %28
}

LLVM IR (-O2):
%struct.pollfd = type { i64, i64, i64 }
%struct.timespec = type { i32, i32 }
@POLLIN = global i64 0
@.str = [23 x i8] c"src/sysdeps/tryppoll.c\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca %struct.pollfd
%2 = alloca i64
%3 = bitcast %struct.pollfd* %1 to i8*
%4 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 0
%5 = load i64, i64* @POLLIN
store i64 %5, i64* %4
%6 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 1
%7 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %1, i64 0, i32 2
%8 = bitcast i64* %2 to i8*
%9 = getelementptr inbounds i64, i64* %6, i64 1
store i64 0, i64* %9
store i64 10, i64* %2
%10 = load i32, i32* @O_RDONLY
%11 = tail call i64 @open(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %10)
store i64 %11, i64* %6
%12 = icmp slt i64 %11, 0
br i1 %12, label %22, label %13
13: ; preds = %0
%14 = bitcast i64* %2 to %struct.timespec*
%15 = call i64 @ppoll(%struct.pollfd* %1, i32 1, %struct.timespec* %14, i32 0)
%16 = icmp slt i64 %15, 0
br i1 %16, label %22, label %17
17: ; preds = %13
%18 = load i64, i64* %7
%19 = load i64, i64* @POLLIN
%20 = icmp ne i64 %18, %19
%21 = zext i1 %20 to i32
br label %22
22: ; preds = %17, %13, %0
%23 = phi i32 [ 111, %0 ], [ 1, %13 ], [ %21, %17 ]
ret i32 %23
}