#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;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ on;
typedef int /*<<< orphan*/ clientaddr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
int inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ listen(int, int);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc != 3) {
    fprintf(stderr, "usage: %s <IP> <port>\n", argv[0]);
    return 1;
  }
  struct sockaddr_in servaddr;
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(atoi(argv[2]));
  if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) != 1) {
    fprintf(stderr, "invalid IP address\n");
    return 1;
  }
  int servfd = socket(AF_INET, SOCK_STREAM, 0);
  if (servfd < 0) {
    perror("cannot create socket");
    return 1;
  }
  int on = 1;
  setsockopt(servfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
  if (bind(servfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) != 0) {
    perror("cannot bind");
    return 1;
  }
  if (listen(servfd, 10) != 0) {
    perror("cannot listen");
    return 1;
  }
  printf("accepting...\n");
  while (1) {
    struct sockaddr_in clientaddr;
    socklen_t clientaddrlen = sizeof(clientaddr);
    int sockfd = accept(servfd, (struct sockaddr *)&clientaddr, &clientaddrlen);
    if (sockfd < 0) {
      continue;
    }
    char buf[1024];
    inet_ntop(AF_INET, &clientaddr.sin_addr, buf, sizeof(buf));
    printf("accepted connection from %s:%d\n", buf, ntohs(clientaddr.sin_port));
    int result = 0;
    int packets = 0;
    while (1) {
      ++packets;
      int ret = read(sockfd, buf, sizeof(buf), 0);
      if (ret <= 0) {
        break;
      }
      int i;
      for (i = 0; i < ret; ++i) {
        result += buf[i];
      }
    }
    close(sockfd);
    printf("closed connection %d %d\n", result, packets);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     124d <main+0x4d>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <main+0x2e1>
lea    -0x20(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x20(%rbp)
mov    0x2d5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x20(%rbp),%rdx
add    $0x4,%rdx
call   10a0 <inet_pton@plt>
cmp    $0x1,%eax
je     12c8 <main+0xc8>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd62(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <main+0x2e1>
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
mov    0x2cf0(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1306 <main+0x106>
lea    0xd36(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <main+0x2e1>
movl   $0x1,-0x28(%rbp)
mov    -0x24(%rbp),%edi
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
mov    0x2ca0(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
je     1364 <main+0x164>
lea    0xced(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <main+0x2e1>
mov    -0x24(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
je     1393 <main+0x193>
lea    0xcca(%rip),%rdi
call   10e0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14e1 <main+0x2e1>
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    13ca <main+0x1ca>
jmp    13a1 <main+0x1a1>
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
lea    -0x38(%rbp),%rsi
add    $0x4,%rsi
lea    -0x440(%rbp),%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
lea    -0x440(%rbp),%rax
mov    %rax,-0x458(%rbp)
mov    -0x38(%rbp),%edi
call   10c0 <ntohs@plt>
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
lea    0xc56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x444(%rbp)
movl   $0x0,-0x448(%rbp)
mov    -0x448(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x448(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1080 <read@plt>
mov    %eax,-0x44c(%rbp)
cmpl   $0x0,-0x44c(%rbp)
jg     146a <main+0x26a>
jmp    14ba <main+0x2ba>
movl   $0x0,-0x450(%rbp)
mov    -0x450(%rbp),%eax
cmp    -0x44c(%rbp),%eax
jge    14b5 <main+0x2b5>
movslq -0x450(%rbp),%rax
movsbl -0x440(%rbp,%rax,1),%eax
ff
add    -0x444(%rbp),%eax
mov    %eax,-0x444(%rbp)
mov    -0x450(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x450(%rbp)
jmp    1474 <main+0x274>
jmp    142d <main+0x22d>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
mov    -0x444(%rbp),%esi
mov    -0x448(%rbp),%edx
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    13a1 <main+0x1a1>
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%rbx
cmp    $0x3,%edi
jne    1503 <main+0x2f3>
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2d9d(%rip),%rbp
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x10(%rbx),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x0(%rbp),%edi
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdx
call   10b0 <inet_pton@plt>
cmp    $0x1,%eax
jne    151f <main+0x30f>
mov    0x0(%rbp),%edi
mov    0x2d46(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
test   %eax,%eax
js     154d <main+0x33d>
mov    %eax,%r12d
movl   $0x1,0xc(%rsp)
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
mov    0x2d12(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r12d,%edi
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
lea    0x10(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jne    155b <main+0x34b>
mov    %r12d,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
test   %rax,%rax
jne    1569 <main+0x359>
lea    0xd98(%rip),%rdi
call   1040 <puts@plt>
lea    0x30(%rsp),%rbx
jmp    1339 <main+0x129>
nopw   0x0(%rax,%rax,1)
mov    $0x1,%r14d
mov    %r13d,%edi
call   1080 <close@plt>
lea    0xd55(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2ca7(%rip),%rbp
movl   $0xc,0x8(%rsp)
mov    %r12d,%edi
lea    0x20(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   1110 <accept@plt>
test   %eax,%eax
js     1339 <main+0x129>
mov    %eax,%r13d
mov    0x0(%rbp),%edi
lea    0x24(%rsp),%rsi
mov    %rbx,%rdx
mov    $0x400,%ecx
call   1030 <inet_ntop@plt>
mov    0x20(%rsp),%edi
call   10d0 <ntohs@plt>
xor    %r15d,%r15d
lea    0xcd8(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <read@plt>
test   %eax,%eax
jle    1310 <main+0x100>
xor    %r15d,%r15d
mov    $0x1,%r14d
jmp    13de <main+0x1ce>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    $0x1,%r14d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1090 <read@plt>
test   %eax,%eax
jle    1316 <main+0x106>
mov    %eax,%ecx
cmp    $0x8,%eax
jae    13f0 <main+0x1e0>
xor    %eax,%eax
jmp    14e0 <main+0x2d0>
nopl   0x0(%rax)
mov    %ecx,%eax
and    $0xfffffff8,%eax
movd   %r15d,%xmm0
lea    -0x8(%rax),%rsi
mov    %rsi,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rsi,%rsi
je     14f6 <main+0x2e6>
mov    %rdx,%rdi
and    $0xfffffffffffffffe,%rdi
pxor   %xmm1,%xmm1
xor    %esi,%esi
nop
movd   0x34(%rsp,%rsi,1),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
punpcklbw 0x30(%rsp,%rsi,1),%xmm3
punpcklwd %xmm3,%xmm3
psrad  $0x18,%xmm3
paddd  %xmm0,%xmm3
psrad  $0x18,%xmm2
paddd  %xmm1,%xmm2
movq   0x38(%rsp,%rsi,1),%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
movd   0x3c(%rsp,%rsi,1),%xmm1
punpcklbw %xmm1,%xmm1
punpcklwd %xmm1,%xmm1
psrad  $0x18,%xmm0
paddd  %xmm3,%xmm0
psrad  $0x18,%xmm1
paddd  %xmm2,%xmm1
add    $0x10,%rsi
add    $0xfffffffffffffffe,%rdi
jne    1420 <main+0x210>
test   $0x1,%dl
je     14b5 <main+0x2a5>
movq   0x30(%rsp,%rsi,1),%xmm2
punpcklbw %xmm2,%xmm2
punpcklwd %xmm2,%xmm2
movd   0x34(%rsp,%rsi,1),%xmm3
punpcklbw %xmm3,%xmm3
punpcklwd %xmm3,%xmm3
psrad  $0x18,%xmm2
paddd  %xmm2,%xmm0
psrad  $0x18,%xmm3
paddd  %xmm3,%xmm1
paddd  %xmm1,%xmm0
pshufd $0xee,%xmm0,%xmm1
paddd  %xmm0,%xmm1
pshufd $0x55,%xmm1,%xmm0
paddd  %xmm1,%xmm0
movd   %xmm0,%r15d
cmp    %rcx,%rax
je     13c0 <main+0x1b0>
nopl   0x0(%rax)
movsbl 0x30(%rsp,%rax,1),%edx
add    %edx,%r15d
add    $0x1,%rax
cmp    %rax,%rcx
jne    14e0 <main+0x2d0>
jmp    13c0 <main+0x1b0>
pxor   %xmm1,%xmm1
xor    %esi,%esi
test   $0x1,%dl
jne    1487 <main+0x277>
jmp    14b5 <main+0x2a5>
mov    0x2ac6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xaea(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1536 <main+0x326>
mov    0x2aaa(%rip),%rax
mov    (%rax),%edi
lea    0xae8(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xad7(%rip),%rdi
call   10f0 <perror@plt>
jmp    1536 <main+0x326>
lea    0xade(%rip),%rdi
call   10f0 <perror@plt>
jmp    1536 <main+0x326>
lea    0xadc(%rip),%rdi
call   10f0 <perror@plt>
jmp    1536 <main+0x326>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"usage: %s <IP> <port>\0A\00"
@AF_INET = global i32 0
@.str.1 = [20 x i8] c"invalid IP address\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"cannot create socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [12 x i8] c"cannot bind\00"
@.str.4 = [14 x i8] c"cannot listen\00"
@.str.5 = [14 x i8] c"accepting...\0A\00"
@.str.6 = [32 x i8] c"accepted connection from %s:%d\0A\00"
@.str.7 = [25 x i8] c"closed connection %d %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 3
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %121
25: ; preds = %2
%26 = call i32 @bzero(%struct.sockaddr_in* %6, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %27, i32* %28
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
%33 = call i32 @htons(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %33, i32* %34
%35 = load i32, i32* @AF_INET
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%40 = call i32 @inet_pton(i32 %35, i8* %38, i32* %39)
%41 = icmp ne i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %25
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %121
45: ; preds = %25
%46 = load i32, i32* @AF_INET
%47 = load i32, i32* @SOCK_STREAM
%48 = call i32 @socket(i32 %46, i32 %47, i32 0)
store i32 %48, i32* %7
%49 = load i32, i32* %7
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %45
%52 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %121
53: ; preds = %45
store i32 1, i32* %8
%54 = load i32, i32* %7
%55 = load i32, i32* @SOL_SOCKET
%56 = load i32, i32* @SO_REUSEADDR
%57 = call i32 @setsockopt(i32 %54, i32 %55, i32 %56, i32* %8, i32 4)
%58 = load i32, i32* %7
%59 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%60 = call i64 @bind(i32 %58, %struct.sockaddr* %59, i32 12)
%61 = icmp ne i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %53
%63 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %121
64: ; preds = %53
%65 = load i32, i32* %7
%66 = call i64 @listen(i32 %65, i32 10)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %70
68: ; preds = %64
%69 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %121
70: ; preds = %64
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %72
72: ; preds = %70, %78, %115
store i32 12, i32* %10
%73 = load i32, i32* %7
%74 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%75 = call i32 @accept(i32 %73, %struct.sockaddr* %74, i32* %10)
store i32 %75, i32* %11
%76 = load i32, i32* %11
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %72
br label %72
79: ; preds = %72
%80 = load i32, i32* @AF_INET
%81 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%82 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%83 = call i32 @inet_ntop(i32 %80, i32* %81, i8* %82, i32 1024)
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%86 = load i32, i32* %85
%87 = call i32 @ntohs(i32 %86)
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i8* %84, i32 %87)
store i32 0, i32* %13
store i32 0, i32* %14
br label %89
89: ; preds = %79, %114
%90 = load i32, i32* %14
%91 = add nsw i32 %90, 1
store i32 %91, i32* %14
%92 = load i32, i32* %11
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%94 = call i32 @read(i32 %92, i8* %93, i32 1024, i32 0)
store i32 %94, i32* %15
%95 = load i32, i32* %15
%96 = icmp sle i32 %95, 0
br i1 %96, label %97, label %98
97: ; preds = %89
br label %115
98: ; preds = %89
store i32 0, i32* %16
br label %99
99: ; preds = %111, %98
%100 = load i32, i32* %16
%101 = load i32, i32* %15
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %114
103: ; preds = %99
%104 = load i32, i32* %16
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 %105
%107 = load i8, i8* %106
%108 = sext i8 %107 to i32
%109 = load i32, i32* %13
%110 = add nsw i32 %109, %108
store i32 %110, i32* %13
br label %111
111: ; preds = %103
%112 = load i32, i32* %16
%113 = add nsw i32 %112, 1
store i32 %113, i32* %16
br label %99
114: ; preds = %99
br label %89
115: ; preds = %97
%116 = load i32, i32* %11
%117 = call i32 @close(i32 %116)
%118 = load i32, i32* %13
%119 = load i32, i32* %14
%120 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %118, i32 %119)
br label %72
121: ; preds = %68, %62, %51, %42, %19
%122 = load i32, i32* %3
ret i32 %122
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"usage: %s <IP> <port>\0A\00"
@AF_INET = global i32 0
@.str.1 = [20 x i8] c"invalid IP address\0A\00"
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"cannot create socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [12 x i8] c"cannot bind\00"
@.str.4 = [14 x i8] c"cannot listen\00"
@.str.6 = [32 x i8] c"accepted connection from %s:%d\0A\00"
@.str.7 = [25 x i8] c"closed connection %d %d\0A\00"
@str = [13 x i8] c"accepting...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = icmp eq i32 %0, 3
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %165
13: ; preds = %2
%14 = bitcast %struct.sockaddr_in* %3 to i8*
%15 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %16, i32* %17
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%27 = call i32 @inet_pton(i32 %23, i8* %25, i32* %26)
%28 = icmp eq i32 %27, 1
br i1 %28, label %32, label %29
29: ; preds = %13
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %164
32: ; preds = %13
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %32
%38 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %164
39: ; preds = %32
%40 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%41 = load i32, i32* @SOL_SOCKET
%42 = load i32, i32* @SO_REUSEADDR
%43 = call i32 @setsockopt(i32 %35, i32 %41, i32 %42, i32* %4, i32 4)
%44 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%45 = call i64 @bind(i32 %35, %struct.sockaddr* %44, i32 12)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %161
47: ; preds = %39
%48 = call i64 @listen(i32 %35, i32 10)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %161
50: ; preds = %47
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
%52 = bitcast %struct.sockaddr_in* %5 to i8*
%53 = bitcast i32* %6 to i8*
%54 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
br label %58
58: ; preds = %160, %50
store i32 12, i32* %6
%59 = call i32 @accept(i32 %35, %struct.sockaddr* %54, i32* %6)
%60 = icmp slt i32 %59, 0
br i1 %60, label %160, label %61
61: ; preds = %58
%62 = load i32, i32* @AF_INET
%63 = call i32 @inet_ntop(i32 %62, i32* %56, i8* %55, i32 1024)
%64 = load i32, i32* %57
%65 = call i32 @ntohs(i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0), i8* %55, i32 %65)
%67 = call i32 @read(i32 %59, i8* %55, i32 1024, i32 0)
%68 = icmp slt i32 %67, 1
br i1 %68, label %155, label %74
69: ; preds = %146, %137
%70 = phi i32 [ %141, %137 ], [ %152, %146 ]
%71 = add nuw nsw i32 %76, 1
%72 = call i32 @read(i32 %59, i8* %55, i32 1024, i32 0)
%73 = icmp slt i32 %72, 1
br i1 %73, label %155, label %74
74: ; preds = %61, %69
%75 = phi i32 [ %72, %69 ], [ %67, %61 ]
%76 = phi i32 [ %71, %69 ], [ 1, %61 ]
%77 = phi i32 [ %70, %69 ], [ 0, %61 ]
%78 = zext i32 %75 to i64
%79 = icmp ult i32 %75, 8
br i1 %79, label %143, label %80
80: ; preds = %74
%81 = and i64 %78, 4294967288
%82 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %77, i64 0
%83 = add nsw i64 %81, -8
%84 = lshr exact i64 %83, 3
%85 = add nuw nsw i64 %84, 1
%86 = and i64 %85, 1
%87 = icmp eq i64 %83, 0
br i1 %87, label %119, label %88
88: ; preds = %80
%89 = and i64 %85, 4611686018427387902
br label %90
90: ; preds = %90, %88
%91 = phi i64 [ 0, %88 ], [ %116, %90 ]
%92 = phi <4 x i32> [ %82, %88 ], [ %114, %90 ]
%93 = phi <4 x i32> [ zeroinitializer, %88 ], [ %115, %90 ]
%94 = phi i64 [ 0, %88 ], [ %117, %90 ]
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %91
%96 = bitcast i8* %95 to <4 x i8>*
%97 = load <4 x i8>, <4 x i8>* %96
%98 = getelementptr inbounds i8, i8* %95, i64 4
%99 = bitcast i8* %98 to <4 x i8>*
%100 = load <4 x i8>, <4 x i8>* %99
%101 = sext <4 x i8> %97 to <4 x i32>
%102 = sext <4 x i8> %100 to <4 x i32>
%103 = add <4 x i32> %92, %101
%104 = add <4 x i32> %93, %102
%105 = or i64 %91, 8
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %105
%107 = bitcast i8* %106 to <4 x i8>*
%108 = load <4 x i8>, <4 x i8>* %107
%109 = getelementptr inbounds i8, i8* %106, i64 4
%110 = bitcast i8* %109 to <4 x i8>*
%111 = load <4 x i8>, <4 x i8>* %110
%112 = sext <4 x i8> %108 to <4 x i32>
%113 = sext <4 x i8> %111 to <4 x i32>
%114 = add <4 x i32> %103, %112
%115 = add <4 x i32> %104, %113
%116 = add nuw i64 %91, 16
%117 = add i64 %94, 2
%118 = icmp eq i64 %117, %89
br i1 %118, label %119, label %90
119: ; preds = %90, %80
%120 = phi <4 x i32> [ undef, %80 ], [ %114, %90 ]
%121 = phi <4 x i32> [ undef, %80 ], [ %115, %90 ]
%122 = phi i64 [ 0, %80 ], [ %116, %90 ]
%123 = phi <4 x i32> [ %82, %80 ], [ %114, %90 ]
%124 = phi <4 x i32> [ zeroinitializer, %80 ], [ %115, %90 ]
%125 = icmp eq i64 %86, 0
br i1 %125, label %137, label %126
126: ; preds = %119
%127 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %122
%128 = bitcast i8* %127 to <4 x i8>*
%129 = load <4 x i8>, <4 x i8>* %128
%130 = getelementptr inbounds i8, i8* %127, i64 4
%131 = bitcast i8* %130 to <4 x i8>*
%132 = load <4 x i8>, <4 x i8>* %131
%133 = sext <4 x i8> %129 to <4 x i32>
%134 = sext <4 x i8> %132 to <4 x i32>
%135 = add <4 x i32> %123, %133
%136 = add <4 x i32> %124, %134
br label %137
137: ; preds = %119, %126
%138 = phi <4 x i32> [ %120, %119 ], [ %135, %126 ]
%139 = phi <4 x i32> [ %121, %119 ], [ %136, %126 ]
%140 = add <4 x i32> %139, %138
%141 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %140)
%142 = icmp eq i64 %81, %78
br i1 %142, label %69, label %143
143: ; preds = %74, %137
%144 = phi i64 [ 0, %74 ], [ %81, %137 ]
%145 = phi i32 [ %77, %74 ], [ %141, %137 ]
br label %146
146: ; preds = %143, %146
%147 = phi i64 [ %153, %146 ], [ %144, %143 ]
%148 = phi i32 [ %152, %146 ], [ %145, %143 ]
%149 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %147
%150 = load i8, i8* %149
%151 = sext i8 %150 to i32
%152 = add nsw i32 %148, %151
%153 = add nuw nsw i64 %147, 1
%154 = icmp eq i64 %153, %78
br i1 %154, label %69, label %146
155: ; preds = %69, %61
%156 = phi i32 [ 0, %61 ], [ %70, %69 ]
%157 = phi i32 [ 1, %61 ], [ %71, %69 ]
%158 = call i32 @close(i32 %59)
%159 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i32 %156, i32 %157)
br label %160
160: ; preds = %58, %155
br label %58
161: ; preds = %47, %39
%162 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), %39 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %47 ]
%163 = call i32 @perror(i8* %162)
br label %164
164: ; preds = %37, %161, %29
br label %165
165: ; preds = %164, %9
ret i32 1
}