#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 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);
  }
  return 0;
}


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    120e <main+0xce>
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    120e <main+0xce>
mov    -0x8(%rbp),%edi
lea    -0x340(%rbp),%rsi
mov    $0x64,%edx
mov    $0x3e8,%ecx
call   1050 <epoll_wait@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11e5 <main+0xa5>
movl   $0x6f,-0x4(%rbp)
jmp    120e <main+0xce>
cmpl   $0x0,-0x14(%rbp)
jle    1207 <main+0xc7>
mov    -0x340(%rbp),%esi
mov    -0x33c(%rbp),%edx
lea    0xdfe(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
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 [100 x %struct.epoll_event]
store i32 0, i32* %1
%6 = call i32 @epoll_create(i32 10)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 111, i32* %1
br label %39
10: ; preds = %0
%11 = load i32, i32* @EPOLLIN
%12 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i32 0, i32 0
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i32 0, i32 1
%14 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %13, i32 0, i32 0
store i32 0, i32* %14
%15 = load i32, i32* %2
%16 = load i32, i32* @EPOLL_CTL_ADD
%17 = call i32 @epoll_ctl(i32 %15, i32 %16, i32 0, %struct.epoll_event* %3)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %20
19: ; preds = %10
store i32 111, i32* %1
br label %39
20: ; preds = %10
%21 = load i32, i32* %2
%22 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %5, i64 0, i64 0
%23 = call i32 @epoll_wait(i32 %21, %struct.epoll_event* %22, i32 100, i32 1000)
store i32 %23, i32* %4
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %26
25: ; preds = %20
store i32 111, i32* %1
br label %39
26: ; preds = %20
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %5, i64 0, i64 0
%31 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %5, i64 0, i64 0
%34 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %33, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %32, i32 %36)
br label %38
38: ; preds = %29, %26
store i32 0, i32* %1
br label %39
39: ; preds = %38, %25, %19, %9
%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 [ 0, %18 ], [ 0, %20 ], [ 111, %13 ]
br label %28
28: ; preds = %26, %6, %0
%29 = phi i32 [ 111, %0 ], [ 111, %6 ], [ %27, %26 ]
ret i32 %29
}