#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 sockaddr_in {
  TYPE_1__ data;
  void *events;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct epoll_event {
  TYPE_1__ data;
  void *events;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ sai;
typedef int /*<<< orphan*/ ev;
typedef int /*<<< orphan*/ enable;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EINTR;
void *EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
scalar_t__ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct sockaddr_in *);
int epoll_wait(int, struct sockaddr_in *, int, int);
scalar_t__ errno;
int /*<<< orphan*/ htons(unsigned short);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  signal(SIGPIPE, SIG_IGN);
  if (argc < 2) {
    printf("Usage:\n");
    printf("echod [PORT]\n");
    printf("\n");
    printf("Listens on the given TCP port and echos back anything sent "
           "to it.\n");
    return 0;
  }
  unsigned short port = (unsigned short)atoi(argv[1]);
  int s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1) {
    perror("socket");
    return -1;
  }
  int enable = 1;
  setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(enable));
  struct sockaddr_in sai;
  memset(&sai, 0, sizeof(sai));
  sai.sin_family = AF_INET;
  sai.sin_port = htons(port);
  if (bind(s, (struct sockaddr *)&sai, sizeof(sai)) == -1) {
    perror("bind");
    return -1;
  }
  if (listen(s, 1000) == -1) {
    perror("listen");
    return -1;
  }
  printf("Listening on port %d.\n", (int)port);
  struct epoll_event ev;
  struct epoll_event evs[100];
  memset(&ev, 0, sizeof(ev));
  ev.events = EPOLLIN;
  ev.data.fd = s;
  int ep = epoll_create(1000);
  epoll_ctl(ep, EPOLL_CTL_ADD, s, &ev);
  while (1) {
    int result = epoll_wait(ep, evs, 100, -1);
    if (result == -1 && errno == EINTR)
      continue;
    for (int i1 = 0; i1 < result; ++i1) {
      int fd = evs[i1].data.fd;
      if (fd == s) {
        int new_fd = accept(s, NULL, NULL);
        ev.events = EPOLLIN;
        ev.data.fd = new_fd;
        epoll_ctl(ep, EPOLL_CTL_ADD, new_fd, &ev);
      } else {
        char buf[10000];
        ssize_t recv_b = recv(fd, buf, 10000, 0);
        if (recv_b <= 0) {
          close(fd);
        } else {
          send(fd, buf, recv_b, 0);
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30f0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    0x2d8f(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmpl   $0x2,-0x8(%rbp)
jge    128e <main+0x7e>
lea    0xdaf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xda9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xe14(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1552 <main+0x342>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <atoi@plt>
mov    %ax,-0x12(%rbp)
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12dd <main+0xcd>
lea    0xd8d(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1552 <main+0x342>
movl   $0x1,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2cfa(%rip),%rax
mov    (%rax),%esi
mov    0x2ca1(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
lea    -0x38(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2cc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
movzwl -0x12(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x18,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1362 <main+0x152>
lea    0xd0f(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1552 <main+0x342>
mov    -0x18(%rbp),%edi
mov    $0x3e8,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1390 <main+0x180>
lea    0xce6(%rip),%rdi
call   10f0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1552 <main+0x342>
movzwl -0x12(%rbp),%esi
lea    0xcd1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1080 <memset@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    $0x3e8,%edi
call   1120 <epoll_create@plt>
mov    %eax,-0x9b4(%rbp)
mov    -0x9b4(%rbp),%edi
mov    0x2bed(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
mov    -0x9b4(%rbp),%edi
lea    -0x9b0(%rbp),%rsi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
mov    %eax,-0x9b8(%rbp)
cmpl   $0xffffffff,-0x9b8(%rbp)
jne    143f <main+0x22f>
mov    0x2b81(%rip),%rax
mov    (%rax),%rax
mov    0x2b6f(%rip),%rcx
cmp    (%rcx),%rax
jne    143f <main+0x22f>
jmp    13f1 <main+0x1e1>
movl   $0x0,-0x9bc(%rbp)
mov    -0x9bc(%rbp),%eax
cmp    -0x9b8(%rbp),%eax
jge    154d <main+0x33d>
movslq -0x9bc(%rbp),%rcx
lea    -0x9b0(%rbp),%rax
imul   $0x18,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0x9c0(%rbp)
mov    -0x9c0(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    14d6 <main+0x2c6>
mov    -0x18(%rbp),%edi
xor    %eax,%eax
mov    %eax,%edx
mov    %rdx,%rsi
call   1100 <accept@plt>
mov    %eax,-0x9c4(%rbp)
mov    0x2b35(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x9c4(%rbp),%eax
mov    %eax,-0x50(%rbp)
mov    -0x9b4(%rbp),%edi
mov    0x2b10(%rip),%rax
mov    (%rax),%esi
mov    -0x9c4(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1534 <main+0x324>
mov    -0x9c0(%rbp),%edi
lea    -0x30e0(%rbp),%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x30e8(%rbp)
cmpq   $0x0,-0x30e8(%rbp)
jg     1514 <main+0x304>
mov    -0x9c0(%rbp),%edi
call   1090 <close@plt>
jmp    152f <main+0x31f>
mov    -0x9c0(%rbp),%edi
lea    -0x30e0(%rbp),%rsi
mov    -0x30e8(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    1534 <main+0x324>
jmp    1539 <main+0x329>
mov    -0x9bc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x9bc(%rbp)
jmp    1449 <main+0x239>
jmp    13f1 <main+0x1e1>
mov    -0x4(%rbp),%eax
add    $0x30f0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30b8,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
mov    0x2d72(%rip),%rax
mov    (%rax),%esi
call   10d0 <signal@plt>
cmp    $0x1,%ebp
jg     12a4 <main+0x74>
lea    0xdc1(%rip),%rdi
call   1050 <puts@plt>
lea    0xdbc(%rip),%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xdb3(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x30b8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x8(%rbx),%rdi
call   1130 <atoi@plt>
mov    %rax,%r14
mov    0x2d29(%rip),%r15
mov    (%r15),%edi
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
cmp    $0xffffffff,%eax
je     1466 <main+0x236>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2d04(%rip),%rax
mov    (%rax),%esi
mov    0x2cbb(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1060 <setsockopt@plt>
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x3c(%rsp)
movzwl %r14w,%edi
call   1070 <htons@plt>
mov    %eax,0x38(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x18,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
je     146f <main+0x23f>
mov    %ebx,%edi
mov    $0x3e8,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     1478 <main+0x248>
movzwl %r14w,%esi
lea    0xcb2(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   10a0 <memset@plt>
mov    0x2c55(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x18(%rsp)
mov    %ebx,0x10(%rsp)
mov    $0x3e8,%edi
call   1140 <epoll_create@plt>
mov    %eax,%r13d
mov    0x2c2d(%rip),%rax
mov    (%rax),%esi
mov    %r13d,%edi
mov    %ebx,%edx
mov    %rbp,%rcx
call   10c0 <epoll_ctl@plt>
lea    0x9a0(%rsp),%r12
nopw   0x0(%rax,%rax,1)
mov    %r13d,%edi
lea    0x40(%rsp),%rsi
mov    $0x64,%edx
mov    $0xffffffff,%ecx
call   10f0 <epoll_wait@plt>
test   %eax,%eax
jle    13c0 <main+0x190>
mov    %eax,%eax
shl    $0x3,%rax
lea    (%rax,%rax,2),%r15
xor    %r14d,%r14d
jmp    142f <main+0x1ff>
nopw   0x0(%rax,%rax,1)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1120 <accept@plt>
mov    0x2bd6(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x18(%rsp)
mov    %eax,0x10(%rsp)
mov    0x2bbb(%rip),%rcx
mov    (%rcx),%esi
mov    %r13d,%edi
mov    %eax,%edx
lea    0x10(%rsp),%rcx
call   10c0 <epoll_ctl@plt>
add    $0x18,%r14
cmp    %r14,%r15
je     13c0 <main+0x190>
mov    0x40(%rsp,%r14,1),%ebp
cmp    %ebx,%ebp
je     13f0 <main+0x1c0>
mov    %ebp,%edi
mov    %r12,%rsi
mov    $0x2710,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %ebp,%edi
test   %rax,%rax
jle    145f <main+0x22f>
mov    %r12,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1080 <send@plt>
jmp    1426 <main+0x1f6>
call   10b0 <close@plt>
jmp    1426 <main+0x1f6>
lea    0xb93(%rip),%rdi
jmp    147f <main+0x24f>
lea    0xb91(%rip),%rdi
jmp    147f <main+0x24f>
lea    0xb8d(%rip),%rdi
call   1110 <perror@plt>
mov    $0xffffffff,%eax
jmp    1292 <main+0x62>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i8*, i32, i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [8 x i8] c"Usage:\0A\00"
@.str.1 = [14 x i8] c"echod [PORT]\0A\00"
@.str.2 = [2 x i8] c"\0A\00"
@.str.3 = [67 x i8] c"Listens on the given TCP port and echos back anything sent to it.\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [5 x i8] c"bind\00"
@.str.6 = [7 x i8] c"listen\00"
@.str.7 = [23 x i8] c"Listening on port %d.\0A\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@errno = global i64 0
@EINTR = global i64 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.epoll_event
%11 = alloca [100 x %struct.epoll_event]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [10000 x i8]
%18 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = load i32, i32* @SIGPIPE
%20 = load i32, i32* @SIG_IGN
%21 = call i32 @signal(i32 %19, i32 %20)
%22 = load i32, i32* %4
%23 = icmp slt i32 %22, 2
br i1 %23, label %24, label %29
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %142
29: ; preds = %2
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i64 @atoi(i8* %32)
%34 = trunc i64 %33 to i16
store i16 %34, i16* %6
%35 = load i32, i32* @AF_INET
%36 = load i32, i32* @SOCK_STREAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %42
40: ; preds = %29
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %142
42: ; preds = %29
store i32 1, i32* %8
%43 = load i32, i32* %7
%44 = load i32, i32* @SOL_SOCKET
%45 = load i32, i32* @SO_REUSEADDR
%46 = call i32 @setsockopt(i32 %43, i32 %44, i32 %45, i32* %8, i32 4)
%47 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 24)
%48 = load i32, i32* @AF_INET
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 3
store i32 %48, i32* %49
%50 = load i16, i16* %6
%51 = call i32 @htons(i16 zeroext %50)
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %51, i32* %52
%53 = load i32, i32* %7
%54 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%55 = call i32 @bind(i32 %53, %struct.sockaddr* %54, i32 24)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %59
57: ; preds = %42
%58 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %142
59: ; preds = %42
%60 = load i32, i32* %7
%61 = call i32 @listen(i32 %60, i32 1000)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %59
%64 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
store i32 -1, i32* %3
br label %142
65: ; preds = %59
%66 = load i16, i16* %6
%67 = zext i16 %66 to i32
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %67)
%69 = bitcast %struct.epoll_event* %10 to %struct.sockaddr_in*
%70 = call i32 @memset(%struct.sockaddr_in* %69, i32 0, i32 24)
%71 = load i8*, i8** @EPOLLIN
%72 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
store i8* %71, i8** %72
%73 = load i32, i32* %7
%74 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
%75 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %74, i32 0, i32 0
store i32 %73, i32* %75
%76 = call i32 @epoll_create(i32 1000)
store i32 %76, i32* %12
%77 = load i32, i32* %12
%78 = load i32, i32* @EPOLL_CTL_ADD
%79 = load i32, i32* %7
%80 = bitcast %struct.epoll_event* %10 to %struct.sockaddr_in*
%81 = call i32 @epoll_ctl(i32 %77, i32 %78, i32 %79, %struct.sockaddr_in* %80)
br label %82
82: ; preds = %65, %93, %141
%83 = load i32, i32* %12
%84 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %11, i64 0, i64 0
%85 = bitcast %struct.epoll_event* %84 to %struct.sockaddr_in*
%86 = call i32 @epoll_wait(i32 %83, %struct.sockaddr_in* %85, i32 100, i32 -1)
store i32 %86, i32* %13
%87 = load i32, i32* %13
%88 = icmp eq i32 %87, -1
br i1 %88, label %89, label %94
89: ; preds = %82
%90 = load i64, i64* @errno
%91 = load i64, i64* @EINTR
%92 = icmp eq i64 %90, %91
br i1 %92, label %93, label %94
93: ; preds = %89
br label %82
94: ; preds = %89, %82
store i32 0, i32* %14
br label %95
95: ; preds = %138, %94
%96 = load i32, i32* %14
%97 = load i32, i32* %13
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %141
99: ; preds = %95
%100 = load i32, i32* %14
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %11, i64 0, i64 %101
%103 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %102, i32 0, i32 0
%104 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %103, i32 0, i32 0
%105 = load i32, i32* %104
store i32 %105, i32* %15
%106 = load i32, i32* %15
%107 = load i32, i32* %7
%108 = icmp eq i32 %106, %107
br i1 %108, label %109, label %122
109: ; preds = %99
%110 = load i32, i32* %7
%111 = call i32 @accept(i32 %110, i32* null, i32* null)
store i32 %111, i32* %16
%112 = load i8*, i8** @EPOLLIN
%113 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
store i8* %112, i8** %113
%114 = load i32, i32* %16
%115 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 0
%116 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %115, i32 0, i32 0
store i32 %114, i32* %116
%117 = load i32, i32* %12
%118 = load i32, i32* @EPOLL_CTL_ADD
%119 = load i32, i32* %16
%120 = bitcast %struct.epoll_event* %10 to %struct.sockaddr_in*
%121 = call i32 @epoll_ctl(i32 %117, i32 %118, i32 %119, %struct.sockaddr_in* %120)
br label %137
122: ; preds = %99
%123 = load i32, i32* %15
%124 = getelementptr inbounds [10000 x i8], [10000 x i8]* %17, i64 0, i64 0
%125 = call i64 @recv(i32 %123, i8* %124, i32 10000, i32 0)
store i64 %125, i64* %18
%126 = load i64, i64* %18
%127 = icmp sle i64 %126, 0
br i1 %127, label %128, label %131
128: ; preds = %122
%129 = load i32, i32* %15
%130 = call i32 @close(i32 %129)
br label %136
131: ; preds = %122
%132 = load i32, i32* %15
%133 = getelementptr inbounds [10000 x i8], [10000 x i8]* %17, i64 0, i64 0
%134 = load i64, i64* %18
%135 = call i32 @send(i32 %132, i8* %133, i64 %134, i32 0)
br label %136
136: ; preds = %131, %128
br label %137
137: ; preds = %136, %109
br label %138
138: ; preds = %137
%139 = load i32, i32* %14
%140 = add nsw i32 %139, 1
store i32 %140, i32* %14
br label %95
141: ; preds = %95
br label %82
142: ; preds = %63, %57, %40, %24
%143 = load i32, i32* %3
ret i32 %143
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i8*, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i8*, i32, i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [7 x i8] c"socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.5 = [5 x i8] c"bind\00"
@.str.6 = [7 x i8] c"listen\00"
@.str.7 = [23 x i8] c"Listening on port %d.\0A\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@str = [7 x i8] c"Usage:\00"
@str.8 = [13 x i8] c"echod [PORT]\00"
@str.9 = [66 x i8] c"Listens on the given TCP port and echos back anything sent to it.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.epoll_event
%6 = alloca [100 x %struct.epoll_event]
%7 = alloca [10000 x i8]
%8 = load i32, i32* @SIGPIPE
%9 = load i32, i32* @SIG_IGN
%10 = tail call i32 @signal(i32 %8, i32 %9)
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
%15 = tail call i32 @putchar(i32 10)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.9, i64 0, i64 0))
br label %91
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i64 @atoi(i8* %19)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = tail call i32 @socket(i32 %21, i32 %22, i32 0)
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %17
%26 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
br label %91
27: ; preds = %17
%28 = trunc i64 %20 to i16
%29 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%30 = load i32, i32* @SOL_SOCKET
%31 = load i32, i32* @SO_REUSEADDR
%32 = call i32 @setsockopt(i32 %23, i32 %30, i32 %31, i32* %3, i32 4)
%33 = bitcast %struct.sockaddr_in* %4 to i8*
%34 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 24)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %35, i32* %36
%37 = call i32 @htons(i16 zeroext %28)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%40 = call i32 @bind(i32 %23, %struct.sockaddr* %39, i32 24)
%41 = icmp eq i32 %40, -1
br i1 %41, label %88, label %42
42: ; preds = %27
%43 = call i32 @listen(i32 %23, i32 1000)
%44 = icmp eq i32 %43, -1
br i1 %44, label %88, label %45
45: ; preds = %42
%46 = trunc i64 %20 to i32
%47 = and i32 %46, 65535
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %47)
%49 = bitcast %struct.epoll_event* %5 to i8*
%50 = bitcast [100 x %struct.epoll_event]* %6 to i8*
%51 = bitcast %struct.epoll_event* %5 to %struct.sockaddr_in*
%52 = call i32 @memset(%struct.sockaddr_in* %51, i32 0, i32 24)
%53 = load i8*, i8** @EPOLLIN
%54 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1
store i8* %53, i8** %54
%55 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0, i32 0
store i32 %23, i32* %55
%56 = call i32 @epoll_create(i32 1000)
%57 = load i32, i32* @EPOLL_CTL_ADD
%58 = call i32 @epoll_ctl(i32 %56, i32 %57, i32 %23, %struct.sockaddr_in* %51)
%59 = bitcast [100 x %struct.epoll_event]* %6 to %struct.sockaddr_in*
%60 = getelementptr inbounds [10000 x i8], [10000 x i8]* %7, i64 0, i64 0
br label %61
61: ; preds = %64, %45
%62 = call i32 @epoll_wait(i32 %56, %struct.sockaddr_in* %59, i32 100, i32 -1)
%63 = icmp sgt i32 %62, 0
br i1 %63, label %65, label %64
64: ; preds = %85, %61
br label %61
65: ; preds = %61
%66 = zext i32 %62 to i64
br label %67
67: ; preds = %65, %85
%68 = phi i64 [ 0, %65 ], [ %86, %85 ]
%69 = getelementptr inbounds [100 x %struct.epoll_event], [100 x %struct.epoll_event]* %6, i64 0, i64 %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = icmp eq i32 %70, %23
br i1 %71, label %72, label %77
72: ; preds = %67
%73 = call i32 @accept(i32 %23, i32* null, i32* null)
%74 = load i8*, i8** @EPOLLIN
store i8* %74, i8** %54
store i32 %73, i32* %55
%75 = load i32, i32* @EPOLL_CTL_ADD
%76 = call i32 @epoll_ctl(i32 %56, i32 %75, i32 %73, %struct.sockaddr_in* %51)
br label %85
77: ; preds = %67
%78 = call i64 @recv(i32 %70, i8* %60, i32 10000, i32 0)
%79 = icmp slt i64 %78, 1
br i1 %79, label %80, label %82
80: ; preds = %77
%81 = call i32 @close(i32 %70)
br label %84
82: ; preds = %77
%83 = call i32 @send(i32 %70, i8* %60, i64 %78, i32 0)
br label %84
84: ; preds = %82, %80
br label %85
85: ; preds = %84, %72
%86 = add nuw nsw i64 %68, 1
%87 = icmp eq i64 %86, %66
br i1 %87, label %64, label %67
88: ; preds = %42, %27
%89 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), %27 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %42 ]
%90 = call i32 @perror(i8* %89)
br label %91
91: ; preds = %25, %88, %12
%92 = phi i32 [ 0, %12 ], [ -1, %88 ], [ -1, %25 ]
ret i32 %92
}