#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 */

/* Type definitions */
struct epoll_event {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ add_event(int, int, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ handle_events(int, struct epoll_event *, int, int, char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
void do_epoll(int listenfd) {
  int epollfd;
  struct epoll_event events[1000];
  int ret;
  char buf[1024];
  memset(buf, 0, 1024);
  epollfd = epoll_create(1000);
  add_event(epollfd, listenfd, EPOLLIN);
  for (;;) {
    ret = epoll_wait(epollfd, events, 1000, -1);
    handle_events(epollfd, events, ret, listenfd, buf);
  }
  close(epollfd);
}


x86 assembly (clang, -O0):
<do_epoll>:
push   %rbp
mov    %rsp,%rbp
sub    $0x13c0,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x13c0(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    $0x3e8,%edi
call   1070 <epoll_create@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
call   1060 <add_event@plt>
mov    -0x8(%rbp),%edi
lea    -0xfb0(%rbp),%rsi
mov    $0x3e8,%edx
mov    $0xffffffff,%ecx
call   1050 <epoll_wait@plt>
mov    %eax,-0xfb4(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xfb0(%rbp),%rsi
mov    -0xfb4(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    -0x13c0(%rbp),%r8
call   1040 <handle_events@plt>
jmp    1192 <do_epoll+0x42>

x86 assembly (clang, -O2):
<do_epoll>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x13a8,%rsp
mov    %edi,%r15d
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1030 <memset@plt>
mov    $0x3e8,%edi
call   1070 <epoll_create@plt>
mov    %eax,%ebp
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    %r15d,%esi
call   1060 <add_event@plt>
lea    0x400(%rsp),%rbx
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
mov    $0xffffffff,%ecx
call   1050 <epoll_wait@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r15d,%ecx
mov    %r14,%r8
call   1040 <handle_events@plt>
jmp    11a0 <do_epoll+0x50>

LLVM IR (-O0):
%struct.epoll_event = type { i32 }
@EPOLLIN = global i32 0
define void @do_epoll(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1000 x %struct.epoll_event]
%5 = alloca i32
%6 = alloca [1024 x i8]
store i32 %0, i32* %2
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%8 = call i32 @memset(i8* %7, i32 0, i32 1024)
%9 = call i32 @epoll_create(i32 1000)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = load i32, i32* %2
%12 = load i32, i32* @EPOLLIN
%13 = call i32 @add_event(i32 %10, i32 %11, i32 %12)
br label %14
14: ; preds = %14, %1
%15 = load i32, i32* %3
%16 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %4, i64 0, i64 0
%17 = call i32 @epoll_wait(i32 %15, %struct.epoll_event* %16, i32 1000, i32 -1)
store i32 %17, i32* %5
%18 = load i32, i32* %3
%19 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %4, i64 0, i64 0
%20 = load i32, i32* %5
%21 = load i32, i32* %2
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @handle_events(i32 %18, %struct.epoll_event* %19, i32 %20, i32 %21, i8* %22)
br label %14
}

LLVM IR (-O2):
%struct.epoll_event = type { i32 }
@EPOLLIN = global i32 0
define void @do_epoll(i32 %0) {
%2 = alloca [1000 x %struct.epoll_event]
%3 = alloca [1024 x i8]
%4 = bitcast [1000 x %struct.epoll_event]* %2 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 1024)
%7 = call i32 @epoll_create(i32 1000)
%8 = load i32, i32* @EPOLLIN
%9 = call i32 @add_event(i32 %7, i32 %0, i32 %8)
%10 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %2, i64 0, i64 0
br label %11
11: ; preds = %11, %1
%12 = call i32 @epoll_wait(i32 %7, %struct.epoll_event* %10, i32 1000, i32 -1)
%13 = call i32 @handle_events(i32 %7, %struct.epoll_event* %10, i32 %12, i32 %0, i8* %5)
br label %11
}