#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 *);
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*/ 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_number\n", argv[0]);
    return 1;
  }
  const char *ip = argv[1];
  int port = atoi(argv[2]);
  int ret = 0;
  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;
    }
    et(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     1224 <main+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13a1 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
lea    -0x30(%rbp),%rdx
add    $0x4,%rdx
call   1090 <inet_pton@plt>
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x30(%rbp)
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <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   10c0 <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   10a0 <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   10f0 <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   10b0 <epoll_wait@plt>
mov    %eax,-0x1048(%rbp)
cmpl   $0x0,-0x1048(%rbp)
jge    1372 <main+0x192>
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1392 <main+0x1b2>
lea    -0x1040(%rbp),%rdi
mov    -0x1048(%rbp),%esi
mov    -0x1044(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1080 <et@plt>
jmp    1330 <main+0x150>
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   %r12
push   %rbx
sub    $0x1010,%rsp
cmp    $0x2,%edi
jg     1220 <main+0x30>
mov    (%rsi),%rsi
lea    0xdf2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%r14d
jmp    134b <main+0x15b>
mov    0x8(%rsi),%rbp
mov    0x10(%rsi),%rdi
call   10f0 <atoi@plt>
mov    %eax,%ebx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x8(%rsp)
lea    0x4(%rsp),%rdx
mov    %rbp,%rsi
call   10a0 <inet_pton@plt>
mov    %ebx,%edi
call   1050 <htons@plt>
mov    %eax,(%rsp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
xor    %r14d,%r14d
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,%r15d
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1080 <assert@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    %r15d,%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    $0x5,%edi
call   1100 <epoll_create@plt>
mov    %eax,%ebx
xor    %edi,%edi
cmp    $0xffffffff,%eax
setne  %dil
call   1080 <assert@plt>
mov    %ebx,%edi
mov    %r15d,%esi
mov    $0x1,%edx
call   1030 <addfd@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10c0 <epoll_wait@plt>
test   %eax,%eax
js     1337 <main+0x147>
lea    0x10(%rsp),%rbp
nop
mov    %rbp,%rdi
mov    %eax,%esi
mov    %ebx,%edx
mov    %r15d,%ecx
call   1090 <et@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
mov    $0xffffffff,%ecx
call   10c0 <epoll_wait@plt>
test   %eax,%eax
jns    1310 <main+0x120>
lea    0xce3(%rip),%rdi
call   1040 <puts@plt>
mov    %r15d,%edi
call   1070 <close@plt>
mov    %r14d,%eax
add    $0x1010,%rsp
pop    %rbx
pop    %r12
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 = [33 x i8] c"usage %s ip_address port_number\0A\00"
@AF_INET = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 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 %struct.sockaddr_in
%10 = alloca i32
%11 = alloca [1024 x %struct.epoll_event]
%12 = alloca i32
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp sle i32 %14, 2
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %19)
store i32 1, i32* %3
br label %84
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
store i8* %24, i8** %6
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 2
%27 = load i8*, i8** %26
%28 = call i32 @atoi(i8* %27)
store i32 %28, i32* %7
store i32 0, i32* %8
%29 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @AF_INET
%33 = load i8*, i8** %6
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%35 = call i32 @inet_pton(i32 %32, i8* %33, i32* %34)
%36 = load i32, i32* %7
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* @PF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp sge i32 %42, 0
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i32, i32* %10
%47 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%48 = call i32 @bind(i32 %46, %struct.sockaddr* %47, i32 12)
store i32 %48, i32* %8
%49 = load i32, i32* %8
%50 = icmp ne i32 %49, -1
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
%53 = load i32, i32* %10
%54 = call i32 @listen(i32 %53, i32 5)
store i32 %54, i32* %8
%55 = load i32, i32* %8
%56 = icmp ne i32 %55, -1
%57 = zext i1 %56 to i32
%58 = call i32 @assert(i32 %57)
%59 = call i32 @epoll_create(i32 5)
store i32 %59, i32* %12
%60 = load i32, i32* %12
%61 = icmp ne i32 %60, -1
%62 = zext i1 %61 to i32
%63 = call i32 @assert(i32 %62)
%64 = load i32, i32* %12
%65 = load i32, i32* %10
%66 = call i32 @addfd(i32 %64, i32 %65, i32 1)
br label %67
67: ; preds = %21, %75
%68 = load i32, i32* %12
%69 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %11, i64 0, i64 0
%70 = call i32 @epoll_wait(i32 %68, %struct.epoll_event* %69, i32 1024, i32 -1)
store i32 %70, i32* %13
%71 = load i32, i32* %13
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %75
73: ; preds = %67
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %81
75: ; preds = %67
%76 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* %11, i64 0, i64 0
%77 = load i32, i32* %13
%78 = load i32, i32* %12
%79 = load i32, i32* %10
%80 = call i32 @et(%struct.epoll_event* %76, i32 %77, i32 %78, i32 %79)
br label %67
81: ; preds = %73
%82 = load i32, i32* %10
%83 = call i32 @close(i32 %82)
store i32 0, i32* %3
br label %84
84: ; preds = %81, %16
%85 = load i32, i32* %3
ret i32 %85
}

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