#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 {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SOCK_DGRAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int open(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int recvfrom(int, char *, int, int /*<<< orphan*/, int /*<<< orphan*/ *,
             int /*<<< orphan*/ *);
int sendto(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int);
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 sockfd;
  char recvbuf[65536];
  struct sockaddr_in servaddr, cliaddr;
  socklen_t clilen;
  int ret;
  int recvsize = 4096;
  if (argc < 3) {
    printf("Usage: %s <ip> <port> <[optional] recvsize (bytes)> <[optional] "
           "filepath>\n",
           argv[0]);
    exit(0);
  }
  if (argc > 3)
    recvsize = atoi(argv[3]);
  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = inet_addr(argv[1]);
  servaddr.sin_port = htons(atoi(argv[2]));
  if (argc > 4) {
    fd = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC);
    if (fd == -1) {
      fprintf(stderr, "! Unable to open file %s.\n", argv[4]);
      close(sockfd);
      exit(1);
    }
  }
  ret = sendto(sockfd, "!?=\n", 4, 0, (struct sockaddr *)&servaddr,
               sizeof(servaddr));
  if (ret <= 0) {
    fprintf(stderr, "! Unable to initialize data transfer. errno:%d.\n", errno);
    close(sockfd);
    exit(1);
  }
  gettimeofday(&t_start, NULL);
  for (;;) {
    ret = recvfrom(sockfd, recvbuf, recvsize, 0, NULL, NULL);
    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] == '!'))
      break;
    if (argc > 4)
      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 (argc > 4)
    close(fd);
  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,-0x1007c(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1237 <main+0x57>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    1254 <main+0x74>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,-0x1007c(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    0x2d6c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x48(%rbp)
lea    -0x10060(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10058(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x1005c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x10060(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    1332 <main+0x152>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    0x2cd2(%rip),%rax
mov    (%rax),%esi
mov    0x2d19(%rip),%rax
or     (%rax),%esi
mov    0x2d08(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    132d <main+0x14d>
mov    0x2cbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd3f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1332 <main+0x152>
mov    -0x48(%rbp),%edi
lea    -0x10060(%rbp),%r8
lea    0xd2b(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
mov    %eax,-0x10078(%rbp)
cmpl   $0x0,-0x10078(%rbp)
jg     139a <main+0x1ba>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
mov    0x2c40(%rip),%rax
mov    (%rax),%edx
lea    0xcf2(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x48(%rbp),%edi
lea    -0x10050(%rbp),%rsi
mov    -0x1007c(%rbp),%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10b0 <recvfrom@plt>
mov    %eax,-0x10078(%rbp)
cmpl   $0x0,-0x10078(%rbp)
jg     141e <main+0x23e>
mov    0x2bd8(%rip),%rax
cmpl   $0x0,(%rax)
jne    13ee <main+0x20e>
jmp    1483 <main+0x2a3>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
mov    -0x10078(%rbp),%edx
mov    0x2bb4(%rip),%rax
mov    (%rax),%ecx
lea    0xc97(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movsbl -0x10050(%rbp),%eax
cmp    $0x3d,%eax
jne    1453 <main+0x273>
movsbl -0x1004f(%rbp),%eax
cmp    $0x3f,%eax
jne    1453 <main+0x273>
movsbl -0x1004e(%rbp),%eax
cmp    $0x21,%eax
jne    1453 <main+0x273>
jmp    1483 <main+0x2a3>
cmpl   $0x4,-0x8(%rbp)
jle    1472 <main+0x292>
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    13a7 <main+0x1c7>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x40(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  0xb54(%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    0xbf8(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x48(%rbp),%edi
call   1080 <close@plt>
cmpl   $0x4,-0x8(%rbp)
jle    14f8 <main+0x318>
mov    -0x44(%rbp),%edi
call   1080 <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    $0x10048,%rsp
mov    %rsi,%r12
cmp    $0x2,%edi
jle    13ff <main+0x21f>
mov    %edi,%r14d
movl   $0x1000,0xc(%rsp)
cmp    $0x3,%edi
je     121b <main+0x3b>
mov    0x18(%r12),%rdi
call   10e0 <atoi@plt>
mov    %eax,0xc(%rsp)
mov    0x2db6(%rip),%rbx
mov    (%rbx),%edi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
movl   $0x0,0x8(%rsp)
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r15d
lea    0x10(%rsp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r12),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%r12),%rdi
call   10e0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
cmp    $0x5,%r14d
jb     12af <main+0xcf>
mov    0x2d24(%rip),%rax
mov    0x2d6d(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x20(%r12),%rdi
mov    0x2d55(%rip),%rax
or     (%rax),%esi
call   10c0 <open@plt>
mov    %eax,0x8(%rsp)
cmp    $0xffffffff,%eax
je     145d <main+0x27d>
lea    0xdb8(%rip),%rsi
xor    %ebx,%ebx
lea    0x10(%rsp),%r8
mov    %r15d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
test   %eax,%eax
jle    1418 <main+0x238>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
lea    0x40(%rsp),%rsi
mov    %r15d,%r13d
mov    %r15d,%edi
mov    0xc(%rsp),%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10b0 <recvfrom@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1370 <main+0x190>
xor    %r15d,%r15d
lea    0x40(%rsp),%r12
jmp    1345 <main+0x165>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %ebp,%ebx
add    %r15d,%ebx
mov    %r13d,%edi
mov    %r12,%rsi
mov    0xc(%rsp),%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10b0 <recvfrom@plt>
mov    %eax,%ebp
mov    %ebx,%r15d
test   %eax,%eax
jle    1370 <main+0x190>
cmpb   $0x3d,0x40(%rsp)
jne    135a <main+0x17a>
cmpb   $0x3f,0x41(%rsp)
jne    135a <main+0x17a>
cmpb   $0x21,0x42(%rsp)
je     1384 <main+0x1a4>
cmp    $0x5,%r14d
jb     1320 <main+0x140>
mov    0x8(%rsp),%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1030 <write@plt>
jmp    1320 <main+0x140>
mov    0x2c41(%rip),%rax
mov    (%rax),%ecx
mov    %ebx,%r15d
test   %ecx,%ecx
jne    143a <main+0x25a>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movapd 0x20(%rsp),%xmm1
subpd  0x30(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xc54(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%r15,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xd05(%rip),%rdi
mov    %r15d,%esi
mov    $0x2,%al
call   1050 <printf@plt>
mov    %r13d,%edi
call   1080 <close@plt>
cmp    $0x5,%r14d
jb     13eb <main+0x20b>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x10048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r12),%rsi
lea    0xbfe(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%edi
mov    0x2b90(%rip),%rax
mov    (%rax),%edx
lea    0xc42(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1479 <main+0x299>
mov    0x2b7f(%rip),%rax
mov    (%rax),%edi
lea    0xc5a(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    0x2b5c(%rip),%rax
mov    (%rax),%edi
mov    0x20(%r12),%rdx
lea    0xbe1(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

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

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