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

/* Variables and functions */
int O_NONBLOCK;
int O_RDONLY;
int /*<<< orphan*/ POLLIN;
int POLLNVAL;
int /*<<< orphan*/ close(int);
int open(char *, int, int /*<<< orphan*/);
int poll(struct pollfd *, int, int /*<<< orphan*/);
int main() {
  int fd, n;
  struct pollfd pollfds[1];
  fd = open("/dev/null", O_RDONLY | O_NONBLOCK, 0);
  pollfds[0].fd = fd;
  pollfds[0].events = POLLIN;
  n = poll(pollfds, 1, 0);
  close(fd);
  return (n == 1 && !(pollfds[0].revents & POLLNVAL)) ? 0 : 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e61(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
xor    %eax,%eax
cmpl   $0x1,-0xc(%rbp)
mov    %al,-0x19(%rbp)
jne    11b5 <main+0x85>
mov    -0x14(%rbp),%eax
mov    0x2e38(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%dl
mov    $0x1,%eax
xor    %ecx,%ecx
test   $0x1,%dl
cmovne %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    0x2ea2(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeaf(%rip),%rdi
xor    %edx,%edx
call   1050 <open@plt>
mov    %eax,%ebp
mov    %eax,(%rsp)
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rdi
mov    $0x1,%ebx
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <poll@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <close@plt>
cmp    $0x1,%r14d
jne    11a0 <main+0x70>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
xor    %ebx,%ebx
test   %eax,0x4(%rsp)
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [10 x i8] c"/dev/null\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@POLLIN = global i32 0
@POLLNVAL = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1 x %struct.pollfd]
store i32 0, i32* %1
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %5, %6
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7, i32 0)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%11 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = load i32, i32* @POLLIN
%13 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%14 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %13, i32 0, i32 2
store i32 %12, i32* %14
%15 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%16 = call i32 @poll(%struct.pollfd* %15, i32 1, i32 0)
store i32 %16, i32* %3
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %3
%20 = icmp eq i32 %19, 1
br i1 %20, label %21, label %29
21: ; preds = %0
%22 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %4, i64 0, i64 0
%23 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load i32, i32* @POLLNVAL
%26 = and i32 %24, %25
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br label %29
29: ; preds = %21, %0
%30 = phi i1 [ false, %0 ], [ %28, %21 ]
%31 = zext i1 %30 to i64
%32 = select i1 %30, i32 0, i32 1
ret i32 %32
}

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