#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*/ _accept_epoll_connections(int, int);
int /*<<< orphan*/ _remove_epoll_socket(int, int);
int /*<<< orphan*/ assert(int);
int read(int, char *, int);
int /*<<< orphan*/ throw(char *);
int write(int, char *, int);
void _handle_epoll_requests(int epfd, int server_socket,
                            struct epoll_event *events,
                            size_t number_of_events) {
  char buffer[4096];
  assert(number_of_events > 0);
  for (size_t index = 0; index < number_of_events; ++index) {
    int fd = events[index].data.fd;
    assert(events[index].events & EPOLLIN);
    if (fd == server_socket) {
      _accept_epoll_connections(epfd, server_socket);
    } else {
      int amount_read;
      if ((amount_read = read(fd, buffer, 4096)) == 0) {
        _remove_epoll_socket(epfd, fd);
      } else if (amount_read < 4096) {
        throw("Error reading on server side");
      } else {
        if (write(fd, buffer, 4096) < 4096) {
          throw("Error writing on server side");
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<_handle_epoll_requests>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movq   $0x0,-0x1028(%rbp)
mov    -0x1028(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12aa <_handle_epoll_requests+0x14a>
mov    -0x10(%rbp),%rax
mov    -0x1028(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%eax
mov    %eax,-0x102c(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x1028(%rbp),%rcx
mov    (%rax,%rcx,8),%edi
mov    0x2e17(%rip),%rax
and    (%rax),%edi
call   1060 <assert@plt>
mov    -0x102c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11f7 <_handle_epoll_requests+0x97>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <_accept_epoll_connections@plt>
jmp    128e <_handle_epoll_requests+0x12e>
mov    -0x102c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
mov    %eax,-0x1030(%rbp)
cmp    $0x0,%eax
jne    1230 <_handle_epoll_requests+0xd0>
mov    -0x4(%rbp),%edi
mov    -0x102c(%rbp),%esi
call   1080 <_remove_epoll_socket@plt>
jmp    1289 <_handle_epoll_requests+0x129>
cmpl   $0x1000,-0x1030(%rbp)
jge    1251 <_handle_epoll_requests+0xf1>
lea    0xdb9(%rip),%rdi
call   1070 <throw@plt>
jmp    1284 <_handle_epoll_requests+0x124>
mov    -0x102c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
cmp    $0x1000,%eax
jge    127f <_handle_epoll_requests+0x11f>
lea    0xda3(%rip),%rdi
call   1070 <throw@plt>
jmp    1284 <_handle_epoll_requests+0x124>
jmp    1289 <_handle_epoll_requests+0x129>
jmp    128e <_handle_epoll_requests+0x12e>
jmp    1293 <_handle_epoll_requests+0x133>
mov    -0x1028(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
jmp    1196 <_handle_epoll_requests+0x36>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_handle_epoll_requests>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1008,%rsp
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %edi,%r15d
xor    %edi,%edi
test   %rcx,%rcx
setne  %dil
call   1060 <assert@plt>
test   %r14,%r14
je     1225 <_handle_epoll_requests+0xc5>
xor    %r12d,%r12d
jmp    11b3 <_handle_epoll_requests+0x53>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
mov    %ebp,%esi
call   1040 <_accept_epoll_connections@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     1225 <_handle_epoll_requests+0xc5>
mov    0x4(%rbx,%r12,8),%r13d
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
and    (%rbx,%r12,8),%edi
call   1060 <assert@plt>
cmp    %ebp,%r13d
je     11a0 <_handle_epoll_requests+0x40>
mov    %r13d,%edi
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1050 <read@plt>
test   %eax,%eax
je     11f3 <_handle_epoll_requests+0x93>
cmp    $0xfff,%eax
jg     1200 <_handle_epoll_requests+0xa0>
lea    0xe0f(%rip),%rdi
jmp    121e <_handle_epoll_requests+0xbe>
mov    %r15d,%edi
mov    %r13d,%esi
call   1080 <_remove_epoll_socket@plt>
jmp    11aa <_handle_epoll_requests+0x4a>
mov    %r13d,%edi
mov    %rsp,%rsi
mov    $0x1000,%edx
call   1030 <write@plt>
cmp    $0xfff,%eax
jg     11aa <_handle_epoll_requests+0x4a>
lea    0xdff(%rip),%rdi
call   1070 <throw@plt>
jmp    11aa <_handle_epoll_requests+0x4a>
add    $0x1008,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@.str = [29 x i8] c"Error reading on server side\00"
@.str.1 = [29 x i8] c"Error writing on server side\00"
define void @_handle_epoll_requests(i32 %0, i32 %1, %struct.epoll_event* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.epoll_event*
%8 = alloca i64
%9 = alloca [4096 x i8]
%10 = alloca i64
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store %struct.epoll_event* %2, %struct.epoll_event** %7
store i64 %3, i64* %8
%13 = load i64, i64* %8
%14 = icmp ugt i64 %13, 0
%15 = zext i1 %14 to i32
%16 = call i32 @assert(i32 %15)
store i64 0, i64* %10
br label %17
17: ; preds = %68, %4
%18 = load i64, i64* %10
%19 = load i64, i64* %8
%20 = icmp ult i64 %18, %19
br i1 %20, label %21, label %71
21: ; preds = %17
%22 = load %struct.epoll_event*, %struct.epoll_event** %7
%23 = load i64, i64* %10
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %22, i64 %23
%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
%27 = load i32, i32* %26
store i32 %27, i32* %11
%28 = load %struct.epoll_event*, %struct.epoll_event** %7
%29 = load i64, i64* %10
%30 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %28, i64 %29
%31 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = load i32, i32* @EPOLLIN
%34 = and i32 %32, %33
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %11
%37 = load i32, i32* %6
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %21
%40 = load i32, i32* %5
%41 = load i32, i32* %6
%42 = call i32 @_accept_epoll_connections(i32 %40, i32 %41)
br label %67
43: ; preds = %21
%44 = load i32, i32* %11
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%46 = call i32 @read(i32 %44, i8* %45, i32 4096)
store i32 %46, i32* %12
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %52
48: ; preds = %43
%49 = load i32, i32* %5
%50 = load i32, i32* %11
%51 = call i32 @_remove_epoll_socket(i32 %49, i32 %50)
br label %66
52: ; preds = %43
%53 = load i32, i32* %12
%54 = icmp slt i32 %53, 4096
br i1 %54, label %55, label %57
55: ; preds = %52
%56 = call i32 @throw(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %65
57: ; preds = %52
%58 = load i32, i32* %11
%59 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
%60 = call i32 @write(i32 %58, i8* %59, i32 4096)
%61 = icmp slt i32 %60, 4096
br i1 %61, label %62, label %64
62: ; preds = %57
%63 = call i32 @throw(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %64
64: ; preds = %62, %57
br label %65
65: ; preds = %64, %55
br label %66
66: ; preds = %65, %48
br label %67
67: ; preds = %66, %39
br label %68
68: ; preds = %67
%69 = load i64, i64* %10
%70 = add i64 %69, 1
store i64 %70, i64* %10
br label %17
71: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@.str = [29 x i8] c"Error reading on server side\00"
@.str.1 = [29 x i8] c"Error writing on server side\00"
define void @_handle_epoll_requests(i32 %0, i32 %1, %struct.epoll_event* nocapture %2, i64 %3) {
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%7 = icmp ne i64 %3, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = icmp eq i64 %3, 0
br i1 %10, label %11, label %12
11: ; preds = %38, %4
ret void
12: ; preds = %4, %38
%13 = phi i64 [ %39, %38 ], [ 0, %4 ]
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 %13, i32 1, i32 0
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 %13, i32 0
%17 = load i32, i32* %16
%18 = load i32, i32* @EPOLLIN
%19 = and i32 %18, %17
%20 = tail call i32 @assert(i32 %19)
%21 = icmp eq i32 %15, %1
br i1 %21, label %22, label %24
22: ; preds = %12
%23 = tail call i32 @_accept_epoll_connections(i32 %0, i32 %1)
br label %38
24: ; preds = %12
%25 = call i32 @read(i32 %15, i8* %6, i32 4096)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %24
%28 = tail call i32 @_remove_epoll_socket(i32 %0, i32 %15)
br label %38
29: ; preds = %24
%30 = icmp slt i32 %25, 4096
br i1 %30, label %31, label %33
31: ; preds = %29
%32 = tail call i32 @throw(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %38
33: ; preds = %29
%34 = call i32 @write(i32 %15, i8* %6, i32 4096)
%35 = icmp slt i32 %34, 4096
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = tail call i32 @throw(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %27, %33, %36, %31, %22
%39 = add nuw i64 %13, 1
%40 = icmp eq i64 %39, %3
br i1 %40, label %11, label %12
}