#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 user_list {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
};

/* Variables and functions */
scalar_t__ accept_client(int, int);
int /*<<< orphan*/ close(int);
struct user_list *create_user_list();
int epoll_wait(int, struct epoll_event *, int, int);
scalar_t__ init_server(int *, int *);
int /*<<< orphan*/ printf(char *);
scalar_t__ serve_client(int, struct epoll_event *, struct user_list *);
int main(int argc, const char *argv[]) {
  int i = 0;
  int srv_fd = -1;
  int epoll_fd = -1;
  struct epoll_event es[1000];
  struct user_list *ul = create_user_list();
  if (init_server(&srv_fd, &epoll_fd) != 0)
    return 1;
  for (;;) {
    i = epoll_wait(epoll_fd, es, 1000, -1);
    if (i < 0) {
      printf("Cannot wait for events\n");
      close(epoll_fd);
      close(srv_fd);
      return 1;
    }
    for (--i; i > -1; --i) {
      if (es[i].data.fd == srv_fd) {
        if (accept_client(srv_fd, epoll_fd) < 0)
          return 1;
      } else {
        if (serve_client(epoll_fd, &es[i], ul) < 0) {
          close(epoll_fd);
          close(srv_fd);
          return 1;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <create_user_list@plt>
mov    %rax,-0xfc8(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <init_server@plt>
cmp    $0x0,%rax
je     11cf <main+0x5f>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
jmp    11d4 <main+0x64>
mov    -0x1c(%rbp),%edi
lea    -0xfc0(%rbp),%rsi
mov    $0x3e8,%edx
mov    $0xffffffff,%ecx
call   1090 <epoll_wait@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1222 <main+0xb2>
lea    0xdff(%rip),%rdi
call   1060 <printf@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jle    12ce <main+0x15e>
movslq -0x14(%rbp),%rax
mov    -0xfc0(%rbp,%rax,4),%eax
cmp    -0x18(%rbp),%eax
jne    126f <main+0xff>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1050 <accept_client@plt>
cmp    $0x0,%rax
jge    126a <main+0xfa>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
jmp    12bb <main+0x14b>
mov    -0x1c(%rbp),%edi
movslq -0x14(%rbp),%rax
lea    -0xfc0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
mov    -0xfc8(%rbp),%rdx
call   1030 <serve_client@plt>
cmp    $0x0,%rax
jge    12b6 <main+0x146>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    12d3 <main+0x163>
jmp    12bb <main+0x14b>
jmp    12c0 <main+0x150>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    122b <main+0xbb>
jmp    11d4 <main+0x64>
mov    -0x4(%rbp),%eax
add    $0xfd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xfb0,%rsp
movl   $0xffffffff,0xc(%rsp)
ff
movl   $0xffffffff,0x8(%rsp)
ff
xor    %eax,%eax
call   1050 <create_user_list@plt>
mov    %rax,%r15
lea    0xc(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1080 <init_server@plt>
test   %rax,%rax
jne    126e <main+0xfe>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x3e8,%edx
mov    $0xffffffff,%ecx
call   1090 <epoll_wait@plt>
test   %eax,%eax
js     1250 <main+0xe0>
lea    0x10(%rsp),%r14
jmp    11fa <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x8(%rsp),%edi
mov    %r14,%rsi
mov    $0x3e8,%edx
mov    $0xffffffff,%ecx
call   1090 <epoll_wait@plt>
test   %eax,%eax
js     1250 <main+0xe0>
test   %eax,%eax
je     11e0 <main+0x70>
mov    %eax,%ebx
add    $0x1,%rbx
jmp    1231 <main+0xc1>
cs nopw 0x0(%rax,%rax,1)
lea    (%rsp,%rcx,4),%rsi
add    $0x10,%rsi
mov    %eax,%edi
mov    %r15,%rdx
call   1030 <serve_client@plt>
test   %rax,%rax
js     125c <main+0xec>
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11e0 <main+0x70>
lea    -0x2(%rbx),%ecx
mov    0x10(%rsp,%rcx,4),%edi
mov    0x8(%rsp),%eax
cmp    0xc(%rsp),%edi
jne    1210 <main+0xa0>
mov    %eax,%esi
call   1060 <accept_client@plt>
test   %rax,%rax
jns    1227 <main+0xb7>
jmp    126e <main+0xfe>
lea    0xda9(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    $0x1,%eax
add    $0xfb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.user_list = type { i32 }
@.str = [24 x i8] c"Cannot wait for events\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1000 x %struct.epoll_event]
%10 = alloca %struct.user_list*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
%11 = call %struct.user_list* (...) @create_user_list()
store %struct.user_list* %11, %struct.user_list** %10
%12 = call i64 @init_server(i32* %7, i32* %8)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 1, i32* %3
br label %69
15: ; preds = %2
br label %16
16: ; preds = %68, %15
%17 = load i32, i32* %8
%18 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %9, i64 0, i64 0
%19 = call i32 @epoll_wait(i32 %17, %struct.epoll_event* %18, i32 1000, i32 -1)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* %8
%25 = call i32 @close(i32 %24)
%26 = load i32, i32* %7
%27 = call i32 @close(i32 %26)
store i32 1, i32* %3
br label %69
28: ; preds = %16
%29 = load i32, i32* %6
%30 = add nsw i32 %29, -1
store i32 %30, i32* %6
br label %31
31: ; preds = %65, %28
%32 = load i32, i32* %6
%33 = icmp sgt i32 %32, -1
br i1 %33, label %34, label %68
34: ; preds = %31
%35 = load i32, i32* %6
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %9, i64 0, i64 %36
%38 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %37, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i32, i32* %7
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %50
43: ; preds = %34
%44 = load i32, i32* %7
%45 = load i32, i32* %8
%46 = call i64 @accept_client(i32 %44, i32 %45)
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %49
48: ; preds = %43
store i32 1, i32* %3
br label %69
49: ; preds = %43
br label %64
50: ; preds = %34
%51 = load i32, i32* %8
%52 = load i32, i32* %6
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %9, i64 0, i64 %53
%55 = load %struct.user_list*, %struct.user_list** %10
%56 = call i64 @serve_client(i32 %51, %struct.epoll_event* %54, %struct.user_list* %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %50
%59 = load i32, i32* %8
%60 = call i32 @close(i32 %59)
%61 = load i32, i32* %7
%62 = call i32 @close(i32 %61)
store i32 1, i32* %3
br label %69
63: ; preds = %50
br label %64
64: ; preds = %63, %49
br label %65
65: ; preds = %64
%66 = load i32, i32* %6
%67 = add nsw i32 %66, -1
store i32 %67, i32* %6
br label %31
68: ; preds = %31
br label %16
69: ; preds = %58, %48, %22, %14
%70 = load i32, i32* %3
ret i32 %70
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.user_list = type { i32 }
@str = [23 x i8] c"Cannot wait for events\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x %struct.epoll_event]
%6 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%7 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%8 = bitcast [1000 x %struct.epoll_event]* %5 to i8*
%9 = tail call %struct.user_list* (...) @create_user_list()
%10 = call i64 @init_server(i32* %3, i32* %4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %51
12: ; preds = %2
%13 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %5, i64 0, i64 0
%14 = load i32, i32* %4
%15 = call i32 @epoll_wait(i32 %14, %struct.epoll_event* %13, i32 1000, i32 -1)
%16 = icmp slt i32 %15, 0
br i1 %16, label %26, label %21
17: ; preds = %44, %21
%18 = load i32, i32* %4
%19 = call i32 @epoll_wait(i32 %18, %struct.epoll_event* %13, i32 1000, i32 -1)
%20 = icmp slt i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %12, %17
%22 = phi i32 [ %19, %17 ], [ %15, %12 ]
%23 = icmp eq i32 %22, 0
br i1 %23, label %17, label %24
24: ; preds = %21
%25 = zext i32 %22 to i64
br label %28
26: ; preds = %17, %12
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %46
28: ; preds = %24, %44
%29 = phi i64 [ %25, %24 ], [ %30, %44 ]
%30 = add nsw i64 %29, -1
%31 = and i64 %30, 4294967295
%32 = getelementptr inbounds [1000 x %struct.epoll_event], [1000 x %struct.epoll_event]* %5, i64 0, i64 %31
%33 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %32, i64 0, i32 0, i32 0
%34 = load i32, i32* %33
%35 = load i32, i32* %3
%36 = icmp eq i32 %34, %35
%37 = load i32, i32* %4
br i1 %36, label %38, label %41
38: ; preds = %28
%39 = call i64 @accept_client(i32 %34, i32 %37)
%40 = icmp slt i64 %39, 0
br i1 %40, label %51, label %44
41: ; preds = %28
%42 = call i64 @serve_client(i32 %37, %struct.epoll_event* %32, %struct.user_list* %9)
%43 = icmp slt i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %38, %41
%45 = icmp ugt i64 %29, 1
br i1 %45, label %28, label %17
46: ; preds = %41, %26
%47 = load i32, i32* %4
%48 = call i32 @close(i32 %47)
%49 = load i32, i32* %3
%50 = call i32 @close(i32 %49)
br label %51
51: ; preds = %38, %46, %2
ret i32 1
}