#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int O_NONBLOCK;
int O_RDONLY;
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int timeout = 8050, rc, fd, epfd, maxevents = 1;
  struct epoll_event ep_sd, ep_event;
  fd = open("./afifo", O_RDONLY | O_NONBLOCK);
  ep_sd.data.fd = fd;
  ep_sd.events = EPOLLIN;
  epfd = epoll_create(1);
  epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ep_sd);
  if ((rc = epoll_wait(epfd, &ep_event, maxevents, timeout)) < 0) {
    printf("error in epoll()\n");
    exit(EXIT_FAILURE);
  }
  printf(" epoll returned with rc=%d\n", rc);
  if (rc > 0 && (ep_event.events & EPOLLIN))
    printf("Data ready for reading on fd=%d\n", ep_event.data.fd);
  if (rc == 0)
    printf("No data found\n");
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1f72,-0x8(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
mov    0x2e5b(%rip),%rax
or     (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x1,%edi
call   1070 <epoll_create@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e09(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    -0x28(%rbp),%rsi
call   1050 <epoll_wait@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    120f <main+0xaf>
lea    0xe0e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0xc(%rbp),%esi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jle    1250 <main+0xf0>
mov    -0x28(%rbp),%eax
mov    0x2dac(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1250 <main+0xf0>
mov    -0x24(%rbp),%esi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0xc(%rbp)
jne    1268 <main+0x108>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e59(%rip),%rax
mov    0x2e62(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe6f(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %eax,0xc(%rsp)
mov    0x2e3d(%rip),%r14
mov    (%r14),%eax
mov    %eax,0x8(%rsp)
mov    $0x1,%edi
call   1080 <epoll_create@plt>
mov    %eax,%ebp
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
mov    %ebx,%edx
call   1050 <epoll_ctl@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x1,%edx
mov    $0x1f72,%ecx
call   1060 <epoll_wait@plt>
test   %eax,%eax
jns    11ff <main+0x8f>
lea    0xe67(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    %eax,%ebx
lea    0xe00(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
jne    1223 <main+0xb3>
lea    0xe29(%rip),%rdi
call   1030 <puts@plt>
jmp    123d <main+0xcd>
mov    (%r14),%eax
test   %eax,(%rsp)
je     123d <main+0xcd>
mov    0x4(%rsp),%esi
lea    0xdee(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [18 x i8] c"error in epoll()\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [28 x i8] c" epoll 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 i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.epoll_event
%8 = alloca %struct.epoll_event
store i32 0, i32* %1
store i32 8050, i32* %2
store i32 1, i32* %6
%9 = load i32, i32* @O_RDONLY
%10 = load i32, i32* @O_NONBLOCK
%11 = or i32 %9, %10
%12 = call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %4
%13 = load i32, i32* %4
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %7, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 %13, i32* %15
%16 = load i32, i32* @EPOLLIN
%17 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %7, i32 0, i32 0
store i32 %16, i32* %17
%18 = call i32 @epoll_create(i32 1)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = load i32, i32* @EPOLL_CTL_ADD
%21 = load i32, i32* %4
%22 = call i32 @epoll_ctl(i32 %19, i32 %20, i32 %21, %struct.epoll_event* %7)
%23 = load i32, i32* %5
%24 = load i32, i32* %6
%25 = load i32, i32* %2
%26 = call i32 @epoll_wait(i32 %23, %struct.epoll_event* %8, i32 %24, i32 %25)
store i32 %26, i32* %3
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
%31 = call i32 @exit(i32 %30)
unreachable
32: ; preds = %0
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %33)
%35 = load i32, i32* %3
%36 = icmp sgt i32 %35, 0
br i1 %36, label %37, label %48
37: ; preds = %32
%38 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 0
%39 = load i32, i32* %38
%40 = load i32, i32* @EPOLLIN
%41 = and i32 %39, %40
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %37
%44 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %43, %37, %32
%49 = load i32, i32* %3
%50 = icmp eq i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %48
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
br label %53
53: ; preds = %51, %48
%54 = load i32, i32* @EXIT_SUCCESS
%55 = call i32 @exit(i32 %54)
unreachable
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [8 x i8] c"./afifo\00"
@O_RDONLY = global i32 0
@O_NONBLOCK = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [28 x i8] c" epoll 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 = [17 x i8] c"error in epoll()\00"
define i32 @main() {
%1 = alloca %struct.epoll_event
%2 = alloca %struct.epoll_event
%3 = bitcast %struct.epoll_event* %1 to i8*
%4 = bitcast %struct.epoll_event* %2 to i8*
%5 = load i32, i32* @O_RDONLY
%6 = load i32, i32* @O_NONBLOCK
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1, i32 0
store i32 %8, i32* %9
%10 = load i32, i32* @EPOLLIN
%11 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0
store i32 %10, i32* %11
%12 = tail call i32 @epoll_create(i32 1)
%13 = load i32, i32* @EPOLL_CTL_ADD
%14 = call i32 @epoll_ctl(i32 %12, i32 %13, i32 %8, %struct.epoll_event* %1)
%15 = call i32 @epoll_wait(i32 %12, %struct.epoll_event* %2, i32 1, i32 8050)
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %0
%18 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.5, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %0
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%23 = icmp eq i32 %15, 0
br i1 %23, label %34, label %24
24: ; preds = %21
%25 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @EPOLLIN
%28 = and i32 %27, %26
%29 = icmp eq i32 %28, 0
br i1 %29, label %36, label %30
30: ; preds = %24
%31 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 1, i32 0
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %32)
br label %36
34: ; preds = %21
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %24, %30, %34
%37 = load i32, i32* @EXIT_SUCCESS
%38 = call i32 @exit(i32 %37)
unreachable
}