#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*/ STDIN_FILENO;
int /*<<< orphan*/ add_event(int, int /*<<< orphan*/, 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 *);
void handle_connection(int sockfd) {
  int epollfd;
  struct epoll_event events[20];
  char buf[1024];
  int ret;
  epollfd = epoll_create(1024);
  add_event(epollfd, STDIN_FILENO, EPOLLIN);
  for (;;) {
    ret = epoll_wait(epollfd, events, 20, -1);
    handle_events(epollfd, events, ret, sockfd, buf);
  }
  close(epollfd);
}


x86 assembly (clang, -O0):
<handle_connection>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x400,%edi
call   1060 <epoll_create@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e73(%rip),%rax
mov    (%rax),%esi
mov    0x2e7a(%rip),%rax
mov    (%rax),%edx
call   1050 <add_event@plt>
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0x14,%edx
mov    $0xffffffff,%ecx
call   1040 <epoll_wait@plt>
mov    %eax,-0x464(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    -0x464(%rbp),%edx
mov    -0x4(%rbp),%ecx
lea    -0x460(%rbp),%r8
call   1030 <handle_events@plt>
jmp    1175 <handle_connection+0x35>

x86 assembly (clang, -O2):
<handle_connection>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x458,%rsp
mov    %edi,%r14d
mov    $0x400,%edi
call   1060 <epoll_create@plt>
mov    %eax,%ebp
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
call   1050 <add_event@plt>
mov    %rsp,%rbx
lea    0x50(%rsp),%r15
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
mov    $0xffffffff,%ecx
call   1040 <epoll_wait@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
mov    %r14d,%ecx
mov    %r15,%r8
call   1030 <handle_events@plt>
jmp    1180 <handle_connection+0x40>

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

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