#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 sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct epoll_event {
  int dummy;
};
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ addfd(int, int, int);
int /*<<< orphan*/ assert(int);
int atoi(char *);
char *basename(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ et(struct epoll_event *, int, int, int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char const *,
                             int /*<<< orphan*/ *);
int listen(int, int);
int /*<<< orphan*/ lt(struct epoll_event *, int, int, int);
int /*<<< orphan*/ printf(char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc <= 2) {
    printf("usage: %s ip_address port_numbder\n", basename(argv[0]));
    return 1;
  }
  const char *ip = argv[1];
  int port = atoi(argv[2]);
  int ret = 0;
  int isEt = 0;
  if (argc == 4) {
    isEt = atoi(argv[3]);
  }
  struct sockaddr_in address;
  bzero(&address, sizeof(address));
  address.sin_family = AF_INET;
  inet_pton(AF_INET, ip, &address.sin_addr);
  address.sin_port = htons(port);
  int listenfd = socket(PF_INET, SOCK_STREAM, 0);
  assert(listenfd >= 0);
  ret = bind(listenfd, (struct sockaddr *)&address, sizeof(address));
  assert(ret != -1);
  ret = listen(listenfd, 5);
  assert(ret != -1);
  struct epoll_event events[1024];
  int epollfd = epoll_create(5);
  assert(epollfd != -1);
  addfd(epollfd, listenfd, 1);
  while (1) {
    int ret = epoll_wait(epollfd, events, 1024, -1);
    if (ret < 0) {
      printf("epoll failure\n");
      break;
    }
    if (isEt) {
      et(events, ret, epollfd, listenfd);
    } else {
      lt(events, ret, epollfd, listenfd);
    }
  }
  close(listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     124c <main+0x4c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1080 <basename@plt>
mov    %rax,%rsi
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1414 <main+0x214>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    1290 <main+0x90>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,-0x24(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2d43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x4,%rdx
call   10a0 <inet_pton@plt>
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    0x2cf9(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x34(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    $0x5,%edi
call   1110 <epoll_create@plt>
mov    %eax,-0x1044(%rbp)
cmpl   $0xffffffff,-0x1044(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x1044(%rbp),%edi
mov    -0x34(%rbp),%esi
mov    $0x1,%edx
call   1030 <addfd@plt>
mov    -0x1044(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10c0 <epoll_wait@plt>
mov    %eax,-0x1048(%rbp)
cmpl   $0x0,-0x1048(%rbp)
jge    13bb <main+0x1bb>
lea    0xc74(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1405 <main+0x205>
cmpl   $0x0,-0x24(%rbp)
je     13e5 <main+0x1e5>
lea    -0x1040(%rbp),%rdi
mov    -0x1048(%rbp),%esi
mov    -0x1044(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1090 <et@plt>
jmp    1400 <main+0x200>
lea    -0x1040(%rbp),%rdi
mov    -0x1048(%rbp),%esi
mov    -0x1044(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1100 <lt@plt>
jmp    1379 <main+0x179>
mov    -0x34(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jg     124e <main+0x3e>
mov    0x0(%rbp),%rdi
call   1090 <basename@plt>
lea    0xdc7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r14d
jmp    13a7 <main+0x197>
mov    %edi,%ebx
mov    0x8(%rbp),%r14
mov    0x10(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r12d
xor    %r15d,%r15d
cmp    $0x4,%ebx
jne    1274 <main+0x64>
mov    0x18(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%r15d
mov    %rsp,%r13
mov    %r13,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d5d(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
mov    %r14,%rsi
call   10b0 <inet_pton@plt>
mov    %r12d,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    0x2d1f(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r12d
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1080 <assert@plt>
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    $0x5,%edi
call   1120 <epoll_create@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    %ebx,%edi
mov    %r12d,%esi
mov    $0x1,%edx
call   1030 <addfd@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
test   %eax,%eax
js     1393 <main+0x183>
lea    0x10(%rsp),%rbp
jmp    137d <main+0x16d>
nopw   0x0(%rax,%rax,1)
call   1110 <lt@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
test   %eax,%eax
js     1393 <main+0x183>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
test   %r15d,%r15d
je     1360 <main+0x150>
call   10a0 <et@plt>
jmp    1365 <main+0x155>
lea    0xc89(%rip),%rdi
call   1040 <puts@plt>
mov    %r12d,%edi
call   1070 <close@plt>
mov    %r14d,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.epoll_event = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"usage: %s ip_address port_numbder\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [15 x i8] c"epoll failure\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca [1024 x %struct.epoll_event]
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = load i32, i32* %4
%16 = icmp sle i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i8* @basename(i8* %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %21)
store i32 1, i32* %3
br label %104
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
store i8* %26, i8** %6
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
%31 = load i32, i32* %4
%32 = icmp eq i32 %31, 4
br i1 %32, label %33, label %38
33: ; preds = %23
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %9
br label %38
38: ; preds = %33, %23
%39 = call i32 @bzero(%struct.sockaddr_in* %10, i32 12)
%40 = load i32, i32* @AF_INET
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %40, i32* %41
%42 = load i32, i32* @AF_INET
%43 = load i8*, i8** %6
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%45 = call i32 @inet_pton(i32 %42, i8* %43, i32* %44)
%46 = load i32, i32* %7
%47 = call i32 @htons(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %47, i32* %48
%49 = load i32, i32* @PF_INET
%50 = load i32, i32* @SOCK_STREAM
%51 = call i32 @socket(i32 %49, i32 %50, i32 0)
store i32 %51, i32* %11
%52 = load i32, i32* %11
%53 = icmp sge i32 %52, 0
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i32, i32* %11
%57 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%58 = call i32 @bind(i32 %56, %struct.sockaddr* %57, i32 12)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp ne i32 %59, -1
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i32, i32* %11
%64 = call i32 @listen(i32 %63, i32 5)
store i32 %64, i32* %8
%65 = load i32, i32* %8
%66 = icmp ne i32 %65, -1
%67 = zext i1 %66 to i32
%68 = call i32 @assert(i32 %67)
%69 = call i32 @epoll_create(i32 5)
store i32 %69, i32* %13
%70 = load i32, i32* %13
%71 = icmp ne i32 %70, -1
%72 = zext i1 %71 to i32
%73 = call i32 @assert(i32 %72)
%74 = load i32, i32* %13
%75 = load i32, i32* %11
%76 = call i32 @addfd(i32 %74, i32 %75, i32 1)
br label %77
77: ; preds = %38, %100
%78 = load i32, i32* %13
%79 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %12, i64 0, i64 0
%80 = call i32 @epoll_wait(i32 %78, %struct.epoll_event* %79, i32 1024, i32 -1)
store i32 %80, i32* %14
%81 = load i32, i32* %14
%82 = icmp slt i32 %81, 0
br i1 %82, label %83, label %85
83: ; preds = %77
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %101
85: ; preds = %77
%86 = load i32, i32* %9
%87 = icmp ne i32 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %85
%89 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %12, i64 0, i64 0
%90 = load i32, i32* %14
%91 = load i32, i32* %13
%92 = load i32, i32* %11
%93 = call i32 @et(%struct.epoll_event* %89, i32 %90, i32 %91, i32 %92)
br label %100
94: ; preds = %85
%95 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %12, i64 0, i64 0
%96 = load i32, i32* %14
%97 = load i32, i32* %13
%98 = load i32, i32* %11
%99 = call i32 @lt(%struct.epoll_event* %95, i32 %96, i32 %97, i32 %98)
br label %100
100: ; preds = %94, %88
br label %77
101: ; preds = %83
%102 = load i32, i32* %11
%103 = call i32 @close(i32 %102)
store i32 0, i32* %3
br label %104
104: ; preds = %101, %17
%105 = load i32, i32* %3
ret i32 %105
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.epoll_event = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [35 x i8] c"usage: %s ip_address port_numbder\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@str = [14 x i8] c"epoll failure\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [1024 x %struct.epoll_event]
%5 = icmp slt i32 %0, 3
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i8* @basename(i8* %7)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %69
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = getelementptr inbounds i8*, i8** %1, i64 2
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = icmp eq i32 %0, 4
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
br label %21
21: ; preds = %17, %10
%22 = phi i32 [ %20, %17 ], [ 0, %10 ]
%23 = bitcast %struct.sockaddr_in* %3 to i8*
%24 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%28 = call i32 @inet_pton(i32 %25, i8* %12, i32* %27)
%29 = call i32 @htons(i32 %15)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %29, i32* %30
%31 = load i32, i32* @PF_INET
%32 = load i32, i32* @SOCK_STREAM
%33 = call i32 @socket(i32 %31, i32 %32, i32 0)
%34 = xor i32 %33, -1
%35 = lshr i32 %34, 31
%36 = call i32 @assert(i32 %35)
%37 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%38 = call i32 @bind(i32 %33, %struct.sockaddr* %37, i32 12)
%39 = icmp ne i32 %38, -1
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = call i32 @listen(i32 %33, i32 5)
%43 = icmp ne i32 %42, -1
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = bitcast [1024 x %struct.epoll_event]* %4 to i8*
%47 = call i32 @epoll_create(i32 5)
%48 = icmp ne i32 %47, -1
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = call i32 @addfd(i32 %47, i32 %33, i32 1)
%52 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %4, i64 0, i64 0
%53 = call i32 @epoll_wait(i32 %47, %struct.epoll_event* %52, i32 1024, i32 -1)
%54 = icmp slt i32 %53, 0
br i1 %54, label %66, label %55
55: ; preds = %21
%56 = icmp eq i32 %22, 0
br label %57
57: ; preds = %55, %63
%58 = phi i32 [ %53, %55 ], [ %64, %63 ]
br i1 %56, label %61, label %59
59: ; preds = %57
%60 = call i32 @et(%struct.epoll_event* %52, i32 %58, i32 %47, i32 %33)
br label %63
61: ; preds = %57
%62 = call i32 @lt(%struct.epoll_event* %52, i32 %58, i32 %47, i32 %33)
br label %63
63: ; preds = %59, %61
%64 = call i32 @epoll_wait(i32 %47, %struct.epoll_event* %52, i32 1024, i32 -1)
%65 = icmp slt i32 %64, 0
br i1 %65, label %66, label %57
66: ; preds = %63, %21
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%68 = call i32 @close(i32 %33)
br label %69
69: ; preds = %66, %6
%70 = phi i32 [ 1, %6 ], [ 0, %66 ]
ret i32 %70
}