#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SOMAXCONN;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ addfd(int, int, int);
char *basename(char *);
int /*<<< orphan*/ close(int);
int create_and_bind(char *);
int epoll_create1(int /*<<< orphan*/);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ lt(struct epoll_event *, int, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  int sfd, s;
  int efd;
  struct epoll_event event;
  struct epoll_event events[1024];
  if (argc < 2) {
    fprintf(stderr, "Usage: %s [port]\n", basename(argv[0]));
    exit(EXIT_FAILURE);
  }
  sfd = create_and_bind(argv[1]);
  if (sfd == -1)
    abort();
  s = listen(sfd, SOMAXCONN);
  if (s == -1) {
    perror("listen");
    abort();
  }
  efd = epoll_create1(0);
  if (efd == -1) {
    perror("epoll_create");
    abort();
  }
  addfd(efd, sfd, 1);
  while (1) {
    int ret = epoll_wait(efd, events, 1024, -1);
    if (ret < 0) {
      printf("epoll wait failture..\n");
      break;
    }
    lt(events, ret, efd, sfd);
  }
  close(sfd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1231 <main+0x61>
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1028(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <basename@plt>
mov    -0x1028(%rbp),%edi
mov    %rax,%rdx
lea    0xde2(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <create_and_bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1252 <main+0x82>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x14(%rbp),%edi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1090 <listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1283 <main+0xb3>
lea    0xd9b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
xor    %edi,%edi
call   10f0 <epoll_create1@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    12aa <main+0xda>
lea    0xd7b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x1c(%rbp),%edi
mov    -0x14(%rbp),%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
mov    -0x1c(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10a0 <epoll_wait@plt>
mov    %eax,-0x1024(%rbp)
cmpl   $0x0,-0x1024(%rbp)
jge    12f7 <main+0x127>
lea    0xd39(%rip),%rdi
call   1050 <printf@plt>
jmp    1314 <main+0x144>
lea    -0x1020(%rbp),%rdi
mov    -0x1024(%rbp),%esi
mov    -0x1c(%rbp),%edx
mov    -0x14(%rbp),%ecx
call   10d0 <lt@plt>
jmp    12ba <main+0xea>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
mov    0x2ca5(%rip),%rax
mov    (%rax),%eax
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
cmp    $0x1,%edi
jle    12a0 <main+0xd0>
mov    0x8(%rsi),%rdi
call   10b0 <create_and_bind@plt>
cmp    $0xffffffff,%eax
je     12d0 <main+0x100>
mov    %eax,%r14d
mov    0x2dd8(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
je     12d7 <main+0x107>
xor    %edi,%edi
call   10f0 <epoll_create1@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x110>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14d,%esi
mov    $0x1,%edx
call   1040 <addfd@plt>
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10a0 <epoll_wait@plt>
test   %eax,%eax
js     1277 <main+0xa7>
mov    %rsp,%rbx
nop
mov    %rbx,%rdi
mov    %eax,%esi
mov    %ebp,%edx
mov    %r14d,%ecx
call   10d0 <lt@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10a0 <epoll_wait@plt>
test   %eax,%eax
jns    1250 <main+0x80>
lea    0xda8(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d39(%rip),%rax
mov    (%rax),%ebx
mov    (%rsi),%rdi
call   1080 <basename@plt>
lea    0xd48(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>
lea    0xd34(%rip),%rdi
jmp    12e7 <main+0x117>
lea    0xd32(%rip),%rdi
call   10c0 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s [port]\0A\00"
@EXIT_FAILURE = global i32 0
@SOMAXCONN = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@.str.2 = [13 x i8] c"epoll_create\00"
@.str.3 = [23 x i8] c"epoll wait failture..\0A\00"
@EXIT_SUCCESS = global i32 0
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 %struct.epoll_event
%10 = alloca [1024 x %struct.epoll_event]
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %23
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i8* @basename(i8* %18)
%20 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @create_and_bind(i8* %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 (...) @abort()
unreachable
32: ; preds = %23
%33 = load i32, i32* %6
%34 = load i32, i32* @SOMAXCONN
%35 = call i32 @listen(i32 %33, i32 %34)
store i32 %35, i32* %7
%36 = load i32, i32* %7
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %32
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 (...) @abort()
unreachable
41: ; preds = %32
%42 = call i32 @epoll_create1(i32 0)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %41
%46 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 (...) @abort()
unreachable
48: ; preds = %41
%49 = load i32, i32* %8
%50 = load i32, i32* %6
%51 = call i32 @addfd(i32 %49, i32 %50, i32 1)
br label %52
52: ; preds = %48, %60
%53 = load i32, i32* %8
%54 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %10, i64 0, i64 0
%55 = call i32 @epoll_wait(i32 %53, %struct.epoll_event* %54, i32 1024, i32 -1)
store i32 %55, i32* %11
%56 = load i32, i32* %11
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %66
60: ; preds = %52
%61 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %10, i64 0, i64 0
%62 = load i32, i32* %11
%63 = load i32, i32* %8
%64 = load i32, i32* %6
%65 = call i32 @lt(%struct.epoll_event* %61, i32 %62, i32 %63, i32 %64)
br label %52
66: ; preds = %58
%67 = load i32, i32* %6
%68 = call i32 @close(i32 %67)
%69 = load i32, i32* @EXIT_SUCCESS
ret i32 %69
}

LLVM IR (-O2):
%struct.epoll_event = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s [port]\0A\00"
@EXIT_FAILURE = global i32 0
@SOMAXCONN = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@.str.2 = [13 x i8] c"epoll_create\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"epoll wait failture..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x %struct.epoll_event]
%4 = bitcast [1024 x %struct.epoll_event]* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %13
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i8* @basename(i8* %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 @create_and_bind(i8* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 (...) @abort()
unreachable
20: ; preds = %13
%21 = load i32, i32* @SOMAXCONN
%22 = tail call i32 @listen(i32 %16, i32 %21)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = tail call i32 (...) @abort()
unreachable
27: ; preds = %20
%28 = tail call i32 @epoll_create1(i32 0)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%32 = tail call i32 (...) @abort()
unreachable
33: ; preds = %27
%34 = tail call i32 @addfd(i32 %28, i32 %16, i32 1)
%35 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %3, i64 0, i64 0
%36 = call i32 @epoll_wait(i32 %28, %struct.epoll_event* %35, i32 1024, i32 -1)
%37 = icmp slt i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %33, %38
%39 = phi i32 [ %41, %38 ], [ %36, %33 ]
%40 = call i32 @lt(%struct.epoll_event* %35, i32 %39, i32 %28, i32 %16)
%41 = call i32 @epoll_wait(i32 %28, %struct.epoll_event* %35, i32 1024, i32 -1)
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %38
43: ; preds = %38, %33
%44 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%45 = call i32 @close(i32 %16)
%46 = load i32, i32* @EXIT_SUCCESS
ret i32 %46
}