#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 */
typedef int uint32_t;
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int /*<<< orphan*/ event;

/* Variables and functions */
int EPOLLET;
int EPOLLIN;
int EPOLLOUT;
int EPOLLPRI;
int /*<<< orphan*/ EPOLL_CLOEXEC;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ O_NONBLOCK;
int epoll_create1(int /*<<< orphan*/);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ err(int, char *);
int /*<<< orphan*/ errx(int, char *, ...);
int /*<<< orphan*/ memset(struct epoll_event *, char, int);
scalar_t__ pipe2(int *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  if (argc != 1 && argc != 2) {
    errx(1, "invalid arguments count");
  }
  uint32_t expected_events = EPOLLIN;
  if (argc == 2 && !strcmp(argv[1], "EMULATE_GRAPHENE_BUG")) {
    expected_events |= EPOLLOUT;
  }
  int efd = epoll_create1(EPOLL_CLOEXEC);
  if (efd < 0) {
    err(1, "epoll_create1");
  }
  int p[2];
  if (pipe2(p, O_NONBLOCK) < 0) {
    err(1, "pipe2");
  }
  struct epoll_event event = {
      .events = EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLET,
      .data.fd = p[0],
  };
  if (epoll_ctl(efd, EPOLL_CTL_ADD, p[0], &event) < 0) {
    err(1, "EPOLL_CTL_ADD");
  }
  if (write(p[1], "", 1) != 1) {
    err(1, "write");
  }
  if (write(p[1], "", 1) != 1) {
    err(1, "write");
  }
  memset(&event, '\0', sizeof(event));
  if (epoll_wait(efd, &event, 1, -1) != 1) {
    err(1, "epoll_wait");
  }
  if (event.data.fd != p[0]) {
    errx(1, "epoll invalid data: %d", event.data.fd);
  }
  if (event.events != expected_events) {
    errx(1, "epoll invalid events: 0x%x", event.events);
  }
  char c;
  if (read(p[0], &c, 1) != 1) {
    err(1, "read");
  }
  memset(&event, '\0', sizeof(event));
  int ret = epoll_wait(efd, &event, 1, 10);
  if (ret < 0) {
    err(1, "epoll_wait");
  } else if (ret != 0) {
    errx(1, "EPOLLET reported 2 times: %d", ret);
  }
  puts("TEST OK");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     11ed <main+0x3d>
cmpl   $0x2,-0x8(%rbp)
je     11ed <main+0x3d>
mov    $0x1,%edi
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    122f <main+0x7f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe06(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    122f <main+0x7f>
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
or     -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   10d0 <epoll_create1@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    125b <main+0xab>
mov    $0x1,%edi
lea    0xdd7(%rip),%rsi
call   10a0 <err@plt>
lea    -0x20(%rbp),%rdi
mov    0x2d7a(%rip),%rax
mov    (%rax),%esi
call   10c0 <pipe2@plt>
cmp    $0x0,%rax
jge    1288 <main+0xd8>
mov    $0x1,%edi
lea    0xdb8(%rip),%rsi
call   10a0 <err@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    0x2d20(%rip),%rcx
or     (%rcx),%eax
mov    0x2d4f(%rip),%rcx
or     (%rcx),%eax
mov    0x2d06(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    12e8 <main+0x138>
mov    $0x1,%edi
lea    0xd5e(%rip),%rsi
call   10a0 <err@plt>
mov    -0x1c(%rbp),%edi
lea    0xd48(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1316 <main+0x166>
mov    $0x1,%edi
lea    0xd3e(%rip),%rsi
call   10a0 <err@plt>
mov    -0x1c(%rbp),%edi
lea    0xd1a(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     1344 <main+0x194>
mov    $0x1,%edi
lea    0xd10(%rip),%rsi
call   10a0 <err@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
cmp    $0x1,%eax
je     1384 <main+0x1d4>
mov    $0x1,%edi
lea    0xcd6(%rip),%rsi
call   10a0 <err@plt>
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     13a6 <main+0x1f6>
mov    -0x24(%rbp),%edx
mov    $0x1,%edi
lea    0xcc1(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x28(%rbp),%eax
cmp    -0x14(%rbp),%eax
je     13c8 <main+0x218>
mov    -0x28(%rbp),%edx
mov    $0x1,%edi
lea    0xcb6(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
mov    -0x20(%rbp),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
je     13f3 <main+0x243>
mov    $0x1,%edi
lea    0xca4(%rip),%rsi
call   10a0 <err@plt>
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
mov    $0xa,%ecx
call   10b0 <epoll_wait@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0x0,-0x30(%rbp)
jge    143c <main+0x28c>
mov    $0x1,%edi
lea    0xc23(%rip),%rsi
call   10a0 <err@plt>
jmp    1461 <main+0x2b1>
cmpl   $0x0,-0x30(%rbp)
je     145c <main+0x2ac>
mov    -0x30(%rbp),%edx
mov    $0x1,%edi
lea    0xc42(%rip),%rsi
mov    $0x0,%al
call   1050 <errx@plt>
jmp    1461 <main+0x2b1>
lea    0xc4c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    -0x3(%rdi),%eax
cmp    $0xfffffffd,%eax
ja     11df <main+0x2f>
lea    0xe39(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%r14d
jmp    120c <main+0x5c>
mov    0x2df2(%rip),%rax
mov    (%rax),%r14d
cmp    $0x2,%edi
jne    120c <main+0x5c>
mov    0x8(%rsi),%rdi
lea    0xe1f(%rip),%rsi
call   1090 <strcmp@plt>
test   %eax,%eax
jne    120c <main+0x5c>
mov    0x2daf(%rip),%rax
or     (%rax),%r14d
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
call   10d0 <epoll_create1@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1231 <main+0x81>
lea    0xe06(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
lea    0x18(%rsp),%rdi
call   10c0 <pipe2@plt>
test   %rax,%rax
jns    125a <main+0xaa>
lea    0xdeb(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2d77(%rip),%rax
mov    0x2d50(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    0x2d7d(%rip),%rax
or     (%rax),%ecx
mov    0x2d34(%rip),%rax
or     (%rax),%ecx
mov    %ecx,0x10(%rsp)
mov    0x18(%rsp),%edx
mov    %edx,0x14(%rsp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rcx
mov    %ebp,%edi
call   1070 <epoll_ctl@plt>
test   %rax,%rax
jns    12b5 <main+0x105>
lea    0xd96(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x1c(%rsp),%edi
lea    0xd7a(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     12e0 <main+0x130>
lea    0xd79(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x1c(%rsp),%edi
lea    0xd4f(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
cmp    $0x1,%eax
je     130b <main+0x15b>
lea    0xd4e(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
cmp    $0x1,%eax
je     1349 <main+0x199>
lea    0xd16(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x14(%rsp),%edx
cmp    0x18(%rsp),%edx
je     1366 <main+0x1b6>
lea    0xd06(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x10(%rsp),%edx
cmp    %r14d,%edx
je     1382 <main+0x1d2>
lea    0xd01(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1050 <errx@plt>
mov    0x18(%rsp),%edi
lea    0xf(%rsp),%rsi
mov    $0x1,%edx
call   1080 <read@plt>
cmp    $0x1,%eax
je     13ab <main+0x1fb>
lea    0xcf1(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
mov    $0xa,%ecx
call   10b0 <epoll_wait@plt>
test   %eax,%eax
js     13f0 <main+0x240>
je     1401 <main+0x251>
lea    0xcb7(%rip),%rsi
mov    $0x1,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <errx@plt>
jmp    1401 <main+0x251>
lea    0xc5e(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0xcac(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [24 x i8] c"invalid arguments count\00"
@EPOLLIN = global i32 0
@.str.1 = [21 x i8] c"EMULATE_GRAPHENE_BUG\00"
@EPOLLOUT = global i32 0
@EPOLL_CLOEXEC = global i32 0
@.str.2 = [14 x i8] c"epoll_create1\00"
@O_NONBLOCK = global i32 0
@.str.3 = [6 x i8] c"pipe2\00"
@EPOLLPRI = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [14 x i8] c"EPOLL_CTL_ADD\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [11 x i8] c"epoll_wait\00"
@.str.8 = [23 x i8] c"epoll invalid data: %d\00"
@.str.9 = [27 x i8] c"epoll invalid events: 0x%x\00"
@.str.10 = [5 x i8] c"read\00"
@.str.11 = [29 x i8] c"EPOLLET reported 2 times: %d\00"
@.str.12 = [8 x i8] c"TEST OK\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [2 x i32]
%9 = alloca %struct.epoll_event
%10 = alloca i8
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 1
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %14, %2
%20 = load i32, i32* @EPOLLIN
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 2
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcmp(i8* %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i32 %27, 0
br i1 %28, label %33, label %29
29: ; preds = %23
%30 = load i32, i32* @EPOLLOUT
%31 = load i32, i32* %6
%32 = or i32 %31, %30
store i32 %32, i32* %6
br label %33
33: ; preds = %29, %23, %19
%34 = load i32, i32* @EPOLL_CLOEXEC
%35 = call i32 @epoll_create1(i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %33
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%42 = load i32, i32* @O_NONBLOCK
%43 = call i64 @pipe2(i32* %41, i32 %42)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %47
47: ; preds = %45, %40
%48 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%49 = load i32, i32* @EPOLLIN
%50 = load i32, i32* @EPOLLOUT
%51 = or i32 %49, %50
%52 = load i32, i32* @EPOLLPRI
%53 = or i32 %51, %52
%54 = load i32, i32* @EPOLLET
%55 = or i32 %53, %54
store i32 %55, i32* %48
%56 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
%57 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %56, i32 0, i32 0
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%59 = load i32, i32* %58
store i32 %59, i32* %57
%60 = load i32, i32* %7
%61 = load i32, i32* @EPOLL_CTL_ADD
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i64 @epoll_ctl(i32 %60, i32 %61, i32 %63, %struct.epoll_event* %9)
%65 = icmp slt i64 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %47
%67 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %68
68: ; preds = %66, %47
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @write(i32 %70, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
%72 = icmp ne i32 %71, 1
br i1 %72, label %73, label %75
73: ; preds = %68
%74 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %75
75: ; preds = %73, %68
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @write(i32 %77, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
%79 = icmp ne i32 %78, 1
br i1 %79, label %80, label %82
80: ; preds = %75
%81 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %82
82: ; preds = %80, %75
%83 = call i32 @memset(%struct.epoll_event* %9, i8 signext 0, i32 8)
%84 = load i32, i32* %7
%85 = call i32 @epoll_wait(i32 %84, %struct.epoll_event* %9, i32 1, i32 -1)
%86 = icmp ne i32 %85, 1
br i1 %86, label %87, label %89
87: ; preds = %82
%88 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %89
89: ; preds = %87, %82
%90 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
%91 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %90, i32 0, i32 0
%92 = load i32, i32* %91
%93 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%94 = load i32, i32* %93
%95 = icmp ne i32 %92, %94
br i1 %95, label %96, label %101
96: ; preds = %89
%97 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 1
%98 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %99)
br label %101
101: ; preds = %96, %89
%102 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%103 = load i32, i32* %102
%104 = load i32, i32* %6
%105 = icmp ne i32 %103, %104
br i1 %105, label %106, label %110
106: ; preds = %101
%107 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i32 0, i32 0
%108 = load i32, i32* %107
%109 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %108)
br label %110
110: ; preds = %106, %101
%111 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%112 = load i32, i32* %111
%113 = call i32 @read(i32 %112, i8* %10, i32 1)
%114 = icmp ne i32 %113, 1
br i1 %114, label %115, label %117
115: ; preds = %110
%116 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %117
117: ; preds = %115, %110
%118 = call i32 @memset(%struct.epoll_event* %9, i8 signext 0, i32 8)
%119 = load i32, i32* %7
%120 = call i32 @epoll_wait(i32 %119, %struct.epoll_event* %9, i32 1, i32 10)
store i32 %120, i32* %11
%121 = load i32, i32* %11
%122 = icmp slt i32 %121, 0
br i1 %122, label %123, label %125
123: ; preds = %117
%124 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %132
125: ; preds = %117
%126 = load i32, i32* %11
%127 = icmp ne i32 %126, 0
br i1 %127, label %128, label %131
128: ; preds = %125
%129 = load i32, i32* %11
%130 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i32 %129)
br label %131
131: ; preds = %128, %125
br label %132
132: ; preds = %131, %123
%133 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [24 x i8] c"invalid arguments count\00"
@EPOLLIN = global i32 0
@.str.1 = [21 x i8] c"EMULATE_GRAPHENE_BUG\00"
@EPOLLOUT = global i32 0
@EPOLL_CLOEXEC = global i32 0
@.str.2 = [14 x i8] c"epoll_create1\00"
@O_NONBLOCK = global i32 0
@.str.3 = [6 x i8] c"pipe2\00"
@EPOLLPRI = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [14 x i8] c"EPOLL_CTL_ADD\00"
@.str.5 = [1 x i8] zeroinitializer
@.str.6 = [6 x i8] c"write\00"
@.str.7 = [11 x i8] c"epoll_wait\00"
@.str.8 = [23 x i8] c"epoll invalid data: %d\00"
@.str.9 = [27 x i8] c"epoll invalid events: 0x%x\00"
@.str.10 = [5 x i8] c"read\00"
@.str.11 = [29 x i8] c"EPOLLET reported 2 times: %d\00"
@.str.12 = [8 x i8] c"TEST OK\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca %struct.epoll_event
%5 = alloca i8
%6 = add i32 %0, -3
%7 = icmp ult i32 %6, -2
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @EPOLLIN
br label %22
11: ; preds = %2
%12 = load i32, i32* @EPOLLIN
%13 = icmp eq i32 %0, 2
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = tail call i32 @strcmp(i8* dereferenceable(1) %16, i8* dereferenceable(21) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @EPOLLOUT
%21 = or i32 %20, %12
br label %22
22: ; preds = %8, %19, %14, %11
%23 = phi i32 [ %12, %14 ], [ %21, %19 ], [ %12, %11 ], [ %10, %8 ]
%24 = load i32, i32* @EPOLL_CLOEXEC
%25 = tail call i32 @epoll_create1(i32 %24)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = bitcast [2 x i32]* %3 to i8*
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%32 = load i32, i32* @O_NONBLOCK
%33 = call i64 @pipe2(i32* %31, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %29
%36 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
br label %37
37: ; preds = %35, %29
%38 = bitcast %struct.epoll_event* %4 to i8*
%39 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0
%40 = load i32, i32* @EPOLLIN
%41 = load i32, i32* @EPOLLOUT
%42 = or i32 %41, %40
%43 = load i32, i32* @EPOLLPRI
%44 = or i32 %42, %43
%45 = load i32, i32* @EPOLLET
%46 = or i32 %44, %45
store i32 %46, i32* %39
%47 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 1, i32 0
%48 = load i32, i32* %31
store i32 %48, i32* %47
%49 = load i32, i32* @EPOLL_CTL_ADD
%50 = call i64 @epoll_ctl(i32 %25, i32 %49, i32 %48, %struct.epoll_event* %4)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %37
%53 = call i32 @err(i32 1, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
br label %54
54: ; preds = %52, %37
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%56 = load i32, i32* %55
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
%58 = icmp eq i32 %57, 1
br i1 %58, label %61, label %59
59: ; preds = %54
%60 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %59, %54
%62 = load i32, i32* %55
%63 = call i32 @write(i32 %62, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), i32 1)
%64 = icmp eq i32 %63, 1
br i1 %64, label %67, label %65
65: ; preds = %61
%66 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %67
67: ; preds = %65, %61
%68 = call i32 @memset(%struct.epoll_event* %4, i8 signext 0, i32 8)
%69 = call i32 @epoll_wait(i32 %25, %struct.epoll_event* %4, i32 1, i32 -1)
%70 = icmp eq i32 %69, 1
br i1 %70, label %73, label %71
71: ; preds = %67
%72 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %73
73: ; preds = %71, %67
%74 = load i32, i32* %47
%75 = load i32, i32* %31
%76 = icmp eq i32 %74, %75
br i1 %76, label %79, label %77
77: ; preds = %73
%78 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %74)
br label %79
79: ; preds = %77, %73
%80 = load i32, i32* %39
%81 = icmp eq i32 %80, %23
br i1 %81, label %84, label %82
82: ; preds = %79
%83 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0), i32 %80)
br label %84
84: ; preds = %82, %79
%85 = load i32, i32* %31
%86 = call i32 @read(i32 %85, i8* %5, i32 1)
%87 = icmp eq i32 %86, 1
br i1 %87, label %90, label %88
88: ; preds = %84
%89 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %90
90: ; preds = %88, %84
%91 = call i32 @memset(%struct.epoll_event* %4, i8 signext 0, i32 8)
%92 = call i32 @epoll_wait(i32 %25, %struct.epoll_event* %4, i32 1, i32 10)
%93 = icmp slt i32 %92, 0
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 @err(i32 1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %100
96: ; preds = %90
%97 = icmp eq i32 %92, 0
br i1 %97, label %100, label %98
98: ; preds = %96
%99 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.11, i64 0, i64 0), i32 %92)
br label %100
100: ; preds = %96, %98, %94
%101 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
ret i32 0
}