#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 stat {
  int st_size;
};
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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
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*/ fstat(int, struct stat *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
scalar_t__ isNumber(char *);
int /*<<< orphan*/ listen(int, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int send(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*/ usleep(int);
int main(int argc, char *argv[]) {
  uint slotLength = 10000;
  uint quota = 1000000000;
  uint sentInSlot = 0, slot = 1;
  uint total_bytes_sent = 0;
  double elapsedTime;
  struct timeval t_start, t_end, t_now;
  int fd;
  int listenfd, sockfd;
  char sendbuf[65536];
  struct sockaddr_in servaddr, cliaddr;
  socklen_t clilen;
  int ret;
  int sendsize = 1460;
  uint bytes2send = 0;
  struct stat st;
  unsigned char listenOnce = 0;
  signal(SIGPIPE, SIG_IGN);
  if (argc < 3) {
    printf(
        "Usage: %s <port> <bytes2send/file2send> <[optional] bandwidth (bps)> "
        "<[optional] listenOnce ([0]/1)> <[optional] sendsize (bytes)>\n",
        argv[0]);
    exit(0);
  }
  if (argc > 3)
    quota = atoi(argv[3]) / 8 / (1000000 / slotLength);
  if (argc > 4)
    listenOnce = atoi(argv[4]);
  if (argc > 5)
    sendsize = atoi(argv[5]);
  if ((quota % sendsize) > 0) {
    slotLength =
        (uint)((double)(quota / sendsize + 1) * sendsize / quota * slotLength);
    quota = (quota / sendsize + 1) * sendsize;
  }
  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(atoi(argv[1]));
  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));
    if (isNumber(argv[2])) {
      bytes2send = atoi(argv[2]);
      fd = open("/dev/zero", O_RDONLY);
      if (fd == -1) {
        fprintf(stderr, "! Unable to open /data/local/tmp/bigfile.\n");
        exit(1);
      }
    } else {
      fd = open(argv[2], O_RDONLY);
      if (fd == -1) {
        fprintf(stderr, "! Unable to open file %s.\n", argv[2]);
        exit(1);
      }
      fstat(fd, &st);
      bytes2send = st.st_size;
      printf("bytes2send:%d\n", bytes2send);
    }
    total_bytes_sent = 0;
    sentInSlot = 0;
    slot = 1;
    gettimeofday(&t_start, NULL);
    while (total_bytes_sent < bytes2send) {
      if ((bytes2send - total_bytes_sent) < quota) {
        quota = bytes2send - total_bytes_sent;
      }
      while (sentInSlot < quota) {
        read(fd, sendbuf,
             (quota - sentInSlot < sendsize) ? (quota - sentInSlot) : sendsize);
        ret = send(sockfd, sendbuf,
                   (quota - sentInSlot < sendsize) ? (quota - sentInSlot)
                                                   : sendsize,
                   0);
        if (ret <= 0) {
          fprintf(stderr, "! Fail to send: ret:%d, err:%d; wait for 100us..\n",
                  ret, errno);
          total_bytes_sent = bytes2send + 1;
          break;
        }
        total_bytes_sent += ret;
        sentInSlot += ret;
      }
      if (total_bytes_sent > bytes2send) {
        break;
      }
      gettimeofday(&t_now, NULL);
      elapsedTime = (t_now.tv_sec - t_start.tv_sec) * 1000000.0 +
                    (t_now.tv_usec - t_start.tv_usec);
      if (elapsedTime < slotLength * slot) {
        usleep((int)(slotLength * slot - elapsedTime));
      }
      sentInSlot = 0;
      ++slot;
    }
    if (total_bytes_sent == bytes2send) {
      gettimeofday(&t_end, NULL);
      elapsedTime = (t_end.tv_sec - t_start.tv_sec) +
                    (t_end.tv_usec - t_start.tv_usec) / 1000000.0;
      printf("sent(bytes):%d\nduration(s):%lf\nthroughput(bps):%lf\n",
             total_bytes_sent, elapsedTime, total_bytes_sent * 8 / elapsedTime);
    } else {
      fprintf(stderr, "! error: total_bytes_sent > bytes2send\n");
    }
    close(sockfd);
    close(fd);
    if (listenOnce)
      break;
  }
  close(listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x2710,-0x14(%rbp)
movl   $0x3b9aca00,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x5b4,-0x1009c(%rbp)
movl   $0x0,-0x100a0(%rbp)
movb   $0x0,-0x100a9(%rbp)
mov    0x2d02(%rip),%rax
mov    (%rax),%edi
mov    0x2d19(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmpl   $0x3,-0x8(%rbp)
jge    12e4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    1320 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1130 <atoi@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x100b0(%rbp)
mov    $0xf4240,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x100b0(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jle    133d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1130 <atoi@plt>
mov    %al,-0x100a9(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    135a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x1009c(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1009c(%rbp)
cmp    $0x0,%edx
jle    13ba <main+0x16a>
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1009c(%rbp)
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x1009c(%rbp),%xmm1
ff
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1009c(%rbp)
add    $0x1,%eax
imul   -0x1009c(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
mov    0x2bee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x68(%rbp)
lea    -0x10080(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2bfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10078(%rbp)
mov    0x2bdb(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x10080(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x1007c(%rbp)
mov    -0x68(%rbp),%edi
lea    -0x10080(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
mov    -0x68(%rbp),%edi
mov    $0x1,%esi
call   10e0 <listen@plt>
movl   $0xc,-0x10094(%rbp)
mov    -0x68(%rbp),%edi
lea    -0x10090(%rbp),%rsi
lea    -0x10094(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x10090(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xc0f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <isNumber@plt>
cmp    $0x0,%rax
je     14f6 <main+0x2a6>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x100a0(%rbp)
mov    0x2b2b(%rip),%rax
mov    (%rax),%esi
lea    0xbe5(%rip),%rdi
call   1100 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    14f1 <main+0x2a1>
mov    0x2ae9(%rip),%rax
mov    (%rax),%edi
lea    0xbcd(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
jmp    1571 <main+0x321>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2adb(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1542 <main+0x2f2>
mov    0x2aa0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xba7(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x64(%rbp),%edi
lea    -0x100a8(%rbp),%rsi
call   1150 <fstat@plt>
mov    -0x100a8(%rbp),%eax
mov    %eax,-0x100a0(%rbp)
mov    -0x100a0(%rbp),%esi
lea    0xb89(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jge    1788 <main+0x538>
mov    -0x100a0(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    15c0 <main+0x370>
mov    -0x100a0(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    15c5 <main+0x375>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    16f6 <main+0x4a6>
mov    -0x64(%rbp),%eax
mov    %eax,-0x100bc(%rbp)
lea    -0x10070(%rbp),%rax
mov    %rax,-0x100b8(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    -0x1009c(%rbp),%eax
jge    160b <main+0x3bb>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x100c0(%rbp)
jmp    1617 <main+0x3c7>
mov    -0x1009c(%rbp),%eax
mov    %eax,-0x100c0(%rbp)
mov    -0x100b8(%rbp),%rsi
mov    -0x100bc(%rbp),%edi
mov    -0x100c0(%rbp),%edx
call   10a0 <read@plt>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x100cc(%rbp)
lea    -0x10070(%rbp),%rax
mov    %rax,-0x100c8(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    -0x1009c(%rbp),%eax
jge    1669 <main+0x419>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x100d0(%rbp)
jmp    1675 <main+0x425>
mov    -0x1009c(%rbp),%eax
mov    %eax,-0x100d0(%rbp)
mov    -0x100c8(%rbp),%rsi
mov    -0x100cc(%rbp),%edi
mov    -0x100d0(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x10098(%rbp)
cmpl   $0x0,-0x10098(%rbp)
jg     16d9 <main+0x489>
mov    0x2917(%rip),%rax
mov    (%rax),%edi
mov    -0x10098(%rbp),%edx
mov    0x28f0(%rip),%rax
mov    (%rax),%ecx
lea    0xa41(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x100a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    16f6 <main+0x4a6>
mov    -0x10098(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10098(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    15c5 <main+0x375>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jle    170a <main+0x4ba>
jmp    1788 <main+0x538>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movsd  -0x60(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0x8cd(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1773 <main+0x523>
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1160 <usleep@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1593 <main+0x343>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jne    17f7 <main+0x5a7>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1070 <gettimeofday@plt>
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0x840(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%esi
movsd  -0x30(%rbp),%xmm0
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cvtsi2sd %eax,%xmm1
divsd  -0x30(%rbp),%xmm1
lea    0x949(%rip),%rdi
mov    $0x2,%al
call   1060 <printf@plt>
jmp    180e <main+0x5be>
mov    0x27c2(%rip),%rax
mov    (%rax),%edi
lea    0x961(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x6c(%rbp),%edi
call   1090 <close@plt>
mov    -0x64(%rbp),%edi
call   1090 <close@plt>
cmpb   $0x0,-0x100a9(%rbp)
je     1830 <main+0x5e0>
jmp    1835 <main+0x5e5>
jmp    1445 <main+0x1f5>
mov    -0x68(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x100d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100a8,%rsp
mov    %rsi,%r13
mov    %edi,%r14d
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmp    $0x2,%r14d
jle    16f4 <main+0x4a4>
mov    $0x5b4,%ebp
cmp    $0x3,%r14d
jne    129a <main+0x4a>
mov    $0x3b9aca00,%ebx
jmp    12df <main+0x8f>
mov    0x18(%r13),%rdi
call   1130 <atoi@plt>
cltq
imul   $0x51eb851f,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x28,%rbx
add    %eax,%ebx
cmp    $0x5,%r14d
jb     12df <main+0x8f>
mov    0x20(%r13),%rdi
call   1130 <atoi@plt>
mov    %eax,0x4(%rsp)
cmp    $0x5,%r14d
je     12e7 <main+0x97>
mov    0x28(%r13),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebp
jmp    12e7 <main+0x97>
movl   $0x0,0x4(%rsp)
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
jle    131e <main+0xce>
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sd %ebp,%xmm1
cvtsi2sd %ebx,%xmm2
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
mulsd  0xcf1(%rip),%xmm1
cvttsd2si %xmm1,%ecx
mov    %ecx,0x10(%rsp)
imul   %ebp,%eax
mov    %eax,%ebx
jmp    1326 <main+0xd6>
movl   $0x2710,0x10(%rsp)
mov    0x2cbb(%rip),%r15
mov    (%r15),%edi
mov    0x2c81(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x38(%rsp)
mov    0x2c75(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x30(%rsp)
mov    0x8(%r13),%rdi
call   1130 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x34(%rsp)
mov    %r12d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
mov    %r12d,0xc(%rsp)
mov    %r12d,%edi
mov    $0x1,%esi
call   10e0 <listen@plt>
mov    0x2c15(%rip),%r14
mov    %r13,0x18(%rsp)
jmp    1419 <main+0x1c9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x2bf9(%rip),%r14
mov    (%r14),%edi
mov    0x2bd7(%rip),%rcx
mov    (%rcx),%ecx
lea    0xd30(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x18(%rsp),%r13
mov    %r12d,%ebp
mov    (%r14),%edi
lea    0xd7b(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x14(%rsp),%edi
call   1090 <close@plt>
mov    0x8(%rsp),%edi
call   1090 <close@plt>
cmpb   $0x0,0x4(%rsp)
jne    169d <main+0x44d>
movl   $0xc,0x2c(%rsp)
mov    0xc(%rsp),%edi
lea    0x80(%rsp),%rsi
lea    0x2c(%rsp),%rdx
call   1120 <accept@plt>
mov    %eax,0x14(%rsp)
mov    0x80(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xc46(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%r13),%rdi
call   10c0 <isNumber@plt>
mov    0x10(%r13),%rdi
test   %rax,%rax
je     14a0 <main+0x250>
call   1130 <atoi@plt>
mov    %eax,%r15d
mov    0x2b67(%rip),%rax
mov    (%rax),%esi
lea    0xc29(%rip),%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     16ba <main+0x46a>
mov    %eax,0x8(%rsp)
jmp    14dd <main+0x28d>
cs nopw 0x0(%rax,%rax,1)
mov    0x2b39(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     16d5 <main+0x485>
mov    %eax,0x8(%rsp)
mov    %eax,%edi
lea    0x20(%rsp),%rsi
call   1150 <fstat@plt>
mov    0x20(%rsp),%r15d
lea    0xc28(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%r12
xor    %r13d,%r13d
lea    0x40(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
test   %r15d,%r15d
jle    1620 <main+0x3d0>
movsd  0x40(%rsp),%xmm0
movsd  %xmm0,0x60(%rsp)
movsd  0x48(%rsp),%xmm0
movsd  %xmm0,0x58(%rsp)
mov    $0x1,%ebx
xor    %r13d,%r13d
mov    %r15,0x68(%rsp)
jmp    152c <main+0x2dc>
nop
add    $0x1,%ebx
cmp    %r13d,%r15d
jle    1620 <main+0x3d0>
mov    %ebx,0x28(%rsp)
mov    %r12d,%eax
mov    %r15d,%ebx
sub    %r13d,%ebx
cmp    %r12d,%ebx
cmovge %r12d,%ebx
test   %ebx,%ebx
jle    159e <main+0x34e>
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %ebx,%r14d
sub    %r15d,%r14d
cmp    %ebp,%r14d
mov    %ebp,%r12d
cmovge %ebp,%r14d
mov    0x8(%rsp),%edi
lea    0xa0(%rsp),%rbp
mov    %rbp,%rsi
mov    %r14d,%edx
call   10a0 <read@plt>
mov    0x14(%rsp),%edi
mov    %rbp,%rsi
mov    %r14d,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
test   %eax,%eax
jle    13c0 <main+0x170>
add    %eax,%r13d
add    %eax,%r15d
cmp    %r15d,%ebx
mov    %r12d,%ebp
jg     1550 <main+0x300>
mov    %rbx,%r12
mov    0x68(%rsp),%r15
cmp    %r15d,%r13d
jg     1610 <main+0x3c0>
lea    0x70(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movsd  0x70(%rsp),%xmm0
subsd  0x60(%rsp),%xmm0
movsd  0x78(%rsp),%xmm1
subsd  0x58(%rsp),%xmm1
mulsd  0xa31(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    0x28(%rsp),%ebx
mov    %ebx,%eax
imul   0x10(%rsp),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd %xmm0,%xmm1
mov    0x29c8(%rip),%r14
jbe    1520 <main+0x2d0>
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1160 <usleep@plt>
jmp    1520 <main+0x2d0>
mov    0x29a9(%rip),%r14
nopw   0x0(%rax,%rax,1)
cmp    %r15d,%r13d
jne    1690 <main+0x440>
lea    0x90(%rsp),%rdi
xor    %esi,%esi
call   1070 <gettimeofday@plt>
movapd 0x90(%rsp),%xmm1
subpd  0x40(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0x9b5(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%r15,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xacb(%rip),%rdi
mov    %r15d,%esi
mov    $0x2,%al
call   1060 <printf@plt>
mov    0x18(%rsp),%r13
mov    %r12,%rbx
jmp    13fc <main+0x1ac>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%r13
mov    %r12,%rbx
jmp    13eb <main+0x19b>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x100a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r14),%edi
lea    0x9f1(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    (%r14),%edi
mov    0x10(%r13),%rdx
lea    0x9fd(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    0x0(%r13),%rsi
lea    0x911(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   1140 <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.stat = type { i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [132 x i8] c"Usage: %s <port> <bytes2send/file2send> <[optional] bandwidth (bps)> <[optional] listenOnce ([0]/1)> <[optional] sendsize (bytes)>\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"
@.str.2 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.3 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.4 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.5 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.6 = [50 x i8] c"! Fail to send: ret:%d, err:%d; wait for 100us..\0A\00"
@errno = global i32 0
@.str.7 = [52 x i8] c"sent(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
@.str.8 = [40 x i8] c"! error: total_bytes_sent > bytes2send\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
%12 = alloca %struct.timeval
%13 = alloca %struct.timeval
%14 = alloca %struct.timeval
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [65536 x i8]
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.sockaddr_in
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca %struct.stat
%26 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10000, i32* %6
store i32 1000000000, i32* %7
store i32 0, i32* %8
store i32 1, i32* %9
store i32 0, i32* %10
store i32 1460, i32* %23
store i32 0, i32* %24
store i8 0, i8* %26
%27 = load i32, i32* @SIGPIPE
%28 = load i32, i32* @SIG_IGN
%29 = call i32 @signal(i32 %27, i32 %28)
%30 = load i32, i32* %4
%31 = icmp slt i32 %30, 3
br i1 %31, label %32, label %38
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = call i32 @exit(i32 0)
unreachable
38: ; preds = %2
%39 = load i32, i32* %4
%40 = icmp sgt i32 %39, 3
br i1 %40, label %41, label %50
41: ; preds = %38
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = call i32 @atoi(i8* %44)
%46 = sdiv i32 %45, 8
%47 = load i32, i32* %6
%48 = sdiv i32 1000000, %47
%49 = sdiv i32 %46, %48
store i32 %49, i32* %7
br label %50
50: ; preds = %41, %38
%51 = load i32, i32* %4
%52 = icmp sgt i32 %51, 4
br i1 %52, label %53, label %59
53: ; preds = %50
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 4
%56 = load i8*, i8** %55
%57 = call i32 @atoi(i8* %56)
%58 = trunc i32 %57 to i8
store i8 %58, i8* %26
br label %59
59: ; preds = %53, %50
%60 = load i32, i32* %4
%61 = icmp sgt i32 %60, 5
br i1 %61, label %62, label %67
62: ; preds = %59
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 5
%65 = load i8*, i8** %64
%66 = call i32 @atoi(i8* %65)
store i32 %66, i32* %23
br label %67
67: ; preds = %62, %59
%68 = load i32, i32* %7
%69 = load i32, i32* %23
%70 = srem i32 %68, %69
%71 = icmp sgt i32 %70, 0
br i1 %71, label %72, label %94
72: ; preds = %67
%73 = load i32, i32* %7
%74 = load i32, i32* %23
%75 = sdiv i32 %73, %74
%76 = add nsw i32 %75, 1
%77 = sitofp i32 %76 to double
%78 = load i32, i32* %23
%79 = sitofp i32 %78 to double
%80 = fmul double %77, %79
%81 = load i32, i32* %7
%82 = sitofp i32 %81 to double
%83 = fdiv double %80, %82
%84 = load i32, i32* %6
%85 = sitofp i32 %84 to double
%86 = fmul double %83, %85
%87 = fptosi double %86 to i32
store i32 %87, i32* %6
%88 = load i32, i32* %7
%89 = load i32, i32* %23
%90 = sdiv i32 %88, %89
%91 = add nsw i32 %90, 1
%92 = load i32, i32* %23
%93 = mul nsw i32 %91, %92
store i32 %93, i32* %7
br label %94
94: ; preds = %72, %67
%95 = load i32, i32* @AF_INET
%96 = load i32, i32* @SOCK_STREAM
%97 = call i32 @socket(i32 %95, i32 %96, i32 0)
store i32 %97, i32* %16
%98 = call i32 @bzero(%struct.sockaddr_in* %19, i32 12)
%99 = load i32, i32* @AF_INET
%100 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
store i32 %99, i32* %100
%101 = load i32, i32* @INADDR_ANY
%102 = call i32 @htonl(i32 %101)
%103 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%104 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %103, i32 0, i32 0
store i32 %102, i32* %104
%105 = load i8**, i8*** %5
%106 = getelementptr inbounds i8*, i8** %105, i64 1
%107 = load i8*, i8** %106
%108 = call i32 @atoi(i8* %107)
%109 = call i32 @htons(i32 %108)
%110 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i32 %109, i32* %110
%111 = load i32, i32* %16
%112 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%113 = call i32 @bind(i32 %111, %struct.sockaddr* %112, i32 12)
%114 = load i32, i32* %16
%115 = call i32 @listen(i32 %114, i32 1)
br label %116
116: ; preds = %309, %94
store i32 12, i32* %21
%117 = load i32, i32* %16
%118 = bitcast %struct.sockaddr_in* %20 to %struct.sockaddr*
%119 = call i32 @accept(i32 %117, %struct.sockaddr* %118, i32* %21)
store i32 %119, i32* %17
%120 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%121 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %120, i32 0, i32 0
%122 = load i32, i32* %121
%123 = call i8* @inet_ntoa(i32 %122)
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %123)
%125 = load i8**, i8*** %5
%126 = getelementptr inbounds i8*, i8** %125, i64 2
%127 = load i8*, i8** %126
%128 = call i64 @isNumber(i8* %127)
%129 = icmp ne i64 %128, 0
br i1 %129, label %130, label %144
130: ; preds = %116
%131 = load i8**, i8*** %5
%132 = getelementptr inbounds i8*, i8** %131, i64 2
%133 = load i8*, i8** %132
%134 = call i32 @atoi(i8* %133)
store i32 %134, i32* %24
%135 = load i32, i32* @O_RDONLY
%136 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %135)
store i32 %136, i32* %15
%137 = load i32, i32* %15
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %143
139: ; preds = %130
%140 = load i32, i32* @stderr
%141 = call i32 (i32, i8*, ...) @fprintf(i32 %140, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %130
br label %166
144: ; preds = %116
%145 = load i8**, i8*** %5
%146 = getelementptr inbounds i8*, i8** %145, i64 2
%147 = load i8*, i8** %146
%148 = load i32, i32* @O_RDONLY
%149 = call i32 @open(i8* %147, i32 %148)
store i32 %149, i32* %15
%150 = load i32, i32* %15
%151 = icmp eq i32 %150, -1
br i1 %151, label %152, label %159
152: ; preds = %144
%153 = load i32, i32* @stderr
%154 = load i8**, i8*** %5
%155 = getelementptr inbounds i8*, i8** %154, i64 2
%156 = load i8*, i8** %155
%157 = call i32 (i32, i8*, ...) @fprintf(i32 %153, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %156)
%158 = call i32 @exit(i32 1)
unreachable
159: ; preds = %144
%160 = load i32, i32* %15
%161 = call i32 @fstat(i32 %160, %struct.stat* %25)
%162 = getelementptr inbounds %struct.stat, %struct.stat* %25, i32 0, i32 0
%163 = load i32, i32* %162
store i32 %163, i32* %24
%164 = load i32, i32* %24
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %164)
br label %166
166: ; preds = %159, %143
store i32 0, i32* %10
store i32 0, i32* %8
store i32 1, i32* %9
%167 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
br label %168
168: ; preds = %269, %166
%169 = load i32, i32* %10
%170 = load i32, i32* %24
%171 = icmp slt i32 %169, %170
br i1 %171, label %172, label %272
172: ; preds = %168
%173 = load i32, i32* %24
%174 = load i32, i32* %10
%175 = sub nsw i32 %173, %174
%176 = load i32, i32* %7
%177 = icmp slt i32 %175, %176
br i1 %177, label %178, label %182
178: ; preds = %172
%179 = load i32, i32* %24
%180 = load i32, i32* %10
%181 = sub nsw i32 %179, %180
store i32 %181, i32* %7
br label %182
182: ; preds = %178, %172
br label %183
183: ; preds = %229, %182
%184 = load i32, i32* %8
%185 = load i32, i32* %7
%186 = icmp slt i32 %184, %185
br i1 %186, label %187, label %236
187: ; preds = %183
%188 = load i32, i32* %15
%189 = getelementptr inbounds [65536 x i8], [65536 x i8]* %18, i64 0, i64 0
%190 = load i32, i32* %7
%191 = load i32, i32* %8
%192 = sub nsw i32 %190, %191
%193 = load i32, i32* %23
%194 = icmp slt i32 %192, %193
br i1 %194, label %195, label %199
195: ; preds = %187
%196 = load i32, i32* %7
%197 = load i32, i32* %8
%198 = sub nsw i32 %196, %197
br label %201
199: ; preds = %187
%200 = load i32, i32* %23
br label %201
201: ; preds = %199, %195
%202 = phi i32 [ %198, %195 ], [ %200, %199 ]
%203 = call i32 @read(i32 %188, i8* %189, i32 %202)
%204 = load i32, i32* %17
%205 = getelementptr inbounds [65536 x i8], [65536 x i8]* %18, i64 0, i64 0
%206 = load i32, i32* %7
%207 = load i32, i32* %8
%208 = sub nsw i32 %206, %207
%209 = load i32, i32* %23
%210 = icmp slt i32 %208, %209
br i1 %210, label %211, label %215
211: ; preds = %201
%212 = load i32, i32* %7
%213 = load i32, i32* %8
%214 = sub nsw i32 %212, %213
br label %217
215: ; preds = %201
%216 = load i32, i32* %23
br label %217
217: ; preds = %215, %211
%218 = phi i32 [ %214, %211 ], [ %216, %215 ]
%219 = call i32 @send(i32 %204, i8* %205, i32 %218, i32 0)
store i32 %219, i32* %22
%220 = load i32, i32* %22
%221 = icmp sle i32 %220, 0
br i1 %221, label %222, label %229
222: ; preds = %217
%223 = load i32, i32* @stderr
%224 = load i32, i32* %22
%225 = load i32, i32* @errno
%226 = call i32 (i32, i8*, ...) @fprintf(i32 %223, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %224, i32 %225)
%227 = load i32, i32* %24
%228 = add nsw i32 %227, 1
store i32 %228, i32* %10
br label %236
229: ; preds = %217
%230 = load i32, i32* %22
%231 = load i32, i32* %10
%232 = add nsw i32 %231, %230
store i32 %232, i32* %10
%233 = load i32, i32* %22
%234 = load i32, i32* %8
%235 = add nsw i32 %234, %233
store i32 %235, i32* %8
br label %183
236: ; preds = %222, %183
%237 = load i32, i32* %10
%238 = load i32, i32* %24
%239 = icmp sgt i32 %237, %238
br i1 %239, label %240, label %241
240: ; preds = %236
br label %272
241: ; preds = %236
%242 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%243 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%244 = load double, double* %243
%245 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%246 = load double, double* %245
%247 = fsub double %244, %246
%248 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%249 = load double, double* %248
%250 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%251 = load double, double* %250
%252 = fsub double %249, %251
%253 = call double @llvm.fmuladd.f64(double %247, double 1.000000e+06, double %252)
store double %253, double* %11
%254 = load double, double* %11
%255 = load i32, i32* %6
%256 = load i32, i32* %9
%257 = mul nsw i32 %255, %256
%258 = sitofp i32 %257 to double
%259 = fcmp olt double %254, %258
br i1 %259, label %260, label %269
260: ; preds = %241
%261 = load i32, i32* %6
%262 = load i32, i32* %9
%263 = mul nsw i32 %261, %262
%264 = sitofp i32 %263 to double
%265 = load double, double* %11
%266 = fsub double %264, %265
%267 = fptosi double %266 to i32
%268 = call i32 @usleep(i32 %267)
br label %269
269: ; preds = %260, %241
store i32 0, i32* %8
%270 = load i32, i32* %9
%271 = add nsw i32 %270, 1
store i32 %271, i32* %9
br label %168
272: ; preds = %240, %168
%273 = load i32, i32* %10
%274 = load i32, i32* %24
%275 = icmp eq i32 %273, %274
br i1 %275, label %276, label %298
276: ; preds = %272
%277 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%278 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%279 = load double, double* %278
%280 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%281 = load double, double* %280
%282 = fsub double %279, %281
%283 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%284 = load double, double* %283
%285 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%286 = load double, double* %285
%287 = fsub double %284, %286
%288 = fdiv double %287, 1.000000e+06
%289 = fadd double %282, %288
store double %289, double* %11
%290 = load i32, i32* %10
%291 = load double, double* %11
%292 = load i32, i32* %10
%293 = mul nsw i32 %292, 8
%294 = sitofp i32 %293 to double
%295 = load double, double* %11
%296 = fdiv double %294, %295
%297 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i32 %290, double %291, double %296)
br label %301
298: ; preds = %272
%299 = load i32, i32* @stderr
%300 = call i32 (i32, i8*, ...) @fprintf(i32 %299, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %301
301: ; preds = %298, %276
%302 = load i32, i32* %17
%303 = call i32 @close(i32 %302)
%304 = load i32, i32* %15
%305 = call i32 @close(i32 %304)
%306 = load i8, i8* %26
%307 = icmp ne i8 %306, 0
br i1 %307, label %308, label %309
308: ; preds = %301
br label %310
309: ; preds = %301
br label %116
310: ; preds = %308
%311 = load i32, i32* %16
%312 = call i32 @close(i32 %311)
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.stat = type { i32 }
%struct.sockaddr = type { i32 }
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@.str = [132 x i8] c"Usage: %s <port> <bytes2send/file2send> <[optional] bandwidth (bps)> <[optional] listenOnce ([0]/1)> <[optional] sendsize (bytes)>\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"
@.str.2 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.3 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.4 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.5 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.6 = [50 x i8] c"! Fail to send: ret:%d, err:%d; wait for 100us..\0A\00"
@errno = global i32 0
@.str.7 = [52 x i8] c"sent(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
@.str.8 = [40 x i8] c"! error: total_bytes_sent > bytes2send\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 %struct.timeval
%8 = alloca [65536 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca %struct.stat
%13 = bitcast <2 x double>* %3 to i8*
%14 = bitcast <2 x double>* %5 to i8*
%15 = bitcast %struct.timeval* %7 to i8*
%16 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 0
%17 = bitcast %struct.sockaddr_in* %9 to i8*
%18 = bitcast %struct.sockaddr_in* %10 to i8*
%19 = bitcast i32* %11 to i8*
%20 = bitcast %struct.stat* %12 to i8*
%21 = load i32, i32* @SIGPIPE
%22 = load i32, i32* @SIG_IGN
%23 = tail call i32 @signal(i32 %21, i32 %22)
%24 = icmp slt i32 %0, 3
br i1 %24, label %25, label %29
25: ; preds = %2
%26 = load i8*, i8** %1
%27 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = tail call i32 @exit(i32 0)
unreachable
29: ; preds = %2
%30 = icmp eq i32 %0, 3
br i1 %30, label %47, label %31
31: ; preds = %29
%32 = getelementptr inbounds i8*, i8** %1, i64 3
%33 = load i8*, i8** %32
%34 = tail call i32 @atoi(i8* %33)
%35 = sdiv i32 %34, 800
%36 = icmp ugt i32 %0, 4
br i1 %36, label %37, label %47
37: ; preds = %31
%38 = getelementptr inbounds i8*, i8** %1, i64 4
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = trunc i32 %40 to i8
%42 = icmp eq i32 %0, 5
br i1 %42, label %47, label %43
43: ; preds = %37
%44 = getelementptr inbounds i8*, i8** %1, i64 5
%45 = load i8*, i8** %44
%46 = tail call i32 @atoi(i8* %45)
br label %47
47: ; preds = %29, %31, %43, %37
%48 = phi i8 [ %41, %43 ], [ %41, %37 ], [ 0, %31 ], [ 0, %29 ]
%49 = phi i32 [ %35, %43 ], [ %35, %37 ], [ %35, %31 ], [ 1000000000, %29 ]
%50 = phi i32 [ %46, %43 ], [ 1460, %37 ], [ 1460, %31 ], [ 1460, %29 ]
%51 = srem i32 %49, %50
%52 = sdiv i32 %49, %50
%53 = icmp sgt i32 %51, 0
br i1 %53, label %54, label %64
54: ; preds = %47
%55 = add nsw i32 %52, 1
%56 = sitofp i32 %55 to double
%57 = sitofp i32 %50 to double
%58 = fmul double %57, %56
%59 = sitofp i32 %49 to double
%60 = fdiv double %58, %59
%61 = fmul double %60, 1.000000e+04
%62 = fptosi double %61 to i32
%63 = mul nsw i32 %55, %50
br label %64
64: ; preds = %54, %47
%65 = phi i32 [ %63, %54 ], [ %49, %47 ]
%66 = phi i32 [ %62, %54 ], [ 10000, %47 ]
%67 = load i32, i32* @AF_INET
%68 = load i32, i32* @SOCK_STREAM
%69 = tail call i32 @socket(i32 %67, i32 %68, i32 0)
%70 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%71 = load i32, i32* @AF_INET
%72 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %71, i32* %72
%73 = load i32, i32* @INADDR_ANY
%74 = tail call i32 @htonl(i32 %73)
%75 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0, i32 0
store i32 %74, i32* %75
%76 = getelementptr inbounds i8*, i8** %1, i64 1
%77 = load i8*, i8** %76
%78 = tail call i32 @atoi(i8* %77)
%79 = tail call i32 @htons(i32 %78)
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1
store i32 %79, i32* %80
%81 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%82 = call i32 @bind(i32 %69, %struct.sockaddr* %81, i32 12)
%83 = call i32 @listen(i32 %69, i32 1)
%84 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%85 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i64 0, i32 0, i32 0
%86 = getelementptr inbounds i8*, i8** %1, i64 2
%87 = getelementptr inbounds %struct.stat, %struct.stat* %12, i64 0, i32 0
%88 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%89 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 0
%90 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%91 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 1
%92 = icmp eq i8 %48, 0
br label %93
93: ; preds = %199, %64
%94 = phi i32 [ %65, %64 ], [ %200, %199 ]
store i32 12, i32* %11
%95 = call i32 @accept(i32 %69, %struct.sockaddr* %84, i32* %11)
%96 = load i32, i32* %85
%97 = call i8* @inet_ntoa(i32 %96)
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %97)
%99 = load i8*, i8** %86
%100 = call i64 @isNumber(i8* %99)
%101 = icmp eq i64 %100, 0
%102 = load i8*, i8** %86
br i1 %101, label %112, label %103
103: ; preds = %93
%104 = call i32 @atoi(i8* %102)
%105 = load i32, i32* @O_RDONLY
%106 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %105)
%107 = icmp eq i32 %106, -1
br i1 %107, label %108, label %125
108: ; preds = %103
%109 = load i32, i32* @stderr
%110 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0))
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %93
%113 = load i32, i32* @O_RDONLY
%114 = call i32 @open(i8* %102, i32 %113)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %121
116: ; preds = %112
%117 = load i32, i32* @stderr
%118 = load i8*, i8** %86
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %118)
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %112
%122 = call i32 @fstat(i32 %114, %struct.stat* %12)
%123 = load i32, i32* %87
%124 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i32 %123)
br label %125
125: ; preds = %103, %121
%126 = phi i32 [ %106, %103 ], [ %114, %121 ]
%127 = phi i32 [ %104, %103 ], [ %123, %121 ]
%128 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%129 = icmp sgt i32 %127, 0
br i1 %129, label %130, label %178
130: ; preds = %125
%131 = load double, double* %89
%132 = load double, double* %91
br label %133
133: ; preds = %130, %175
%134 = phi i32 [ %94, %130 ], [ %139, %175 ]
%135 = phi i32 [ 0, %130 ], [ %159, %175 ]
%136 = phi i32 [ 1, %130 ], [ %176, %175 ]
%137 = sub nsw i32 %127, %135
%138 = icmp slt i32 %137, %134
%139 = select i1 %138, i32 %137, i32 %134
%140 = icmp sgt i32 %139, 0
br i1 %140, label %141, label %158
141: ; preds = %133, %154
%142 = phi i32 [ %156, %154 ], [ 0, %133 ]
%143 = phi i32 [ %155, %154 ], [ %135, %133 ]
%144 = sub nsw i32 %139, %142
%145 = icmp slt i32 %144, %50
%146 = select i1 %145, i32 %144, i32 %50
%147 = call i32 @read(i32 %126, i8* %16, i32 %146)
%148 = call i32 @send(i32 %95, i8* %16, i32 %146, i32 0)
%149 = icmp slt i32 %148, 1
br i1 %149, label %150, label %154
150: ; preds = %141
%151 = load i32, i32* @stderr
%152 = load i32, i32* @errno
%153 = call i32 (i32, i8*, ...) @fprintf(i32 %151, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.6, i64 0, i64 0), i32 %148, i32 %152)
br label %195
154: ; preds = %141
%155 = add nsw i32 %148, %143
%156 = add nsw i32 %148, %142
%157 = icmp sgt i32 %139, %156
br i1 %157, label %141, label %158
158: ; preds = %154, %133
%159 = phi i32 [ %135, %133 ], [ %155, %154 ]
%160 = icmp sgt i32 %159, %127
br i1 %160, label %178, label %161
161: ; preds = %158
%162 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%163 = load double, double* %88
%164 = fsub double %163, %131
%165 = load double, double* %90
%166 = fsub double %165, %132
%167 = call double @llvm.fmuladd.f64(double %164, double 1.000000e+06, double %166)
%168 = mul nsw i32 %136, %66
%169 = sitofp i32 %168 to double
%170 = fcmp olt double %167, %169
br i1 %170, label %171, label %175
171: ; preds = %161
%172 = fsub double %169, %167
%173 = fptosi double %172 to i32
%174 = call i32 @usleep(i32 %173)
br label %175
175: ; preds = %171, %161
%176 = add nuw nsw i32 %136, 1
%177 = icmp sgt i32 %127, %159
br i1 %177, label %133, label %178
178: ; preds = %175, %158, %125
%179 = phi i32 [ 0, %125 ], [ %159, %158 ], [ %159, %175 ]
%180 = phi i32 [ %94, %125 ], [ %139, %158 ], [ %139, %175 ]
%181 = icmp eq i32 %179, %127
br i1 %181, label %182, label %195
182: ; preds = %178
%183 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%184 = load <2 x double>, <2 x double>* %5
%185 = load <2 x double>, <2 x double>* %3
%186 = fsub <2 x double> %184, %185
%187 = extractelement <2 x double> %186, i64 1
%188 = fdiv double %187, 1.000000e+06
%189 = extractelement <2 x double> %186, i64 0
%190 = fadd double %189, %188
%191 = shl nsw i32 %127, 3
%192 = sitofp i32 %191 to double
%193 = fdiv double %192, %190
%194 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0), i32 %127, double %190, double %193)
br label %199
195: ; preds = %150, %178
%196 = phi i32 [ %139, %150 ], [ %180, %178 ]
%197 = load i32, i32* @stderr
%198 = call i32 (i32, i8*, ...) @fprintf(i32 %197, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.8, i64 0, i64 0))
br label %199
199: ; preds = %195, %182
%200 = phi i32 [ %196, %195 ], [ %180, %182 ]
%201 = call i32 @close(i32 %95)
%202 = call i32 @close(i32 %126)
br i1 %92, label %93, label %203
203: ; preds = %199
%204 = call i32 @close(i32 %69)
ret i32 0
}