#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 */
typedef int uint;
struct timeval {
  double tv_sec;
  double tv_usec;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ servaddr;
typedef int /*<<< orphan*/ cliaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
void *atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  uint total_bytes_recv = 0;
  double elapsedTime;
  struct timeval t_start, t_end;
  int fd = 0;
  int port;
  int recvsize = 4096;
  int sockfd, listenfd;
  char recvbuf[65536];
  struct sockaddr_in servaddr, cliaddr;
  socklen_t clilen;
  int ret;
  unsigned char listenOnce = 0;
  signal(SIGPIPE, SIG_IGN);
  if (argc < 2) {
    printf("Usage: %s <port> <[optional] listenOnce ([0]/1)> <[optional] "
           "filepath>\n",
           argv[0]);
    exit(0);
  }
  port = atoi(argv[1]);
  if (argc > 2)
    listenOnce = atoi(argv[2]);
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(port);
  bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(listenfd, 1);
  for (;;) {
    clilen = sizeof(cliaddr);
    sockfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
    printf("Accepted client at %s\n", inet_ntoa(cliaddr.sin_addr));
    total_bytes_recv = 0;
    if (argc > 3) {
      fd = open(argv[3], O_WRONLY | O_CREAT | O_TRUNC);
      if (fd == -1) {
        fprintf(stderr, "! Unable to open file %s.\n", argv[2]);
        close(sockfd);
        if (listenOnce)
          break;
        continue;
      }
    }
    gettimeofday(&t_start, NULL);
    for (;;) {
      ret = recv(sockfd, recvbuf, recvsize, 0);
      if (ret <= 0) {
        if (errno == 0) {
          if (argc > 3)
            close(fd);
          break;
        }
        fprintf(stderr, "! Fail to recv: ret:%d, err:%d; quiting..\n", ret,
                errno);
        exit(1);
      }
      if (argc > 3)
        write(fd, recvbuf, ret);
      total_bytes_recv += ret;
    }
    gettimeofday(&t_end, NULL);
    elapsedTime = (t_end.tv_sec - t_start.tv_sec) +
                  (t_end.tv_usec - t_start.tv_usec) / 1000000.0;
    printf("recv(bytes):%d\nduration(s):%lf\nthroughput(bps):%lf\n",
           total_bytes_recv, elapsedTime, total_bytes_recv * 8 / elapsedTime);
    close(sockfd);
    if (listenOnce)
      break;
  }
  close(listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10090,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x1000,-0x4c(%rbp)
movb   $0x0,-0x10089(%rbp)
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1292 <main+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd84(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    12bf <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %al,-0x10089(%rbp)
mov    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    0x2ce1(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x54(%rbp)
lea    -0x10070(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2ce5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10068(%rbp)
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,-0x10070(%rbp)
mov    -0x48(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x1006c(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x10070(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
movl   $0xc,-0x10084(%rbp)
mov    -0x54(%rbp),%edi
lea    -0x10080(%rbp),%rsi
lea    -0x10084(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x50(%rbp)
mov    -0x10080(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    1406 <main+0x1e6>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
mov    0x2c52(%rip),%rax
or     (%rax),%esi
mov    0x2c41(%rip),%rax
or     (%rax),%esi
call   10f0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1401 <main+0x1e1>
mov    0x2bee(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xc8c(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
cmpb   $0x0,-0x10089(%rbp)
je     13fc <main+0x1dc>
jmp    153d <main+0x31d>
jmp    133e <main+0x11e>
jmp    1406 <main+0x1e6>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x50(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    -0x4c(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10088(%rbp)
cmpl   $0x0,-0x10088(%rbp)
jg     1493 <main+0x273>
mov    0x2b5f(%rip),%rax
cmpq   $0x0,(%rax)
jne    1462 <main+0x242>
cmpl   $0x3,-0x8(%rbp)
jle    145d <main+0x23d>
mov    -0x44(%rbp),%edi
call   10a0 <close@plt>
jmp    14c3 <main+0x2a3>
mov    0x2b4f(%rip),%rax
mov    (%rax),%edi
mov    -0x10088(%rbp),%edx
mov    0x2b28(%rip),%rax
mov    (%rax),%rcx
lea    0xc00(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    14b2 <main+0x292>
mov    -0x44(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    -0x10088(%rbp),%edx
call   1040 <write@plt>
mov    -0x10088(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1413 <main+0x1f3>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xb14(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%esi
movsd  -0x20(%rbp),%xmm0
mov    -0x14(%rbp),%eax
shl    $0x3,%eax
cvtsi2sd %eax,%xmm1
divsd  -0x20(%rbp),%xmm1
lea    0xb96(%rip),%rdi
mov    $0x2,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%edi
call   10a0 <close@plt>
cmpb   $0x0,-0x10089(%rbp)
je     1538 <main+0x318>
jmp    153d <main+0x31d>
jmp    133e <main+0x11e>
mov    -0x54(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x10090,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10068,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
mov    0x2d82(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmp    $0x1,%ebp
jle    14de <main+0x2be>
mov    0x8(%rbx),%rdi
call   1120 <atoi@plt>
mov    %rax,%r14
movb   $0x1,0xf(%rsp)
cmp    $0x2,%ebp
je     127c <main+0x5c>
mov    0x10(%rbx),%rdi
call   1120 <atoi@plt>
test   %al,%al
sete   0xf(%rsp)
mov    %rbx,0x18(%rsp)
mov    0x2d50(%rip),%r12
mov    (%r12),%edi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%ebx
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x28(%rsp)
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x20(%rsp)
mov    %r14d,%edi
call   1060 <htons@plt>
mov    %eax,0x24(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    %ebx,0x10(%rsp)
mov    %ebx,%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
lea    0x60(%rsp),%r15
xor    %r13d,%r13d
jmp    1363 <main+0x143>
nop
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
movapd 0x40(%rsp),%xmm1
subpd  0x50(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xcd8(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%r14,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xd67(%rip),%rdi
mov    %r14d,%esi
mov    $0x2,%al
call   1070 <printf@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
cmpb   $0x0,0xf(%rsp)
je     149e <main+0x27e>
movl   $0xc,0x14(%rsp)
mov    0x10(%rsp),%edi
lea    0x30(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1110 <accept@plt>
mov    %eax,%r12d
mov    0x30(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xcbf(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    $0x4,%ebp
jb     13d5 <main+0x1b5>
mov    0x18(%rsp),%rax
mov    0x18(%rax),%rdi
mov    0x2c48(%rip),%rax
mov    (%rax),%esi
mov    0x2bd7(%rip),%rax
or     (%rax),%esi
mov    0x2c2e(%rip),%rax
or     (%rax),%esi
call   10f0 <open@plt>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1465 <main+0x245>
xor    %r14d,%r14d
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1440 <main+0x220>
xor    %r14d,%r14d
jmp    142b <main+0x20b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %ebx,%r14d
mov    %r12d,%edi
mov    %r15,%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1440 <main+0x220>
cmp    $0x4,%ebp
jb     1410 <main+0x1f0>
mov    %r13d,%edi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
jmp    1410 <main+0x1f0>
nop
mov    0x2b59(%rip),%rax
mov    (%rax),%rcx
test   %rcx,%rcx
jne    14bb <main+0x29b>
cmp    $0x4,%ebp
jb     1300 <main+0xe0>
mov    %r13d,%edi
call   10a0 <close@plt>
jmp    1300 <main+0xe0>
mov    0x2b4c(%rip),%rax
mov    (%rax),%edi
mov    0x18(%rsp),%rax
mov    0x10(%rax),%rdx
lea    0xbe9(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    %r12d,%edi
call   10a0 <close@plt>
mov    $0xffffffff,%r13d
cmpb   $0x0,0xf(%rsp)
jne    1363 <main+0x143>
mov    0x10(%rsp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x10068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2af6(%rip),%rax
mov    (%rax),%edi
lea    0xbb7(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    (%rbx),%rsi
lea    0xb20(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [72 x i8] c"Usage: %s <port> <[optional] listenOnce ([0]/1)> <[optional] filepath>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Accepted client at %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@stderr = global i32 0
@.str.2 = [27 x i8] c"! Unable to open file %s.\0A\00"
@errno = global i64 0
@.str.3 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@.str.4 = [52 x i8] c"recv(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [65536 x i8]
%16 = alloca %struct.sockaddr_in
%17 = alloca %struct.sockaddr_in
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %10
store i32 4096, i32* %12
store i8 0, i8* %20
%21 = load i32, i32* @SIGPIPE
%22 = load i32, i32* @SIG_IGN
%23 = call i32 @signal(i32 %21, i32 %22)
%24 = load i32, i32* %4
%25 = icmp slt i32 %24, 2
br i1 %25, label %26, label %32
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 0
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i8* @atoi(i8* %35)
%37 = ptrtoint i8* %36 to i32
store i32 %37, i32* %11
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 2
br i1 %39, label %40, label %46
40: ; preds = %32
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%43 = load i8*, i8** %42
%44 = call i8* @atoi(i8* %43)
%45 = ptrtoint i8* %44 to i8
store i8 %45, i8* %20
br label %46
46: ; preds = %40, %32
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_STREAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %14
%50 = call i32 @bzero(%struct.sockaddr_in* %16, i32 12)
%51 = load i32, i32* @AF_INET
%52 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 2
store i32 %51, i32* %52
%53 = load i32, i32* @INADDR_ANY
%54 = call i32 @htonl(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%56 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %55, i32 0, i32 0
store i32 %54, i32* %56
%57 = load i32, i32* %11
%58 = call i32 @htons(i32 %57)
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 1
store i32 %58, i32* %59
%60 = load i32, i32* %14
%61 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%62 = call i32 @bind(i32 %60, %struct.sockaddr* %61, i32 12)
%63 = load i32, i32* %14
%64 = call i32 @listen(i32 %63, i32 1)
br label %65
65: ; preds = %165, %99, %46
store i32 12, i32* %18
%66 = load i32, i32* %14
%67 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%68 = call i32 @accept(i32 %66, %struct.sockaddr* %67, i32* %18)
store i32 %68, i32* %13
%69 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%70 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %69, i32 0, i32 0
%71 = load i32, i32* %70
%72 = call i8* @inet_ntoa(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %72)
store i32 0, i32* %6
%74 = load i32, i32* %4
%75 = icmp sgt i32 %74, 3
br i1 %75, label %76, label %101
76: ; preds = %65
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 3
%79 = load i8*, i8** %78
%80 = load i32, i32* @O_WRONLY
%81 = load i32, i32* @O_CREAT
%82 = or i32 %80, %81
%83 = load i32, i32* @O_TRUNC
%84 = or i32 %82, %83
%85 = call i32 @open(i8* %79, i32 %84)
store i32 %85, i32* %10
%86 = load i32, i32* %10
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %100
88: ; preds = %76
%89 = load i32, i32* @stderr
%90 = load i8**, i8*** %5
%91 = getelementptr inbounds i8*, i8** %90, i64 2
%92 = load i8*, i8** %91
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %92)
%94 = load i32, i32* %13
%95 = call i32 @close(i32 %94)
%96 = load i8, i8* %20
%97 = icmp ne i8 %96, 0
br i1 %97, label %98, label %99
98: ; preds = %88
br label %166
99: ; preds = %88
br label %65
100: ; preds = %76
br label %101
101: ; preds = %100, %65
%102 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
br label %103
103: ; preds = %134, %101
%104 = load i32, i32* %13
%105 = getelementptr inbounds [65536 x i8], [65536 x i8]* %15, i64 0, i64 0
%106 = load i32, i32* %12
%107 = call i32 @recv(i32 %104, i8* %105, i32 %106, i32 0)
store i32 %107, i32* %19
%108 = load i32, i32* %19
%109 = icmp sle i32 %108, 0
br i1 %109, label %110, label %126
110: ; preds = %103
%111 = load i64, i64* @errno
%112 = icmp eq i64 %111, 0
br i1 %112, label %113, label %120
113: ; preds = %110
%114 = load i32, i32* %4
%115 = icmp sgt i32 %114, 3
br i1 %115, label %116, label %119
116: ; preds = %113
%117 = load i32, i32* %10
%118 = call i32 @close(i32 %117)
br label %119
119: ; preds = %116, %113
br label %138
120: ; preds = %110
%121 = load i32, i32* @stderr
%122 = load i32, i32* %19
%123 = load i64, i64* @errno
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %122, i64 %123)
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %103
%127 = load i32, i32* %4
%128 = icmp sgt i32 %127, 3
br i1 %128, label %129, label %134
129: ; preds = %126
%130 = load i32, i32* %10
%131 = getelementptr inbounds [65536 x i8], [65536 x i8]* %15, i64 0, i64 0
%132 = load i32, i32* %19
%133 = call i32 @write(i32 %130, i8* %131, i32 %132)
br label %134
134: ; preds = %129, %126
%135 = load i32, i32* %19
%136 = load i32, i32* %6
%137 = add nsw i32 %136, %135
store i32 %137, i32* %6
br label %103
138: ; preds = %119
%139 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%140 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%141 = load double, double* %140
%142 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%143 = load double, double* %142
%144 = fsub double %141, %143
%145 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%146 = load double, double* %145
%147 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%148 = load double, double* %147
%149 = fsub double %146, %148
%150 = fdiv double %149, 1.000000e+06
%151 = fadd double %144, %150
store double %151, double* %7
%152 = load i32, i32* %6
%153 = load double, double* %7
%154 = load i32, i32* %6
%155 = mul nsw i32 %154, 8
%156 = sitofp i32 %155 to double
%157 = load double, double* %7
%158 = fdiv double %156, %157
%159 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %152, double %153, double %158)
%160 = load i32, i32* %13
%161 = call i32 @close(i32 %160)
%162 = load i8, i8* %20
%163 = icmp ne i8 %162, 0
br i1 %163, label %164, label %165
164: ; preds = %138
br label %166
165: ; preds = %138
br label %65
166: ; preds = %164, %98
%167 = load i32, i32* %14
%168 = call i32 @close(i32 %167)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [72 x i8] c"Usage: %s <port> <[optional] listenOnce ([0]/1)> <[optional] filepath>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Accepted client at %s\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@stderr = global i32 0
@.str.2 = [27 x i8] c"! Unable to open file %s.\0A\00"
@errno = global i64 0
@.str.3 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@.str.4 = [52 x i8] c"recv(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timeval*
%5 = alloca <2 x double>
%6 = bitcast <2 x double>* %5 to %struct.timeval*
%7 = alloca [65536 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = bitcast <2 x double>* %3 to i8*
%12 = bitcast <2 x double>* %5 to i8*
%13 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 0
%14 = bitcast %struct.sockaddr_in* %8 to i8*
%15 = bitcast %struct.sockaddr_in* %9 to i8*
%16 = bitcast i32* %10 to i8*
%17 = load i32, i32* @SIGPIPE
%18 = load i32, i32* @SIG_IGN
%19 = tail call i32 @signal(i32 %17, i32 %18)
%20 = icmp slt i32 %0, 2
br i1 %20, label %21, label %25
21: ; preds = %2
%22 = load i8*, i8** %1
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = tail call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i8* @atoi(i8* %27)
%29 = ptrtoint i8* %28 to i64
%30 = trunc i64 %29 to i32
%31 = icmp eq i32 %0, 2
br i1 %31, label %39, label %32
32: ; preds = %25
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = tail call i8* @atoi(i8* %34)
%36 = ptrtoint i8* %35 to i64
%37 = trunc i64 %36 to i8
%38 = icmp eq i8 %37, 0
br label %39
39: ; preds = %32, %25
%40 = phi i1 [ %38, %32 ], [ true, %25 ]
%41 = load i32, i32* @AF_INET
%42 = load i32, i32* @SOCK_STREAM
%43 = tail call i32 @socket(i32 %41, i32 %42, i32 0)
%44 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%45 = load i32, i32* @AF_INET
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i32 %45, i32* %46
%47 = load i32, i32* @INADDR_ANY
%48 = tail call i32 @htonl(i32 %47)
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0, i32 0
store i32 %48, i32* %49
%50 = tail call i32 @htons(i32 %30)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
store i32 %50, i32* %51
%52 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%53 = call i32 @bind(i32 %43, %struct.sockaddr* %52, i32 12)
%54 = call i32 @listen(i32 %43, i32 1)
%55 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%56 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0, i32 0
%57 = icmp ugt i32 %0, 3
%58 = getelementptr inbounds i8*, i8** %1, i64 3
%59 = getelementptr inbounds i8*, i8** %1, i64 2
br label %60
60: ; preds = %80, %39
%61 = phi i32 [ 0, %39 ], [ %81, %80 ]
store i32 12, i32* %10
%62 = call i32 @accept(i32 %43, %struct.sockaddr* %55, i32* %10)
%63 = load i32, i32* %56
%64 = call i8* @inet_ntoa(i32 %63)
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %64)
br i1 %57, label %66, label %82
66: ; preds = %60
%67 = load i8*, i8** %58
%68 = load i32, i32* @O_WRONLY
%69 = load i32, i32* @O_CREAT
%70 = or i32 %69, %68
%71 = load i32, i32* @O_TRUNC
%72 = or i32 %70, %71
%73 = call i32 @open(i8* %67, i32 %72)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %82
75: ; preds = %66
%76 = load i32, i32* @stderr
%77 = load i8*, i8** %59
%78 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %77)
%79 = call i32 @close(i32 %62)
br i1 %40, label %80, label %122
80: ; preds = %75, %108
%81 = phi i32 [ -1, %75 ], [ %83, %108 ]
br label %60
82: ; preds = %66, %60
%83 = phi i32 [ %73, %66 ], [ %61, %60 ]
%84 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%85 = call i32 @recv(i32 %62, i8* %13, i32 4096, i32 0)
%86 = icmp slt i32 %85, 1
br i1 %86, label %87, label %99
87: ; preds = %104, %82
%88 = phi i32 [ 0, %82 ], [ %105, %104 ]
%89 = phi i32 [ %85, %82 ], [ %106, %104 ]
%90 = load i64, i64* @errno
%91 = icmp eq i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %87
br i1 %57, label %93, label %108
93: ; preds = %92
%94 = call i32 @close(i32 %83)
br label %108
95: ; preds = %87
%96 = load i32, i32* @stderr
%97 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %89, i64 %90)
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %82, %104
%100 = phi i32 [ %106, %104 ], [ %85, %82 ]
%101 = phi i32 [ %105, %104 ], [ 0, %82 ]
br i1 %57, label %102, label %104
102: ; preds = %99
%103 = call i32 @write(i32 %83, i8* %13, i32 %100)
br label %104
104: ; preds = %102, %99
%105 = add nsw i32 %100, %101
%106 = call i32 @recv(i32 %62, i8* %13, i32 4096, i32 0)
%107 = icmp slt i32 %106, 1
br i1 %107, label %87, label %99
108: ; preds = %92, %93
%109 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%110 = load <2 x double>, <2 x double>* %5
%111 = load <2 x double>, <2 x double>* %3
%112 = fsub <2 x double> %110, %111
%113 = extractelement <2 x double> %112, i64 1
%114 = fdiv double %113, 1.000000e+06
%115 = extractelement <2 x double> %112, i64 0
%116 = fadd double %115, %114
%117 = shl nsw i32 %88, 3
%118 = sitofp i32 %117 to double
%119 = fdiv double %118, %116
%120 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %88, double %116, double %119)
%121 = call i32 @close(i32 %62)
br i1 %40, label %80, label %122
122: ; preds = %108, %75
%123 = call i32 @close(i32 %43)
ret i32 0
}