#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 EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ SOMAXCONN;
struct epoll_event *calloc(int, int);
int /*<<< orphan*/ close(int);
int create_and_bind(char *);
int epoll_create1(int /*<<< orphan*/);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ free(struct epoll_event *);
int listen(int, int /*<<< orphan*/);
int make_socket_non_blocking(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(int argc, char *argv[]) {
  int sfd, s, n;
  int efd;
  struct epoll_event event;
  struct epoll_event *events;
  if (argc != 2) {
    perror("please specify port");
    return 1;
  }
  sfd = create_and_bind(argv[1]);
  if (sfd == -1)
    return 1;
  s = make_socket_non_blocking(sfd);
  if (s == -1)
    return 1;
  s = listen(sfd, SOMAXCONN);
  if (s == -1) {
    perror("listen");
    return 1;
  }
  efd = epoll_create1(0);
  if (efd == -1) {
    perror("epoll_create");
    return 1;
  }
  event.data.fd = sfd;
  event.events = EPOLLIN | EPOLLET;
  s = epoll_ctl(efd, EPOLL_CTL_ADD, sfd, &event);
  if (s == -1) {
    perror("epoll_ctl");
    return 1;
  }
  events = calloc(64, sizeof event);
  n = epoll_wait(efd, events, 64, 1000);
  if (n == -1) {
    perror("epoll_wait");
    return 1;
  }
  printf("epoll_wait test passed\n");
  free(events);
  close(sfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e8 <main+0x38>
lea    0xe29(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <create_and_bind@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    120e <main+0x5e>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x14(%rbp),%edi
call   1040 <make_socket_non_blocking@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    122f <main+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x14(%rbp),%edi
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
call   1090 <listen@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1265 <main+0xb5>
lea    0xdc0(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
xor    %edi,%edi
call   10d0 <epoll_create1@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1291 <main+0xe1>
lea    0xd9b(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d4a(%rip),%rax
mov    (%rax),%eax
mov    0x2d21(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1070 <epoll_ctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12e9 <main+0x139>
lea    0xd50(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
mov    $0x40,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    $0x40,%edx
mov    $0x3e8,%ecx
call   10a0 <epoll_wait@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1337 <main+0x187>
lea    0xd0c(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    135b <main+0x1ab>
lea    0xcff(%rip),%rdi
call   1050 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    12a3 <main+0xf3>
mov    0x8(%rsi),%rdi
call   10b0 <create_and_bind@plt>
mov    $0x1,%r14d
cmp    $0xffffffff,%eax
je     1295 <main+0xe5>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <make_socket_non_blocking@plt>
cmp    $0xffffffff,%eax
je     1295 <main+0xe5>
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
je     12b7 <main+0x107>
xor    %edi,%edi
call   10d0 <epoll_create1@plt>
cmp    $0xffffffff,%eax
je     12c5 <main+0x115>
mov    %eax,%ebx
mov    0x2dcc(%rip),%rax
mov    0x2da5(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ebp,0x4(%rsp)
mov    %ecx,(%rsp)
mov    0x2dab(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %ebp,%edx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     12d3 <main+0x123>
mov    $0x40,%edi
mov    $0x8,%esi
call   1080 <calloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
mov    %rax,%rsi
mov    $0x40,%edx
mov    $0x3e8,%ecx
call   10a0 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     12e1 <main+0x131>
lea    0xdbf(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd56(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%r14d
jmp    1295 <main+0xe5>
lea    0xd56(%rip),%rdi
call   10c0 <perror@plt>
jmp    1295 <main+0xe5>
lea    0xd4f(%rip),%rdi
call   10c0 <perror@plt>
jmp    1295 <main+0xe5>
lea    0xd4e(%rip),%rdi
call   10c0 <perror@plt>
jmp    1295 <main+0xe5>
lea    0xd4a(%rip),%rdi
call   10c0 <perror@plt>
jmp    1295 <main+0xe5>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [20 x i8] c"please specify port\00"
@SOMAXCONN = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@.str.2 = [13 x i8] c"epoll_create\00"
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.3 = [10 x i8] c"epoll_ctl\00"
@.str.4 = [11 x i8] c"epoll_wait\00"
@.str.5 = [24 x i8] c"epoll_wait test passed\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 i32
%10 = alloca %struct.epoll_event
%11 = alloca %struct.epoll_event*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %75
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @create_and_bind(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %16
store i32 1, i32* %3
br label %75
24: ; preds = %16
%25 = load i32, i32* %6
%26 = call i32 @make_socket_non_blocking(i32 %25)
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %3
br label %75
30: ; preds = %24
%31 = load i32, i32* %6
%32 = load i32, i32* @SOMAXCONN
%33 = call i32 @listen(i32 %31, i32 %32)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %75
38: ; preds = %30
%39 = call i32 @epoll_create1(i32 0)
store i32 %39, i32* %9
%40 = load i32, i32* %9
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %75
44: ; preds = %38
%45 = load i32, i32* %6
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
store i32 %45, i32* %47
%48 = load i32, i32* @EPOLLIN
%49 = load i32, i32* @EPOLLET
%50 = or i32 %48, %49
%51 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
store i32 %50, i32* %51
%52 = load i32, i32* %9
%53 = load i32, i32* @EPOLL_CTL_ADD
%54 = load i32, i32* %6
%55 = call i32 @epoll_ctl(i32 %52, i32 %53, i32 %54, %struct.epoll_event* %10)
store i32 %55, i32* %7
%56 = load i32, i32* %7
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %60
58: ; preds = %44
%59 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %75
60: ; preds = %44
%61 = call %struct.epoll_event* @calloc(i32 64, i32 8)
store %struct.epoll_event* %61, %struct.epoll_event** %11
%62 = load i32, i32* %9
%63 = load %struct.epoll_event*, %struct.epoll_event** %11
%64 = call i32 @epoll_wait(i32 %62, %struct.epoll_event* %63, i32 64, i32 1000)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %69
67: ; preds = %60
%68 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %75
69: ; preds = %60
%70 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%71 = load %struct.epoll_event*, %struct.epoll_event** %11
%72 = call i32 @free(%struct.epoll_event* %71)
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
store i32 0, i32* %3
br label %75
75: ; preds = %69, %67, %58, %42, %36, %29, %23, %14
%76 = load i32, i32* %3
ret i32 %76
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [20 x i8] c"please specify port\00"
@SOMAXCONN = global i32 0
@.str.1 = [7 x i8] c"listen\00"
@.str.2 = [13 x i8] c"epoll_create\00"
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.3 = [10 x i8] c"epoll_ctl\00"
@.str.4 = [11 x i8] c"epoll_wait\00"
@str = [23 x i8] c"epoll_wait test passed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.epoll_event
%4 = bitcast %struct.epoll_event* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %48
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @create_and_bind(i8* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %48, label %13
13: ; preds = %8
%14 = tail call i32 @make_socket_non_blocking(i32 %11)
%15 = icmp eq i32 %14, -1
br i1 %15, label %48, label %16
16: ; preds = %13
%17 = load i32, i32* @SOMAXCONN
%18 = tail call i32 @listen(i32 %11, i32 %17)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %48
22: ; preds = %16
%23 = tail call i32 @epoll_create1(i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %48
27: ; preds = %22
%28 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1, i32 0
store i32 %11, i32* %28
%29 = load i32, i32* @EPOLLIN
%30 = load i32, i32* @EPOLLET
%31 = or i32 %30, %29
%32 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0
store i32 %31, i32* %32
%33 = load i32, i32* @EPOLL_CTL_ADD
%34 = call i32 @epoll_ctl(i32 %23, i32 %33, i32 %11, %struct.epoll_event* %3)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %27
%37 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %48
38: ; preds = %27
%39 = call %struct.epoll_event* @calloc(i32 64, i32 8)
%40 = call i32 @epoll_wait(i32 %23, %struct.epoll_event* %39, i32 64, i32 1000)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %48
44: ; preds = %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%46 = call i32 @free(%struct.epoll_event* %39)
%47 = call i32 @close(i32 %11)
br label %48
48: ; preds = %13, %8, %44, %42, %36, %25, %20, %6
%49 = phi i32 [ 1, %6 ], [ 1, %20 ], [ 1, %25 ], [ 1, %36 ], [ 1, %42 ], [ 0, %44 ], [ 1, %8 ], [ 1, %13 ]
ret i32 %49
}