#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*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int O_CREAT;
int O_TRUNC;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, 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 recv(int, char *, int, 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, t_now;
  int fd;
  int sockfd;
  char recvbuf[65536];
  struct sockaddr_in servaddr;
  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_STREAM, 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 (connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
    fprintf(stderr, "! Unable to connect the server.\n");
    exit(1);
  }
  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);
    }
  }
  gettimeofday(&t_start, NULL);
  for (;;) {
    ret = recv(sockfd, recvbuf, recvsize, 0);
    if (ret <= 0) {
      if (errno == 0 || errno == 2) {
        if (argc > 4)
          close(fd);
        break;
      }
      fprintf(stderr, "! Fail to recv: ret:%d, err:%d; quiting..\n", ret,
              errno);
      exit(1);
    }
    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);
  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   $0x1000,-0x10078(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1230 <main+0x50>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    124d <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x10078(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
mov    0x2d63(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x58(%rbp)
lea    -0x10070(%rbp),%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10068(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x1006c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x10070(%rbp)
mov    -0x58(%rbp),%edi
lea    -0x10070(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    12f5 <main+0x115>
mov    0x2ced(%rip),%rax
mov    (%rax),%edi
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jle    136a <main+0x18a>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    0x2c9a(%rip),%rax
mov    (%rax),%esi
mov    0x2ce1(%rip),%rax
or     (%rax),%esi
mov    0x2cd0(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    1365 <main+0x185>
mov    0x2c8d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    -0x58(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    136a <main+0x18a>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x58(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    -0x10078(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x10074(%rbp)
cmpl   $0x0,-0x10074(%rbp)
jg     1408 <main+0x228>
mov    0x2c10(%rip),%rax
cmpl   $0x0,(%rax)
je     13c1 <main+0x1e1>
mov    0x2c00(%rip),%rax
cmpl   $0x2,(%rax)
jne    13d8 <main+0x1f8>
cmpl   $0x4,-0x8(%rbp)
jle    13d3 <main+0x1f3>
mov    -0x54(%rbp),%edi
call   1080 <close@plt>
jmp    1438 <main+0x258>
mov    0x2be9(%rip),%rax
mov    (%rax),%edi
mov    -0x10074(%rbp),%edx
mov    0x2bca(%rip),%rax
mov    (%rax),%ecx
lea    0xc98(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x4,-0x8(%rbp)
jle    1427 <main+0x247>
mov    -0x54(%rbp),%edi
lea    -0x10060(%rbp),%rsi
mov    -0x10074(%rbp),%edx
call   1040 <write@plt>
mov    -0x10074(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1377 <main+0x197>
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  0xb9f(%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    0xc2e(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
mov    -0x58(%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,%rbp
cmp    $0x2,%edi
jle    13ac <main+0x1cc>
mov    %edi,%r15d
mov    $0x1000,%r13d
cmp    $0x3,%edi
je     1217 <main+0x37>
mov    0x18(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%r13d
mov    0x2dba(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,%r14d
lea    0x10(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    0x10(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   10f0 <connect@plt>
test   %rax,%rax
js     13c5 <main+0x1e5>
cmp    $0x5,%r15d
jb     12bc <main+0xdc>
mov    0x2d16(%rip),%rax
mov    0x2d5f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x20(%rbp),%rdi
mov    0x2d48(%rip),%rax
or     (%rax),%esi
call   10b0 <open@plt>
mov    %eax,0xc(%rsp)
cmp    $0xffffffff,%eax
je     1409 <main+0x229>
xor    %ebp,%ebp
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
lea    0x40(%rsp),%rsi
mov    %r14d,%edi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    131e <main+0x13e>
xor    %ebp,%ebp
lea    0x40(%rsp),%r12
jmp    1308 <main+0x128>
nopl   0x0(%rax,%rax,1)
add    %ebx,%ebp
mov    %r14d,%edi
mov    %r12,%rsi
mov    %r13d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    131e <main+0x13e>
cmp    $0x5,%r15d
jb     12f0 <main+0x110>
mov    0xc(%rsp),%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1040 <write@plt>
jmp    12f0 <main+0x110>
mov    0x2c93(%rip),%rax
mov    (%rax),%ecx
test   $0xfffffffd,%ecx
jne    13e6 <main+0x206>
cmp    $0x5,%r15d
jb     1342 <main+0x162>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movapd 0x20(%rsp),%xmm1
subpd  0x30(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xc96(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%rbp,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xd33(%rip),%rdi
mov    %ebp,%esi
mov    $0x2,%al
call   1060 <printf@plt>
mov    %r14d,%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    0x0(%rbp),%rsi
lea    0xc51(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10e0 <exit@plt>
mov    0x2bfc(%rip),%rax
mov    (%rax),%edi
lea    0xc7e(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
lea    0xc99(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    0x2bb8(%rip),%rax
mov    (%rax),%edi
mov    0x20(%rbp),%rdx
lea    0xc57(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   10e0 <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_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"! Unable to connect the server.\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [27 x i8] c"! Unable to open file %s.\0A\00"
@errno = global i32 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 %struct.timeval
%11 = alloca i32
%12 = alloca i32
%13 = alloca [65536 x i8]
%14 = alloca %struct.sockaddr_in
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 4096, i32* %16
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 3
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = load i32, i32* %4
%27 = icmp sgt i32 %26, 3
br i1 %27, label %28, label %33
28: ; preds = %25
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %16
br label %33
33: ; preds = %28, %25
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %12
%37 = call i32 @bzero(%struct.sockaddr_in* %14, i32 12)
%38 = load i32, i32* @AF_INET
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 2
store i32 %38, i32* %39
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @inet_addr(i8* %42)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 1
%45 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %44, i32 0, i32 0
store i32 %43, i32* %45
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 2
%48 = load i8*, i8** %47
%49 = call i32 @atoi(i8* %48)
%50 = call i32 @htons(i32 %49)
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %14, i32 0, i32 0
store i32 %50, i32* %51
%52 = load i32, i32* %12
%53 = bitcast %struct.sockaddr_in* %14 to %struct.sockaddr*
%54 = call i64 @connect(i32 %52, %struct.sockaddr* %53, i32 12)
%55 = icmp slt i64 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %33
%57 = load i32, i32* @stderr
%58 = call i32 (i32, i8*, ...) @fprintf(i32 %57, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 1)
unreachable
60: ; preds = %33
%61 = load i32, i32* %4
%62 = icmp sgt i32 %61, 4
br i1 %62, label %63, label %85
63: ; preds = %60
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 4
%66 = load i8*, i8** %65
%67 = load i32, i32* @O_WRONLY
%68 = load i32, i32* @O_CREAT
%69 = or i32 %67, %68
%70 = load i32, i32* @O_TRUNC
%71 = or i32 %69, %70
%72 = call i32 @open(i8* %66, i32 %71)
store i32 %72, i32* %11
%73 = load i32, i32* %11
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %84
75: ; preds = %63
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = getelementptr inbounds i8*, i8** %77, i64 4
%79 = load i8*, i8** %78
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %79)
%81 = load i32, i32* %12
%82 = call i32 @close(i32 %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %63
br label %85
85: ; preds = %84, %60
%86 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
br label %87
87: ; preds = %121, %85
%88 = load i32, i32* %12
%89 = getelementptr inbounds [65536 x i8], [65536 x i8]* %13, i64 0, i64 0
%90 = load i32, i32* %16
%91 = call i32 @recv(i32 %88, i8* %89, i32 %90, i32 0)
store i32 %91, i32* %15
%92 = load i32, i32* %15
%93 = icmp sle i32 %92, 0
br i1 %93, label %94, label %113
94: ; preds = %87
%95 = load i32, i32* @errno
%96 = icmp eq i32 %95, 0
br i1 %96, label %100, label %97
97: ; preds = %94
%98 = load i32, i32* @errno
%99 = icmp eq i32 %98, 2
br i1 %99, label %100, label %107
100: ; preds = %97, %94
%101 = load i32, i32* %4
%102 = icmp sgt i32 %101, 4
br i1 %102, label %103, label %106
103: ; preds = %100
%104 = load i32, i32* %11
%105 = call i32 @close(i32 %104)
br label %106
106: ; preds = %103, %100
br label %125
107: ; preds = %97
%108 = load i32, i32* @stderr
%109 = load i32, i32* %15
%110 = load i32, i32* @errno
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %108, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %109, i32 %110)
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %87
%114 = load i32, i32* %4
%115 = icmp sgt i32 %114, 4
br i1 %115, label %116, label %121
116: ; preds = %113
%117 = load i32, i32* %11
%118 = getelementptr inbounds [65536 x i8], [65536 x i8]* %13, i64 0, i64 0
%119 = load i32, i32* %15
%120 = call i32 @write(i32 %117, i8* %118, i32 %119)
br label %121
121: ; preds = %116, %113
%122 = load i32, i32* %15
%123 = load i32, i32* %6
%124 = add nsw i32 %123, %122
store i32 %124, i32* %6
br label %87
125: ; preds = %106
%126 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%127 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%128 = load double, double* %127
%129 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%130 = load double, double* %129
%131 = fsub double %128, %130
%132 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%133 = load double, double* %132
%134 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%135 = load double, double* %134
%136 = fsub double %133, %135
%137 = fdiv double %136, 1.000000e+06
%138 = fadd double %131, %137
store double %138, double* %7
%139 = load i32, i32* %6
%140 = load double, double* %7
%141 = load i32, i32* %6
%142 = mul nsw i32 %141, 8
%143 = sitofp i32 %142 to double
%144 = load double, double* %7
%145 = fdiv double %143, %144
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %139, double %140, double %145)
%147 = load i32, i32* %12
%148 = call i32 @close(i32 %147)
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_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"! Unable to connect the server.\0A\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [27 x i8] c"! Unable to open file %s.\0A\00"
@errno = global i32 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 = alloca [65536 x i8]
%7 = alloca %struct.sockaddr_in
%8 = bitcast <2 x double>* %3 to i8*
%9 = bitcast <2 x double>* %5 to i8*
%10 = getelementptr inbounds [65536 x i8], [65536 x i8]* %6, i64 0, i64 0
%11 = bitcast %struct.sockaddr_in* %7 to i8*
%12 = icmp slt i32 %0, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @exit(i32 0)
unreachable
17: ; preds = %2
%18 = icmp eq i32 %0, 3
br i1 %18, label %23, label %19
19: ; preds = %17
%20 = getelementptr inbounds i8*, i8** %1, i64 3
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
br label %23
23: ; preds = %19, %17
%24 = phi i32 [ %22, %19 ], [ 4096, %17 ]
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = tail call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %29, i32* %30
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = tail call i32 @inet_addr(i8* %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1, i32 0
store i32 %33, i32* %34
%35 = getelementptr inbounds i8*, i8** %1, i64 2
%36 = load i8*, i8** %35
%37 = tail call i32 @atoi(i8* %36)
%38 = tail call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
store i32 %38, i32* %39
%40 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%41 = call i64 @connect(i32 %27, %struct.sockaddr* %40, i32 12)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %23
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %23
%48 = icmp ugt i32 %0, 4
br i1 %48, label %49, label %65
49: ; preds = %47
%50 = getelementptr inbounds i8*, i8** %1, i64 4
%51 = load i8*, i8** %50
%52 = load i32, i32* @O_WRONLY
%53 = load i32, i32* @O_CREAT
%54 = or i32 %53, %52
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = call i32 @open(i8* %51, i32 %56)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %65
59: ; preds = %49
%60 = load i32, i32* @stderr
%61 = load i8*, i8** %50
%62 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = call i32 @close(i32 %27)
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %49, %47
%66 = phi i32 [ %57, %49 ], [ undef, %47 ]
%67 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%68 = call i32 @recv(i32 %27, i8* %10, i32 %24, i32 0)
%69 = icmp slt i32 %68, 1
br i1 %69, label %70, label %83
70: ; preds = %88, %65
%71 = phi i32 [ 0, %65 ], [ %89, %88 ]
%72 = phi i32 [ %68, %65 ], [ %90, %88 ]
%73 = load i32, i32* @errno
%74 = and i32 %73, -3
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %79
76: ; preds = %70
br i1 %48, label %77, label %92
77: ; preds = %76
%78 = call i32 @close(i32 %66)
br label %92
79: ; preds = %70
%80 = load i32, i32* @stderr
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %80, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %72, i32 %73)
%82 = call i32 @exit(i32 1)
unreachable
83: ; preds = %65, %88
%84 = phi i32 [ %90, %88 ], [ %68, %65 ]
%85 = phi i32 [ %89, %88 ], [ 0, %65 ]
br i1 %48, label %86, label %88
86: ; preds = %83
%87 = call i32 @write(i32 %66, i8* %10, i32 %84)
br label %88
88: ; preds = %86, %83
%89 = add nsw i32 %84, %85
%90 = call i32 @recv(i32 %27, i8* %10, i32 %24, i32 0)
%91 = icmp slt i32 %90, 1
br i1 %91, label %70, label %83
92: ; preds = %76, %77
%93 = bitcast <2 x double>* %5 to %struct.timeval*
%94 = call i32 @gettimeofday(%struct.timeval* %93, i32* null)
%95 = load <2 x double>, <2 x double>* %5
%96 = load <2 x double>, <2 x double>* %3
%97 = fsub <2 x double> %95, %96
%98 = extractelement <2 x double> %97, i64 1
%99 = fdiv double %98, 1.000000e+06
%100 = extractelement <2 x double> %97, i64 0
%101 = fadd double %100, %99
%102 = shl nsw i32 %71, 3
%103 = sitofp i32 %102 to double
%104 = fdiv double %103, %101
%105 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.4, i64 0, i64 0), i32 %71, double %101, double %104)
%106 = call i32 @close(i32 %27)
ret i32 0
}