#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 EPOLLERR;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int /*<<< orphan*/,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
scalar_t__ malloc(int const);
int /*<<< orphan*/ memset(struct epoll_event *, int /*<<< orphan*/, int const);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_x(struct epoll_event *, int const);
int main() {
  const int ev_size = sizeof(struct epoll_event);
  int i, idx, epfd, nEvent;
  struct epoll_event *ev, eventList[3];
  epfd = epoll_create(1);
  if (-1 == epfd) {
    perror("Can't create epoll");
    return -1;
  }
  ev = (struct epoll_event *)malloc(ev_size);
  memset(ev, 0, ev_size);
  ev->events = EPOLLIN | EPOLLOUT;
  ev->data.fd = 0x123456;
  print_x(ev, ev_size);
  epoll_ctl(epfd, EPOLL_CTL_ADD, 0, ev);
  nEvent = epoll_wait(epfd, eventList, 3, -1);
  for (i = 0; i < nEvent; i++) {
    if (eventList[i].events & EPOLLERR) {
      return 1;
    }
    print_x(eventList + i, ev_size);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x8,-0x8(%rbp)
mov    $0x1,%edi
call   1090 <epoll_create@plt>
mov    %eax,-0x14(%rbp)
mov    $0xffffffff,%eax
cmp    -0x14(%rbp),%eax
jne    11b9 <main+0x49>
lea    0xe58(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    129f <main+0x12f>
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e0a(%rip),%rax
mov    (%rax),%ecx
mov    0x2de1(%rip),%rax
or     (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%rax
movl   $0x123456,0x4(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x8,%esi
call   1080 <print_x@plt>
mov    -0x14(%rbp),%edi
mov    0x2dce(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
call   1040 <epoll_ctl@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
mov    $0xffffffff,%ecx
call   1060 <epoll_wait@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1298 <main+0x128>
movslq -0xc(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%eax
mov    0x2d76(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1271 <main+0x101>
movl   $0x1,-0x4(%rbp)
jmp    129f <main+0x12f>
lea    -0x40(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x3,%rax
add    %rax,%rdi
mov    $0x8,%esi
call   1080 <print_x@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    123f <main+0xcf>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x1,%edi
call   1090 <epoll_create@plt>
cmp    $0xffffffff,%eax
je     1244 <main+0xd4>
mov    %eax,%ebp
mov    $0x8,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e33(%rip),%rax
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rbx)
movl   $0x123456,0x4(%rbx)
mov    %rbx,%rdi
mov    $0x8,%esi
call   1080 <print_x@plt>
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
xor    %edx,%edx
mov    %rbx,%rcx
call   1040 <epoll_ctl@plt>
mov    %rsp,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
mov    $0xffffffff,%ecx
call   1060 <epoll_wait@plt>
test   %eax,%eax
jle    1236 <main+0xc6>
mov    %eax,%ebp
mov    0x2dc1(%rip),%r15
nop
mov    (%r15),%eax
test   %eax,(%rbx)
jne    1230 <main+0xc0>
mov    %rbx,%rdi
mov    $0x8,%esi
call   1080 <print_x@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1210 <main+0xa0>
jmp    1236 <main+0xc6>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb5(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%r14d
jmp    1236 <main+0xc6>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [19 x i8] c"Can't create epoll\00"
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLL_CTL_ADD = global i32 0
@EPOLLERR = 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 [3 x %struct.epoll_event]
store i32 0, i32* %1
store i32 8, i32* %2
%9 = call i32 @epoll_create(i32 1)
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = icmp eq i32 -1, %10
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %60
14: ; preds = %0
%15 = call i64 @malloc(i32 8)
%16 = inttoptr i64 %15 to %struct.epoll_event*
store %struct.epoll_event* %16, %struct.epoll_event** %7
%17 = load %struct.epoll_event*, %struct.epoll_event** %7
%18 = call i32 @memset(%struct.epoll_event* %17, i32 0, i32 8)
%19 = load i32, i32* @EPOLLIN
%20 = load i32, i32* @EPOLLOUT
%21 = or i32 %19, %20
%22 = load %struct.epoll_event*, %struct.epoll_event** %7
%23 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %22, i32 0, i32 0
store i32 %21, i32* %23
%24 = load %struct.epoll_event*, %struct.epoll_event** %7
%25 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %24, i32 0, i32 1
%26 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %25, i32 0, i32 0
store i32 1193046, i32* %26
%27 = load %struct.epoll_event*, %struct.epoll_event** %7
%28 = call i32 @print_x(%struct.epoll_event* %27, i32 8)
%29 = load i32, i32* %5
%30 = load i32, i32* @EPOLL_CTL_ADD
%31 = load %struct.epoll_event*, %struct.epoll_event** %7
%32 = call i32 @epoll_ctl(i32 %29, i32 %30, i32 0, %struct.epoll_event* %31)
%33 = load i32, i32* %5
%34 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %8, i64 0, i64 0
%35 = call i32 @epoll_wait(i32 %33, %struct.epoll_event* %34, i32 3, i32 -1)
store i32 %35, i32* %6
store i32 0, i32* %3
br label %36
36: ; preds = %56, %14
%37 = load i32, i32* %3
%38 = load i32, i32* %6
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %59
40: ; preds = %36
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %8, i64 0, i64 %42
%44 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %43, i32 0, i32 0
%45 = load i32, i32* %44
%46 = load i32, i32* @EPOLLERR
%47 = and i32 %45, %46
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %40
store i32 1, i32* %1
br label %60
50: ; preds = %40
%51 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %8, i64 0, i64 0
%52 = load i32, i32* %3
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %51, i64 %53
%55 = call i32 @print_x(%struct.epoll_event* %54, i32 8)
br label %56
56: ; preds = %50
%57 = load i32, i32* %3
%58 = add nsw i32 %57, 1
store i32 %58, i32* %3
br label %36
59: ; preds = %36
store i32 0, i32* %1
br label %60
60: ; preds = %59, %49, %12
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [19 x i8] c"Can't create epoll\00"
@EPOLLIN = global i32 0
@EPOLLOUT = global i32 0
@EPOLL_CTL_ADD = global i32 0
@EPOLLERR = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.epoll_event]
%2 = bitcast [3 x %struct.epoll_event]* %1 to i8*
%3 = tail call i32 @epoll_create(i32 1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %36
7: ; preds = %0
%8 = tail call i64 @malloc(i32 8)
%9 = inttoptr i64 %8 to %struct.epoll_event*
%10 = tail call i32 @memset(%struct.epoll_event* %9, i32 0, i32 8)
%11 = load i32, i32* @EPOLLIN
%12 = load i32, i32* @EPOLLOUT
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 1, i32 0
store i32 1193046, i32* %15
%16 = tail call i32 @print_x(%struct.epoll_event* %9, i32 8)
%17 = load i32, i32* @EPOLL_CTL_ADD
%18 = tail call i32 @epoll_ctl(i32 %3, i32 %17, i32 0, %struct.epoll_event* %9)
%19 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %1, i64 0, i64 0
%20 = call i32 @epoll_wait(i32 %3, %struct.epoll_event* %19, i32 3, i32 -1)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %7
%23 = zext i32 %20 to i64
br label %24
24: ; preds = %22, %31
%25 = phi i64 [ 0, %22 ], [ %34, %31 ]
%26 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %1, i64 0, i64 %25, i32 0
%27 = load i32, i32* %26
%28 = load i32, i32* @EPOLLERR
%29 = and i32 %28, %27
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %36
31: ; preds = %24
%32 = getelementptr inbounds [3 x %struct.epoll_event], [3 x %struct.epoll_event]* %1, i64 0, i64 %25
%33 = call i32 @print_x(%struct.epoll_event* %32, i32 8)
%34 = add nuw nsw i64 %25, 1
%35 = icmp eq i64 %34, %23
br i1 %35, label %36, label %24
36: ; preds = %24, %31, %7, %5
%37 = phi i32 [ -1, %5 ], [ 0, %7 ], [ 1, %24 ], [ 0, %31 ]
ret i32 %37
}