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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_NONBLOCK;
int O_RDONLY;
int POLLIN;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  struct pollfd ufds[1];
  int timeout = 8050, rc, fd;
  fd = open("./afifo", O_RDONLY | O_NONBLOCK);
  ufds[0].fd = fd;
  ufds[0].events = POLLIN;
  if ((rc = poll(ufds, 1, timeout)) < 0) {
    printf("error in poll()\n");
    exit(EXIT_FAILURE);
  }
  printf(" poll returned with rc=%d\n", rc);
  if (rc > 0 && (ufds[0].revents & POLLIN))
    printf("Data ready for reading on fd=%d\n", fd);
  if (rc == 0)
    printf("No data found\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1f72,-0x14(%rbp)
mov    0x2e83(%rip),%rax
mov    (%rax),%esi
mov    0x2e82(%rip),%rax
or     (%rax),%esi
lea    0xe91(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x1,%esi
call   1040 <poll@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11c2 <main+0x82>
lea    0xe5b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x18(%rbp),%esi
lea    0xe4d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jle    1203 <main+0xc3>
mov    -0x8(%rbp),%eax
mov    0x2df1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1203 <main+0xc3>
mov    -0x1c(%rbp),%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
jne    121b <main+0xdb>
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e81(%rip),%rax
mov    0x2e82(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1060 <open@plt>
mov    %eax,%ebx
mov    %eax,(%rsp)
mov    0x2e56(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1f72,%edx
call   1050 <poll@plt>
test   %eax,%eax
jns    11b9 <main+0x69>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    %eax,%ebp
lea    0xe46(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebp,%ebp
jne    11dd <main+0x8d>
lea    0xe6e(%rip),%rdi
call   1030 <puts@plt>
jmp    11f6 <main+0xa6>
mov    (%r14),%eax
test   %eax,0x8(%rsp)
je     11f6 <main+0xa6>
lea    0xe36(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@POLLIN = global i32 0
@.str.1 = [17 x i8] c"error in poll()\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c" poll returned with rc=%d\0A\00"
@.str.3 = [33 x i8] c"Data ready for reading on fd=%d\0A\00"
@.str.4 = [15 x i8] c"No data found\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x %struct.pollfd]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
store i32 8050, i32* %3
%6 = load i32, i32* @O_RDONLY
%7 = load i32, i32* @O_NONBLOCK
%8 = or i32 %6, %7
%9 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%12 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = load i32, i32* @POLLIN
%14 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%15 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %14, i32 0, i32 1
store i32 %13, i32* %15
%16 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%17 = load i32, i32* %3
%18 = call i32 @poll(%struct.pollfd* %16, i32 1, i32 %17)
store i32 %18, i32* %4
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %0
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %0
%25 = load i32, i32* %4
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %39
29: ; preds = %24
%30 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %2, i64 0, i64 0
%31 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %30, i32 0, i32 2
%32 = load i32, i32* %31
%33 = load i32, i32* @POLLIN
%34 = and i32 %32, %33
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %29
%37 = load i32, i32* %5
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %37)
br label %39
39: ; preds = %36, %29, %24
%40 = load i32, i32* %4
%41 = icmp eq i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %39
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %42, %39
%45 = load i32, i32* @EXIT_SUCCESS
%46 = call i32 @exit(i32 %45)
unreachable
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@POLLIN = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [27 x i8] c" poll returned with rc=%d\0A\00"
@.str.3 = [33 x i8] c"Data ready for reading on fd=%d\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [14 x i8] c"No data found\00"
@str.5 = [16 x i8] c"error in poll()\00"
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 ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %5)
%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 1
store i32 %9, i32* %10
%11 = call i32 @poll(%struct.pollfd* %7, i32 1, i32 8050)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %0
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%19 = icmp eq i32 %11, 0
br i1 %19, label %28, label %20
20: ; preds = %17
%21 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %1, i64 0, i64 0, i32 2
%22 = load i32, i32* %21
%23 = load i32, i32* @POLLIN
%24 = and i32 %23, %22
%25 = icmp eq i32 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %6)
br label %30
28: ; preds = %17
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %30
30: ; preds = %20, %26, %28
%31 = load i32, i32* @EXIT_SUCCESS
%32 = call i32 @exit(i32 %31)
unreachable
}