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

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
scalar_t__ POLLIN;
int /*<<< orphan*/ _exit(int);
int open(char *, int /*<<< orphan*/);
int poll(struct pollfd *, int, int);
main() {
  struct pollfd x;
  x.fd = open("trypoll.c", O_RDONLY);
  if (x.fd == -1)
    _exit(111);
  x.events = POLLIN;
  if (poll(&x, 1, 10) == -1)
    _exit(1);
  if (x.revents != POLLIN)
    _exit(1);
  _exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    116b <main+0x3b>
mov    $0x6f,%edi
call   1030 <_exit@plt>
mov    0x2e6e(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
jne    119f <main+0x6f>
mov    $0x1,%edi
call   1030 <_exit@plt>
mov    -0x18(%rbp),%rax
mov    0x2e36(%rip),%rcx
cmp    (%rcx),%rax
je     11bd <main+0x8d>
mov    $0x1,%edi
call   1030 <_exit@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2eac(%rip),%rax
mov    (%rax),%esi
lea    0xebb(%rip),%rdi
call   1050 <open@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
jne    115d <main+0x2d>
mov    $0x6f,%edi
call   1030 <_exit@plt>
mov    0x2e7c(%rip),%rbx
mov    (%rbx),%rax
mov    %rax,0x18(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0xa,%edx
call   1040 <poll@plt>
cmp    $0xffffffff,%eax
je     1196 <main+0x66>
mov    0x10(%rsp),%rax
cmp    (%rbx),%rax
jne    1196 <main+0x66>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    $0x1,%edi
call   1030 <_exit@plt>

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

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