#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_DGRAM;
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 open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
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 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_DGRAM, 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));
  for (;;) {
    printf("Waiting on port %d...\n", port);
    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[3]);
        close(listenfd);
        if (listenOnce)
          break;
        continue;
      }
    }
    gettimeofday(&t_start, NULL);
    for (;;) {
      clilen = sizeof(cliaddr);
      ret = recvfrom(listenfd, recvbuf, recvsize, 0,
                     (struct sockaddr *)&cliaddr, &clilen);
      printf("Accepted client at %s with %d len msg\n",
             inet_ntoa(cliaddr.sin_addr), ret);
      if (ret <= 0) {
        if (errno == 0)
          break;
        fprintf(stderr, "! Fail to recv: ret:%d, err:%d; quiting..\n", ret,
                errno);
        exit(1);
      }
      if ((recvbuf[0] == '=') && (recvbuf[1] == '?') && (recvbuf[2] == '!')) {
        if (argc > 3)
          close(fd);
        break;
      }
      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);
    if (listenOnce)
      break;
  }
  close(listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10080,%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,-0x10079(%rbp)
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d7b(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
cmpl   $0x2,-0x8(%rbp)
jge    1272 <main+0x72>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    129f <main+0x9f>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %al,-0x10079(%rbp)
mov    0x2d32(%rip),%rax
mov    (%rax),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x50(%rbp)
lea    -0x10060(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10058(%rbp)
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x10060(%rbp)
mov    -0x48(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x1005c(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    -0x48(%rbp),%esi
lea    0xd35(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jle    13ab <main+0x1ab>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    0x2c4e(%rip),%rax
mov    (%rax),%esi
mov    0x2cad(%rip),%rax
or     (%rax),%esi
mov    0x2c9c(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    13a6 <main+0x1a6>
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
lea    0xce7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x50(%rbp),%edi
call   1090 <close@plt>
cmpb   $0x0,-0x10079(%rbp)
je     13a1 <main+0x1a1>
jmp    1549 <main+0x349>
jmp    1311 <main+0x111>
jmp    13ab <main+0x1ab>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movl   $0xc,-0x10074(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x10050(%rbp),%rsi
mov    -0x4c(%rbp),%edx
lea    -0x10070(%rbp),%r8
xor    %ecx,%ecx
lea    -0x10074(%rbp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,-0x10078(%rbp)
mov    -0x10070(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x10078(%rbp),%edx
lea    0xc7d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x0,-0x10078(%rbp)
jg     1460 <main+0x260>
mov    0x2b80(%rip),%rax
cmpq   $0x0,(%rax)
jne    142f <main+0x22f>
jmp    14d7 <main+0x2d7>
mov    0x2b7a(%rip),%rax
mov    (%rax),%edi
mov    -0x10078(%rbp),%edx
mov    0x2b5b(%rip),%rax
mov    (%rax),%rcx
lea    0xc5a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movsbl -0x10050(%rbp),%eax
cmp    $0x3d,%eax
jne    14a7 <main+0x2a7>
movsbl -0x1004f(%rbp),%eax
cmp    $0x3f,%eax
jne    14a7 <main+0x2a7>
movsbl -0x1004e(%rbp),%eax
cmp    $0x21,%eax
jne    14a7 <main+0x2a7>
cmpl   $0x3,-0x8(%rbp)
jle    14a2 <main+0x2a2>
mov    -0x44(%rbp),%edi
call   1090 <close@plt>
jmp    14d7 <main+0x2d7>
cmpl   $0x3,-0x8(%rbp)
jle    14c6 <main+0x2c6>
mov    -0x44(%rbp),%edi
lea    -0x10050(%rbp),%rsi
mov    -0x10078(%rbp),%edx
call   1030 <write@plt>
mov    -0x10078(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    13b8 <main+0x1b8>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xb00(%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    0xba9(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
cmpb   $0x0,-0x10079(%rbp)
je     1544 <main+0x344>
jmp    1549 <main+0x349>
jmp    1311 <main+0x111>
mov    -0x50(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x10080,%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    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    0x2d9a(%rip),%rax
mov    (%rax),%esi
call   10a0 <signal@plt>
cmp    $0x1,%ebp
jle    150d <main+0x30d>
mov    0x8(%rbx),%rdi
call   1100 <atoi@plt>
mov    %rax,0x18(%rsp)
movb   $0x1,0xb(%rsp)
cmp    $0x2,%ebp
je     125e <main+0x5e>
mov    0x10(%rbx),%rdi
call   1100 <atoi@plt>
test   %al,%al
sete   0xb(%rsp)
mov    %rbx,0x10(%rsp)
mov    0x2d6e(%rip),%r15
mov    (%r15),%edi
mov    0x2d54(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebx
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x38(%rsp)
mov    0x2d31(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x30(%rsp)
mov    0x18(%rsp),%rdi
call   1050 <htons@plt>
mov    %eax,0x34(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
xor    %r12d,%r12d
jmp    1341 <main+0x141>
nopl   0x0(%rax)
mov    0x2cc9(%rip),%rax
mov    (%rax),%rcx
mov    %r15d,%r13d
test   %rcx,%rcx
jne    14e9 <main+0x2e9>
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movapd 0x40(%rsp),%xmm1
subpd  0x50(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xcf2(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%r13,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xda8(%rip),%rdi
mov    %r13d,%esi
mov    $0x2,%al
call   1060 <printf@plt>
cmpb   $0x0,0xb(%rsp)
je     14ce <main+0x2ce>
lea    0xd08(%rip),%rdi
mov    0x18(%rsp),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0x4,%ebp
jb     138e <main+0x18e>
mov    0x10(%rsp),%rax
mov    0x18(%rax),%rdi
mov    0x2c8f(%rip),%rax
mov    (%rax),%esi
mov    0x2c1e(%rip),%rax
or     (%rax),%esi
mov    0x2c75(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,%r12d
cmp    $0xffffffff,%eax
je     1496 <main+0x296>
xor    %r15d,%r15d
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
lea    0x60(%rsp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,%r14d
mov    0x20(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xcad(%rip),%rdi
mov    %rax,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %r14d,%r14d
jle    12d0 <main+0xd0>
xor    %r13d,%r13d
jmp    1447 <main+0x247>
mov    %r14d,%r15d
add    %r13d,%r15d
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
lea    0x60(%rsp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    0x20(%rsp),%r8
lea    0xc(%rsp),%r9
call   10c0 <recvfrom@plt>
mov    %eax,%r14d
mov    0x20(%rsp),%edi
call   1040 <inet_ntoa@plt>
lea    0xc54(%rip),%rdi
mov    %rax,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15d,%r13d
test   %r14d,%r14d
jle    12d0 <main+0xd0>
cmpb   $0x3d,0x60(%rsp)
jne    145c <main+0x25c>
cmpb   $0x3f,0x61(%rsp)
jne    145c <main+0x25c>
cmpb   $0x21,0x62(%rsp)
je     1480 <main+0x280>
cmp    $0x4,%ebp
jb     13f0 <main+0x1f0>
mov    %r12d,%edi
lea    0x60(%rsp),%rsi
mov    %r14d,%edx
call   1030 <write@plt>
jmp    13f0 <main+0x1f0>
cs nopw 0x0(%rax,%rax,1)
cmp    $0x4,%ebp
jb     12e6 <main+0xe6>
mov    %r12d,%edi
call   1090 <close@plt>
jmp    12e6 <main+0xe6>
mov    0x2b13(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rax
mov    0x18(%rax),%rdx
lea    0xbb8(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    $0xffffffff,%r12d
cmpb   $0x0,0xb(%rsp)
jne    1341 <main+0x141>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x10068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ac0(%rip),%rax
mov    (%rax),%edi
lea    0xbb0(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    (%rbx),%rsi
lea    0xaf1(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1110 <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_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Waiting on port %d...\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"
@.str.3 = [39 x i8] c"Accepted client at %s with %d len msg\0A\00"
@errno = global i64 0
@.str.4 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@.str.5 = [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 [65536 x i8]
%15 = alloca %struct.sockaddr_in
%16 = alloca %struct.sockaddr_in
%17 = alloca i32
%18 = alloca i32
%19 = 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* %19
%20 = load i32, i32* @SIGPIPE
%21 = load i32, i32* @SIG_IGN
%22 = call i32 @signal(i32 %20, i32 %21)
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %31
25: ; preds = %2
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str, i64 0, i64 0), i8* %28)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i8* @atoi(i8* %34)
%36 = ptrtoint i8* %35 to i32
store i32 %36, i32* %11
%37 = load i32, i32* %4
%38 = icmp sgt i32 %37, 2
br i1 %38, label %39, label %45
39: ; preds = %31
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = call i8* @atoi(i8* %42)
%44 = ptrtoint i8* %43 to i8
store i8 %44, i8* %19
br label %45
45: ; preds = %39, %31
%46 = load i32, i32* @AF_INET
%47 = load i32, i32* @SOCK_DGRAM
%48 = call i32 @socket(i32 %46, i32 %47, i32 0)
store i32 %48, i32* %13
%49 = call i32 @bzero(%struct.sockaddr_in* %15, i32 12)
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* @INADDR_ANY
%53 = call i32 @htonl(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 0
%55 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %54, i32 0, i32 0
store i32 %53, i32* %55
%56 = load i32, i32* %11
%57 = call i32 @htons(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %15, i32 0, i32 1
store i32 %57, i32* %58
%59 = load i32, i32* %13
%60 = bitcast %struct.sockaddr_in* %15 to %struct.sockaddr*
%61 = call i32 @bind(i32 %59, %struct.sockaddr* %60, i32 12)
br label %62
62: ; preds = %177, %90, %45
%63 = load i32, i32* %11
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %63)
store i32 0, i32* %6
%65 = load i32, i32* %4
%66 = icmp sgt i32 %65, 3
br i1 %66, label %67, label %92
67: ; preds = %62
%68 = load i8**, i8*** %5
%69 = getelementptr inbounds i8*, i8** %68, i64 3
%70 = load i8*, i8** %69
%71 = load i32, i32* @O_WRONLY
%72 = load i32, i32* @O_CREAT
%73 = or i32 %71, %72
%74 = load i32, i32* @O_TRUNC
%75 = or i32 %73, %74
%76 = call i32 @open(i8* %70, i32 %75)
store i32 %76, i32* %10
%77 = load i32, i32* %10
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %91
79: ; preds = %67
%80 = load i32, i32* @stderr
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 3
%83 = load i8*, i8** %82
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %83)
%85 = load i32, i32* %13
%86 = call i32 @close(i32 %85)
%87 = load i8, i8* %19
%88 = icmp ne i8 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %79
br label %178
90: ; preds = %79
br label %62
91: ; preds = %67
br label %92
92: ; preds = %91, %62
%93 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
br label %94
94: ; preds = %148, %92
store i32 12, i32* %17
%95 = load i32, i32* %13
%96 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%97 = load i32, i32* %12
%98 = bitcast %struct.sockaddr_in* %16 to %struct.sockaddr*
%99 = call i32 @recvfrom(i32 %95, i8* %96, i32 %97, i32 0, %struct.sockaddr* %98, i32* %17)
store i32 %99, i32* %18
%100 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %16, i32 0, i32 0
%101 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %100, i32 0, i32 0
%102 = load i32, i32* %101
%103 = call i8* @inet_ntoa(i32 %102)
%104 = load i32, i32* %18
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %103, i32 %104)
%106 = load i32, i32* %18
%107 = icmp sle i32 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %94
%109 = load i64, i64* @errno
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %112
111: ; preds = %108
br label %152
112: ; preds = %108
%113 = load i32, i32* @stderr
%114 = load i32, i32* %18
%115 = load i64, i64* @errno
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %113, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %114, i64 %115)
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %94
%119 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%120 = load i8, i8* %119
%121 = sext i8 %120 to i32
%122 = icmp eq i32 %121, 61
br i1 %122, label %123, label %140
123: ; preds = %118
%124 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 1
%125 = load i8, i8* %124
%126 = sext i8 %125 to i32
%127 = icmp eq i32 %126, 63
br i1 %127, label %128, label %140
128: ; preds = %123
%129 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 2
%130 = load i8, i8* %129
%131 = sext i8 %130 to i32
%132 = icmp eq i32 %131, 33
br i1 %132, label %133, label %140
133: ; preds = %128
%134 = load i32, i32* %4
%135 = icmp sgt i32 %134, 3
br i1 %135, label %136, label %139
136: ; preds = %133
%137 = load i32, i32* %10
%138 = call i32 @close(i32 %137)
br label %139
139: ; preds = %136, %133
br label %152
140: ; preds = %128, %123, %118
%141 = load i32, i32* %4
%142 = icmp sgt i32 %141, 3
br i1 %142, label %143, label %148
143: ; preds = %140
%144 = load i32, i32* %10
%145 = getelementptr inbounds [65536 x i8], [65536 x i8]* %14, i64 0, i64 0
%146 = load i32, i32* %18
%147 = call i32 @write(i32 %144, i8* %145, i32 %146)
br label %148
148: ; preds = %143, %140
%149 = load i32, i32* %18
%150 = load i32, i32* %6
%151 = add nsw i32 %150, %149
store i32 %151, i32* %6
br label %94
152: ; preds = %139, %111
%153 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%154 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%155 = load double, double* %154
%156 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%157 = load double, double* %156
%158 = fsub double %155, %157
%159 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%160 = load double, double* %159
%161 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%162 = load double, double* %161
%163 = fsub double %160, %162
%164 = fdiv double %163, 1.000000e+06
%165 = fadd double %158, %164
store double %165, double* %7
%166 = load i32, i32* %6
%167 = load double, double* %7
%168 = load i32, i32* %6
%169 = mul nsw i32 %168, 8
%170 = sitofp i32 %169 to double
%171 = load double, double* %7
%172 = fdiv double %170, %171
%173 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %166, double %167, double %172)
%174 = load i8, i8* %19
%175 = icmp ne i8 %174, 0
br i1 %175, label %176, label %177
176: ; preds = %152
br label %178
177: ; preds = %152
br label %62
178: ; preds = %176, %89
%179 = load i32, i32* %13
%180 = call i32 @close(i32 %179)
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_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [23 x i8] c"Waiting on port %d...\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"
@.str.3 = [39 x i8] c"Accepted client at %s with %d len msg\0A\00"
@errno = global i64 0
@.str.4 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@.str.5 = [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_DGRAM
%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 = icmp ugt i32 %0, 3
%55 = getelementptr inbounds i8*, i8** %1, i64 3
%56 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0, i32 0
%58 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 1
%59 = getelementptr inbounds [65536 x i8], [65536 x i8]* %7, i64 0, i64 2
br label %60
60: ; preds = %77, %39
%61 = phi i32 [ 0, %39 ], [ %78, %77 ]
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %30)
br i1 %54, label %63, label %79
63: ; preds = %60
%64 = load i8*, i8** %55
%65 = load i32, i32* @O_WRONLY
%66 = load i32, i32* @O_CREAT
%67 = or i32 %66, %65
%68 = load i32, i32* @O_TRUNC
%69 = or i32 %67, %68
%70 = call i32 @open(i8* %64, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %72, label %79
72: ; preds = %63
%73 = load i32, i32* @stderr
%74 = load i8*, i8** %55
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %74)
%76 = call i32 @close(i32 %43)
br i1 %40, label %77, label %134
77: ; preds = %72, %120
%78 = phi i32 [ -1, %72 ], [ %80, %120 ]
br label %60
79: ; preds = %63, %60
%80 = phi i32 [ %70, %63 ], [ %61, %60 ]
%81 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
store i32 12, i32* %10
%82 = call i32 @recvfrom(i32 %43, i8* %13, i32 4096, i32 0, %struct.sockaddr* %56, i32* %10)
%83 = load i32, i32* %57
%84 = call i8* @inet_ntoa(i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %84, i32 %82)
%86 = icmp slt i32 %82, 1
br i1 %86, label %87, label %96
87: ; preds = %113, %79
%88 = phi i32 [ 0, %79 ], [ %114, %113 ]
%89 = phi i32 [ %82, %79 ], [ %115, %113 ]
%90 = load i64, i64* @errno
%91 = icmp eq i64 %90, 0
br i1 %91, label %120, label %92
92: ; preds = %87
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0), i32 %89, i64 %90)
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %79, %113
%97 = phi i32 [ %115, %113 ], [ %82, %79 ]
%98 = phi i32 [ %114, %113 ], [ 0, %79 ]
%99 = load i8, i8* %13
%100 = icmp eq i8 %99, 61
%101 = load i8, i8* %58
%102 = icmp eq i8 %101, 63
%103 = select i1 %100, i1 %102, i1 false
%104 = load i8, i8* %59
%105 = icmp eq i8 %104, 33
%106 = select i1 %103, i1 %105, i1 false
br i1 %106, label %107, label %110
107: ; preds = %96
br i1 %54, label %108, label %120
108: ; preds = %107
%109 = call i32 @close(i32 %80)
br label %120
110: ; preds = %96
br i1 %54, label %111, label %113
111: ; preds = %110
%112 = call i32 @write(i32 %80, i8* %13, i32 %97)
br label %113
113: ; preds = %111, %110
%114 = add nsw i32 %97, %98
store i32 12, i32* %10
%115 = call i32 @recvfrom(i32 %43, i8* %13, i32 4096, i32 0, %struct.sockaddr* %56, i32* %10)
%116 = load i32, i32* %57
%117 = call i8* @inet_ntoa(i32 %116)
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* %117, i32 %115)
%119 = icmp slt i32 %115, 1
br i1 %119, label %87, label %96
120: ; preds = %107, %108, %87
%121 = phi i32 [ %98, %107 ], [ %98, %108 ], [ %88, %87 ]
%122 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%123 = load <2 x double>, <2 x double>* %5
%124 = load <2 x double>, <2 x double>* %3
%125 = fsub <2 x double> %123, %124
%126 = extractelement <2 x double> %125, i64 1
%127 = fdiv double %126, 1.000000e+06
%128 = extractelement <2 x double> %125, i64 0
%129 = fadd double %128, %127
%130 = shl nsw i32 %121, 3
%131 = sitofp i32 %130 to double
%132 = fdiv double %131, %129
%133 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.5, i64 0, i64 0), i32 %121, double %129, double %132)
br i1 %40, label %77, label %134
134: ; preds = %120, %72
%135 = call i32 @close(i32 %43)
ret i32 0
}