#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 epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int /*<<< orphan*/,
              struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ printf(char *, int, int);
int main() {
  int efd = epoll_create(10);
  struct epoll_event x;
  if (efd == -1)
    return 111;
  x.events = EPOLLIN;
  x.data.fd = 0;
  if (epoll_ctl(efd, EPOLL_CTL_ADD, 0, &x) == -1)
    return 111;
  {
    int i, n;
    struct epoll_event y[100];
    if ((n = epoll_wait(efd, y, 100, 1000)) == -1)
      return 111;
    if (n > 0)
      printf("event %d on fd #%d\n", y[0].events, y[0].data.fd);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x340,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0xa,%edi
call   1060 <epoll_create@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    1175 <main+0x35>
movl   $0x6f,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e4e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
lea    -0x10(%rbp),%rcx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    11b4 <main+0x74>
movl   $0x6f,-0x4(%rbp)
jmp    1207 <main+0xc7>
mov    -0x8(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    $0x64,%edx
mov    $0x3e8,%ecx
call   1050 <epoll_wait@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <main+0xa5>
movl   $0x6f,-0x4(%rbp)
jmp    1207 <main+0xc7>
cmpl   $0x0,-0x18(%rbp)
jle    1207 <main+0xc7>
mov    -0x340(%rbp),%esi
mov    -0x33c(%rbp),%edx
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x340,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x338,%rsp
mov    $0xa,%edi
call   1060 <epoll_create@plt>
mov    $0x6f,%ebx
cmp    $0xffffffff,%eax
je     11cc <main+0x8c>
mov    %eax,%ebp
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %ebp,%edi
xor    %edx,%edx
call   1040 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     11cc <main+0x8c>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x64,%edx
mov    $0x3e8,%ecx
call   1050 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     11c7 <main+0x87>
xor    %ebx,%ebx
test   %eax,%eax
jle    11cc <main+0x8c>
mov    0x10(%rsp),%esi
mov    0x14(%rsp),%edx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
jmp    11cc <main+0x8c>
mov    $0x6f,%ebx
mov    %ebx,%eax
add    $0x338,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [20 x i8] c"event %d on fd #%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.epoll_event
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x %struct.epoll_event]
store i32 0, i32* %1
%7 = call i32 @epoll_create(i32 10)
store i32 %7, i32* %2
%8 = load i32, i32* %2
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 111, i32* %1
br label %39
11: ; preds = %0
%12 = load i32, i32* @EPOLLIN
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i32 0, i32 0
store i32 %12, i32* %13
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i32 0, i32 1
%15 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %14, i32 0, i32 0
store i32 0, i32* %15
%16 = load i32, i32* %2
%17 = load i32, i32* @EPOLL_CTL_ADD
%18 = call i32 @epoll_ctl(i32 %16, i32 %17, i32 0, %struct.epoll_event* %3)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %21
20: ; preds = %11
store i32 111, i32* %1
br label %39
21: ; preds = %11
%22 = load i32, i32* %2
%23 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %6, i64 0, i64 0
%24 = call i32 @epoll_wait(i32 %22, %struct.epoll_event* %23, i32 100, i32 1000)
store i32 %24, i32* %5
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %27
26: ; preds = %21
store i32 111, i32* %1
br label %39
27: ; preds = %21
%28 = load i32, i32* %5
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27
%31 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %6, i64 0, i64 0
%32 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %6, i64 0, i64 0
%35 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %34, i32 0, i32 1
%36 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %33, i32 %37)
br label %39
39: ; preds = %10, %20, %26, %30, %27
%40 = load i32, i32* %1
ret i32 %40
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [20 x i8] c"event %d on fd #%d\0A\00"
define i32 @main() {
%1 = alloca %struct.epoll_event
%2 = alloca [100 x %struct.epoll_event]
%3 = tail call i32 @epoll_create(i32 10)
%4 = bitcast %struct.epoll_event* %1 to i8*
%5 = icmp eq i32 %3, -1
br i1 %5, label %28, label %6
6: ; preds = %0
%7 = load i32, i32* @EPOLLIN
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0
store i32 %7, i32* %8
%9 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1, i32 0
store i32 0, i32* %9
%10 = load i32, i32* @EPOLL_CTL_ADD
%11 = call i32 @epoll_ctl(i32 %3, i32 %10, i32 0, %struct.epoll_event* %1)
%12 = icmp eq i32 %11, -1
br i1 %12, label %28, label %13
13: ; preds = %6
%14 = bitcast [100 x %struct.epoll_event]* %2 to i8*
%15 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %2, i64 0, i64 0
%16 = call i32 @epoll_wait(i32 %3, %struct.epoll_event* %15, i32 100, i32 1000)
%17 = icmp eq i32 %16, -1
br i1 %17, label %26, label %18
18: ; preds = %13
%19 = icmp sgt i32 %16, 0
br i1 %19, label %20, label %26
20: ; preds = %18
%21 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %2, i64 0, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %2, i64 0, i64 0, i32 1, i32 0
%24 = load i32, i32* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %22, i32 %24)
br label %26
26: ; preds = %18, %20, %13
%27 = phi i32 [ 111, %13 ], [ 0, %20 ], [ 0, %18 ]
br label %28
28: ; preds = %6, %0, %26
%29 = phi i32 [ %27, %26 ], [ 111, %0 ], [ 111, %6 ]
ret i32 %29
}