#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_DGRAM;
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 open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int sendto(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*/ 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;
  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_DGRAM, 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));
  for (;;) {
    clilen = sizeof(cliaddr);
    ret = recvfrom(listenfd, sendbuf, 4096, 0, (struct sockaddr *)&cliaddr,
                   &clilen);
    if (ret <= 0) {
      fprintf(stderr, "! Fail to recv: ret:%d, err:%d; quiting..\n", ret,
              errno);
      exit(1);
    }
    if ((sendbuf[0] == '!') && (sendbuf[1] == '?') && (sendbuf[2] == '=')) {
      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 = sendto(listenfd, sendbuf,
                       (quota - sentInSlot < sendsize) ? (quota - sentInSlot)
                                                       : sendsize,
                       0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
          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);
        ret = sendto(listenfd, "=?!\n", 4, 0, (struct sockaddr *)&cliaddr,
                     sizeof(cliaddr));
        if (ret <= 0) {
          fprintf(stderr, "! Unable to initialize data transfer. errno:%d.\n",
                  errno);
          close(fd);
          close(listenfd);
          exit(1);
        }
      } else {
        fprintf(stderr, "! error: total_bytes_sent > bytes2send\n");
      }
      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    0x2d12(%rip),%rax
mov    (%rax),%edi
mov    0x2d21(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmpl   $0x3,-0x8(%rbp)
jge    12d4 <main+0x94>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd42(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
cmpl   $0x3,-0x8(%rbp)
jle    1310 <main+0xd0>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1120 <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    132d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1120 <atoi@plt>
mov    %al,-0x100a9(%rbp)
cmpl   $0x5,-0x8(%rbp)
jle    134a <main+0x10a>
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x1009c(%rbp)
mov    -0x18(%rbp),%eax
cltd
idivl  -0x1009c(%rbp)
cmp    $0x0,%edx
jle    13aa <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    0x2c37(%rip),%rax
mov    (%rax),%edi
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x68(%rbp)
lea    -0x10080(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2c0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10078(%rbp)
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x10080(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1120 <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>
movl   $0xc,-0x10094(%rbp)
mov    -0x68(%rbp),%edi
lea    -0x10070(%rbp),%rsi
lea    -0x10090(%rbp),%r8
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    -0x10094(%rbp),%r9
call   10e0 <recvfrom@plt>
mov    %eax,-0x10098(%rbp)
cmpl   $0x0,-0x10098(%rbp)
jg     1499 <main+0x259>
mov    0x2b48(%rip),%rax
mov    (%rax),%edi
mov    -0x10098(%rbp),%edx
mov    0x2b29(%rip),%rax
mov    (%rax),%ecx
lea    0xc04(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
movsbl -0x10070(%rbp),%eax
cmp    $0x21,%eax
jne    190b <main+0x6cb>
movsbl -0x1006f(%rbp),%eax
cmp    $0x3f,%eax
jne    190b <main+0x6cb>
movsbl -0x1006e(%rbp),%eax
cmp    $0x3d,%eax
jne    190b <main+0x6cb>
mov    -0x10090(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xbd9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10c0 <isNumber@plt>
cmp    $0x0,%rax
je     1557 <main+0x317>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x100a0(%rbp)
mov    0x2aca(%rip),%rax
mov    (%rax),%esi
lea    0xbaf(%rip),%rdi
call   1100 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1552 <main+0x312>
mov    0x2a80(%rip),%rax
mov    (%rax),%edi
lea    0xb97(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    15d2 <main+0x392>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2a7a(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    15a3 <main+0x363>
mov    0x2a37(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xb71(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    -0x64(%rbp),%edi
lea    -0x100a8(%rbp),%rsi
call   1140 <fstat@plt>
mov    -0x100a8(%rbp),%eax
mov    %eax,-0x100a0(%rbp)
mov    -0x100a0(%rbp),%esi
lea    0xb53(%rip),%rdi
mov    $0x0,%al
call   1050 <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   1060 <gettimeofday@plt>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jge    17f6 <main+0x5b6>
mov    -0x100a0(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1621 <main+0x3e1>
mov    -0x100a0(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    1626 <main+0x3e6>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1764 <main+0x524>
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    166c <main+0x42c>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x100c0(%rbp)
jmp    1678 <main+0x438>
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    -0x68(%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    16ca <main+0x48a>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x100d0(%rbp)
jmp    16d6 <main+0x496>
mov    -0x1009c(%rbp),%eax
mov    %eax,-0x100d0(%rbp)
mov    -0x100c8(%rbp),%rsi
mov    -0x100cc(%rbp),%edi
mov    -0x100d0(%rbp),%edx
lea    -0x10090(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x10098(%rbp)
cmpl   $0x0,-0x10098(%rbp)
jg     1747 <main+0x507>
mov    0x28a1(%rip),%rax
mov    (%rax),%edi
mov    -0x10098(%rbp),%edx
mov    0x2882(%rip),%rax
mov    (%rax),%ecx
lea    0x9fe(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x100a0(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1764 <main+0x524>
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    1626 <main+0x3e6>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jle    1778 <main+0x538>
jmp    17f6 <main+0x5b6>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x60(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0x85f(%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    17e1 <main+0x5a1>
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1150 <usleep@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    15f4 <main+0x3b4>
mov    -0x24(%rbp),%eax
cmp    -0x100a0(%rbp),%eax
jne    18d5 <main+0x695>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0x7d2(%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    0x906(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x68(%rbp),%edi
lea    -0x10090(%rbp),%r8
lea    0x922(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1080 <sendto@plt>
mov    %eax,-0x10098(%rbp)
cmpl   $0x0,-0x10098(%rbp)
jg     18d0 <main+0x690>
mov    0x271b(%rip),%rax
mov    (%rax),%edi
mov    0x2702(%rip),%rax
mov    (%rax),%edx
lea    0x8e9(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x64(%rbp),%edi
call   1090 <close@plt>
mov    -0x68(%rbp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
jmp    18ec <main+0x6ac>
mov    0x26dc(%rip),%rax
mov    (%rax),%edi
lea    0x8e4(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    -0x64(%rbp),%edi
call   1090 <close@plt>
cmpb   $0x0,-0x100a9(%rbp)
je     1906 <main+0x6c6>
jmp    1910 <main+0x6d0>
jmp    190b <main+0x6cb>
jmp    1428 <main+0x1e8>
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,%r12
mov    %edi,%r14d
mov    0x2d52(%rip),%rax
mov    (%rax),%edi
mov    0x2d61(%rip),%rax
mov    (%rax),%esi
call   10b0 <signal@plt>
cmp    $0x2,%r14d
jle    17bd <main+0x57d>
mov    $0x5b4,%ebp
cmp    $0x3,%r14d
jne    128a <main+0x4a>
mov    $0x3b9aca00,%ebx
jmp    12d2 <main+0x92>
mov    0x18(%r12),%rdi
call   1120 <atoi@plt>
cltq
imul   $0x51eb851f,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x28,%rbx
add    %eax,%ebx
cmp    $0x5,%r14d
jb     12d2 <main+0x92>
mov    0x20(%r12),%rdi
call   1120 <atoi@plt>
mov    %eax,0x14(%rsp)
cmp    $0x5,%r14d
je     12da <main+0x9a>
mov    0x28(%r12),%rdi
call   1120 <atoi@plt>
mov    %eax,%ebp
jmp    12da <main+0x9a>
movl   $0x0,0x14(%rsp)
mov    %ebx,%eax
cltd
idiv   %ebp
test   %edx,%edx
jle    1311 <main+0xd1>
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
cvtsi2sd %ebp,%xmm1
cvtsi2sd %ebx,%xmm2
mulsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
mulsd  0xcfe(%rip),%xmm1
cvttsd2si %xmm1,%ecx
mov    %ecx,0x1c(%rsp)
imul   %ebp,%eax
mov    %eax,%ebx
jmp    1319 <main+0xd9>
movl   $0x2710,0x1c(%rsp)
mov    0x2cc8(%rip),%r15
mov    (%r15),%edi
mov    0x2ca6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x48(%rsp)
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,0x40(%rsp)
mov    0x8(%r12),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x44(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
movl   $0xc,0x18(%rsp)
lea    0xa0(%rsp),%rsi
lea    0x30(%rsp),%r8
lea    0x18(%rsp),%r9
mov    %r13d,0xc(%rsp)
mov    %r13d,%edi
mov    $0x1000,%edx
xor    %ecx,%ecx
call   10e0 <recvfrom@plt>
test   %eax,%eax
jle    1720 <main+0x4e0>
mov    0x2bf5(%rip),%r15
mov    %r12,0x20(%rsp)
jmp    1452 <main+0x212>
nopl   (%rax)
mov    0x2be1(%rip),%r15
mov    (%r15),%edi
mov    0x2bc7(%rip),%rcx
mov    (%rcx),%ecx
lea    0xd4b(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x20(%rsp),%r12
mov    %r14d,%ebp
mov    (%r15),%edi
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
cmpb   $0x0,0x14(%rsp)
jne    1703 <main+0x4c3>
movl   $0xc,0x18(%rsp)
mov    0xc(%rsp),%edi
lea    0xa0(%rsp),%rsi
mov    $0x1000,%edx
xor    %ecx,%ecx
lea    0x30(%rsp),%r8
lea    0x18(%rsp),%r9
call   10e0 <recvfrom@plt>
test   %eax,%eax
jle    1720 <main+0x4e0>
cmpb   $0x21,0xa0(%rsp)
21
jne    1420 <main+0x1e0>
cmpb   $0x3f,0xa1(%rsp)
3f
jne    1420 <main+0x1e0>
cmpb   $0x3d,0xa2(%rsp)
3d
jne    1420 <main+0x1e0>
mov    0x30(%rsp),%edi
call   1030 <inet_ntoa@plt>
lea    0xc3f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x10(%r12),%rdi
call   10c0 <isNumber@plt>
mov    0x10(%r12),%rdi
test   %rax,%rax
je     14ca <main+0x28a>
call   1120 <atoi@plt>
mov    %eax,%r14d
mov    0x2b33(%rip),%rax
mov    (%rax),%esi
lea    0xc20(%rip),%rdi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     174c <main+0x50c>
mov    %eax,0x10(%rsp)
jmp    1507 <main+0x2c7>
mov    0x2b0f(%rip),%rax
mov    (%rax),%esi
call   1100 <open@plt>
cmp    $0xffffffff,%eax
je     1767 <main+0x527>
mov    %eax,0x10(%rsp)
mov    %eax,%edi
lea    0x28(%rsp),%rsi
call   1140 <fstat@plt>
mov    0x28(%rsp),%r14d
lea    0xc29(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%r13
xor    %r12d,%r12d
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
test   %r14d,%r14d
jle    1660 <main+0x420>
movsd  0x50(%rsp),%xmm0
movsd  %xmm0,0x70(%rsp)
movsd  0x58(%rsp),%xmm0
movsd  %xmm0,0x68(%rsp)
mov    $0x1,%ebx
xor    %r12d,%r12d
mov    %r14,0x78(%rsp)
jmp    155c <main+0x31c>
nopl   0x0(%rax)
add    $0x1,%ebx
cmp    %r12d,%r14d
jle    1660 <main+0x420>
mov    %ebx,0x2c(%rsp)
mov    %r13d,%eax
mov    %r14d,%ebx
sub    %r12d,%ebx
cmp    %r13d,%ebx
cmovge %r13d,%ebx
test   %ebx,%ebx
jle    15d9 <main+0x399>
xor    %r13d,%r13d
nopw   0x0(%rax,%rax,1)
mov    %ebx,%r15d
sub    %r13d,%r15d
cmp    %ebp,%r15d
mov    %ebp,%r14d
cmovge %ebp,%r15d
mov    0x10(%rsp),%edi
lea    0xa0(%rsp),%rbp
mov    %rbp,%rsi
mov    %r15d,%edx
call   10a0 <read@plt>
mov    0xc(%rsp),%edi
mov    %rbp,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
lea    0x30(%rsp),%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
jle    13d0 <main+0x190>
add    %eax,%r12d
add    %eax,%r13d
cmp    %r13d,%ebx
mov    %r14d,%ebp
jg     1580 <main+0x340>
mov    %rbx,%r13
mov    0x78(%rsp),%r14
cmp    %r14d,%r12d
jg     1654 <main+0x414>
lea    0x80(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movsd  0x80(%rsp),%xmm0
subsd  0x70(%rsp),%xmm0
movsd  0x88(%rsp),%xmm1
subsd  0x68(%rsp),%xmm1
mulsd  0x9ed(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    0x2c(%rsp),%ebx
mov    %ebx,%eax
imul   0x1c(%rsp),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd %xmm0,%xmm1
mov    0x297c(%rip),%r15
jbe    1550 <main+0x310>
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   1150 <usleep@plt>
jmp    1550 <main+0x310>
mov    0x295d(%rip),%r15
nopl   0x0(%rax,%rax,1)
cmp    %r14d,%r12d
jne    16f6 <main+0x4b6>
lea    0x90(%rsp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
movapd 0x90(%rsp),%xmm1
subpd  0x50(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0x971(%rip),%xmm0
addsd  %xmm1,%xmm0
lea    0x0(,%r14,8),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm0,%xmm1
lea    0xab2(%rip),%rdi
mov    %r14d,%esi
mov    $0x2,%al
call   1050 <printf@plt>
mov    0xc(%rsp),%edi
lea    0xad1(%rip),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
lea    0x30(%rsp),%r8
mov    $0xc,%r9d
call   1080 <sendto@plt>
test   %eax,%eax
mov    0x20(%rsp),%r12
mov    %r13,%rbx
jg     140c <main+0x1cc>
jmp    1787 <main+0x547>
mov    0x20(%rsp),%r12
mov    %r13,%rbx
jmp    13fb <main+0x1bb>
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    0x2891(%rip),%rcx
mov    (%rcx),%edi
mov    0x2878(%rip),%rcx
mov    (%rcx),%ecx
lea    0x95b(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    (%r15),%edi
lea    0x98a(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    (%r15),%edi
mov    0x10(%r12),%rdx
lea    0x995(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    (%r15),%edi
mov    0x2817(%rip),%rax
mov    (%rax),%edx
lea    0xa06(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
mov    0xc(%rsp),%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    (%r12),%rsi
lea    0x848(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.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_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str.1 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Accepted client at %s\0A\00"
@.str.3 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.4 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.5 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.6 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.7 = [50 x i8] c"! Fail to send: ret:%d, err:%d; wait for 100us..\0A\00"
@.str.8 = [52 x i8] c"sent(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
@.str.9 = [5 x i8] c"=?!\0A\00"
@.str.10 = [49 x i8] c"! Unable to initialize data transfer. errno:%d.\0A\00"
@.str.11 = [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 [65536 x i8]
%18 = alloca %struct.sockaddr_in
%19 = alloca %struct.sockaddr_in
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca %struct.stat
%25 = 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* %22
store i32 0, i32* %23
store i8 0, i8* %25
%26 = load i32, i32* @SIGPIPE
%27 = load i32, i32* @SIG_IGN
%28 = call i32 @signal(i32 %26, i32 %27)
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 3
br i1 %30, label %31, label %37
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([132 x i8], [132 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 0)
unreachable
37: ; preds = %2
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 3
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
%45 = sdiv i32 %44, 8
%46 = load i32, i32* %6
%47 = sdiv i32 1000000, %46
%48 = sdiv i32 %45, %47
store i32 %48, i32* %7
br label %49
49: ; preds = %40, %37
%50 = load i32, i32* %4
%51 = icmp sgt i32 %50, 4
br i1 %51, label %52, label %58
52: ; preds = %49
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 4
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
%57 = trunc i32 %56 to i8
store i8 %57, i8* %25
br label %58
58: ; preds = %52, %49
%59 = load i32, i32* %4
%60 = icmp sgt i32 %59, 5
br i1 %60, label %61, label %66
61: ; preds = %58
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 5
%64 = load i8*, i8** %63
%65 = call i32 @atoi(i8* %64)
store i32 %65, i32* %22
br label %66
66: ; preds = %61, %58
%67 = load i32, i32* %7
%68 = load i32, i32* %22
%69 = srem i32 %67, %68
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %93
71: ; preds = %66
%72 = load i32, i32* %7
%73 = load i32, i32* %22
%74 = sdiv i32 %72, %73
%75 = add nsw i32 %74, 1
%76 = sitofp i32 %75 to double
%77 = load i32, i32* %22
%78 = sitofp i32 %77 to double
%79 = fmul double %76, %78
%80 = load i32, i32* %7
%81 = sitofp i32 %80 to double
%82 = fdiv double %79, %81
%83 = load i32, i32* %6
%84 = sitofp i32 %83 to double
%85 = fmul double %82, %84
%86 = fptosi double %85 to i32
store i32 %86, i32* %6
%87 = load i32, i32* %7
%88 = load i32, i32* %22
%89 = sdiv i32 %87, %88
%90 = add nsw i32 %89, 1
%91 = load i32, i32* %22
%92 = mul nsw i32 %90, %91
store i32 %92, i32* %7
br label %93
93: ; preds = %71, %66
%94 = load i32, i32* @AF_INET
%95 = load i32, i32* @SOCK_DGRAM
%96 = call i32 @socket(i32 %94, i32 %95, i32 0)
store i32 %96, i32* %16
%97 = call i32 @bzero(%struct.sockaddr_in* %18, i32 12)
%98 = load i32, i32* @AF_INET
%99 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 2
store i32 %98, i32* %99
%100 = load i32, i32* @INADDR_ANY
%101 = call i32 @htonl(i32 %100)
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%103 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %102, i32 0, i32 0
store i32 %101, i32* %103
%104 = load i8**, i8*** %5
%105 = getelementptr inbounds i8*, i8** %104, i64 1
%106 = load i8*, i8** %105
%107 = call i32 @atoi(i8* %106)
%108 = call i32 @htons(i32 %107)
%109 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 1
store i32 %108, i32* %109
%110 = load i32, i32* %16
%111 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%112 = call i32 @bind(i32 %110, %struct.sockaddr* %111, i32 12)
br label %113
113: ; preds = %346, %93
store i32 12, i32* %20
%114 = load i32, i32* %16
%115 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%116 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%117 = call i32 @recvfrom(i32 %114, i8* %115, i32 4096, i32 0, %struct.sockaddr* %116, i32* %20)
store i32 %117, i32* %21
%118 = load i32, i32* %21
%119 = icmp sle i32 %118, 0
br i1 %119, label %120, label %126
120: ; preds = %113
%121 = load i32, i32* @stderr
%122 = load i32, i32* %21
%123 = load i32, i32* @errno
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %122, i32 %123)
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %113
%127 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%128 = load i8, i8* %127
%129 = sext i8 %128 to i32
%130 = icmp eq i32 %129, 33
br i1 %130, label %131, label %346
131: ; preds = %126
%132 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 1
%133 = load i8, i8* %132
%134 = sext i8 %133 to i32
%135 = icmp eq i32 %134, 63
br i1 %135, label %136, label %346
136: ; preds = %131
%137 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 2
%138 = load i8, i8* %137
%139 = sext i8 %138 to i32
%140 = icmp eq i32 %139, 61
br i1 %140, label %141, label %346
141: ; preds = %136
%142 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%143 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %142, i32 0, i32 0
%144 = load i32, i32* %143
%145 = call i8* @inet_ntoa(i32 %144)
%146 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %145)
%147 = load i8**, i8*** %5
%148 = getelementptr inbounds i8*, i8** %147, i64 2
%149 = load i8*, i8** %148
%150 = call i64 @isNumber(i8* %149)
%151 = icmp ne i64 %150, 0
br i1 %151, label %152, label %166
152: ; preds = %141
%153 = load i8**, i8*** %5
%154 = getelementptr inbounds i8*, i8** %153, i64 2
%155 = load i8*, i8** %154
%156 = call i32 @atoi(i8* %155)
store i32 %156, i32* %23
%157 = load i32, i32* @O_RDONLY
%158 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %157)
store i32 %158, i32* %15
%159 = load i32, i32* %15
%160 = icmp eq i32 %159, -1
br i1 %160, label %161, label %165
161: ; preds = %152
%162 = load i32, i32* @stderr
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %162, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%164 = call i32 @exit(i32 1)
unreachable
165: ; preds = %152
br label %188
166: ; preds = %141
%167 = load i8**, i8*** %5
%168 = getelementptr inbounds i8*, i8** %167, i64 2
%169 = load i8*, i8** %168
%170 = load i32, i32* @O_RDONLY
%171 = call i32 @open(i8* %169, i32 %170)
store i32 %171, i32* %15
%172 = load i32, i32* %15
%173 = icmp eq i32 %172, -1
br i1 %173, label %174, label %181
174: ; preds = %166
%175 = load i32, i32* @stderr
%176 = load i8**, i8*** %5
%177 = getelementptr inbounds i8*, i8** %176, i64 2
%178 = load i8*, i8** %177
%179 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %178)
%180 = call i32 @exit(i32 1)
unreachable
181: ; preds = %166
%182 = load i32, i32* %15
%183 = call i32 @fstat(i32 %182, %struct.stat* %24)
%184 = getelementptr inbounds %struct.stat, %struct.stat* %24, i32 0, i32 0
%185 = load i32, i32* %184
store i32 %185, i32* %23
%186 = load i32, i32* %23
%187 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %186)
br label %188
188: ; preds = %181, %165
store i32 0, i32* %10
store i32 0, i32* %8
store i32 1, i32* %9
%189 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
br label %190
190: ; preds = %292, %188
%191 = load i32, i32* %10
%192 = load i32, i32* %23
%193 = icmp slt i32 %191, %192
br i1 %193, label %194, label %295
194: ; preds = %190
%195 = load i32, i32* %23
%196 = load i32, i32* %10
%197 = sub nsw i32 %195, %196
%198 = load i32, i32* %7
%199 = icmp slt i32 %197, %198
br i1 %199, label %200, label %204
200: ; preds = %194
%201 = load i32, i32* %23
%202 = load i32, i32* %10
%203 = sub nsw i32 %201, %202
store i32 %203, i32* %7
br label %204
204: ; preds = %200, %194
br label %205
205: ; preds = %252, %204
%206 = load i32, i32* %8
%207 = load i32, i32* %7
%208 = icmp slt i32 %206, %207
br i1 %208, label %209, label %259
209: ; preds = %205
%210 = load i32, i32* %15
%211 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%212 = load i32, i32* %7
%213 = load i32, i32* %8
%214 = sub nsw i32 %212, %213
%215 = load i32, i32* %22
%216 = icmp slt i32 %214, %215
br i1 %216, label %217, label %221
217: ; preds = %209
%218 = load i32, i32* %7
%219 = load i32, i32* %8
%220 = sub nsw i32 %218, %219
br label %223
221: ; preds = %209
%222 = load i32, i32* %22
br label %223
223: ; preds = %221, %217
%224 = phi i32 [ %220, %217 ], [ %222, %221 ]
%225 = call i32 @read(i32 %210, i8* %211, i32 %224)
%226 = load i32, i32* %16
%227 = getelementptr inbounds [65536 x i8], [65536 x i8]* %17, i64 0, i64 0
%228 = load i32, i32* %7
%229 = load i32, i32* %8
%230 = sub nsw i32 %228, %229
%231 = load i32, i32* %22
%232 = icmp slt i32 %230, %231
br i1 %232, label %233, label %237
233: ; preds = %223
%234 = load i32, i32* %7
%235 = load i32, i32* %8
%236 = sub nsw i32 %234, %235
br label %239
237: ; preds = %223
%238 = load i32, i32* %22
br label %239
239: ; preds = %237, %233
%240 = phi i32 [ %236, %233 ], [ %238, %237 ]
%241 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%242 = call i32 @sendto(i32 %226, i8* %227, i32 %240, i32 0, %struct.sockaddr* %241, i32 12)
store i32 %242, i32* %21
%243 = load i32, i32* %21
%244 = icmp sle i32 %243, 0
br i1 %244, label %245, label %252
245: ; preds = %239
%246 = load i32, i32* @stderr
%247 = load i32, i32* %21
%248 = load i32, i32* @errno
%249 = call i32 (i32, i8*, ...) @fprintf(i32 %246, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 %247, i32 %248)
%250 = load i32, i32* %23
%251 = add nsw i32 %250, 1
store i32 %251, i32* %10
br label %259
252: ; preds = %239
%253 = load i32, i32* %21
%254 = load i32, i32* %10
%255 = add nsw i32 %254, %253
store i32 %255, i32* %10
%256 = load i32, i32* %21
%257 = load i32, i32* %8
%258 = add nsw i32 %257, %256
store i32 %258, i32* %8
br label %205
259: ; preds = %245, %205
%260 = load i32, i32* %10
%261 = load i32, i32* %23
%262 = icmp sgt i32 %260, %261
br i1 %262, label %263, label %264
263: ; preds = %259
br label %295
264: ; preds = %259
%265 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%266 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%267 = load double, double* %266
%268 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%269 = load double, double* %268
%270 = fsub double %267, %269
%271 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%272 = load double, double* %271
%273 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%274 = load double, double* %273
%275 = fsub double %272, %274
%276 = call double @llvm.fmuladd.f64(double %270, double 1.000000e+06, double %275)
store double %276, double* %11
%277 = load double, double* %11
%278 = load i32, i32* %6
%279 = load i32, i32* %9
%280 = mul nsw i32 %278, %279
%281 = sitofp i32 %280 to double
%282 = fcmp olt double %277, %281
br i1 %282, label %283, label %292
283: ; preds = %264
%284 = load i32, i32* %6
%285 = load i32, i32* %9
%286 = mul nsw i32 %284, %285
%287 = sitofp i32 %286 to double
%288 = load double, double* %11
%289 = fsub double %287, %288
%290 = fptosi double %289 to i32
%291 = call i32 @usleep(i32 %290)
br label %292
292: ; preds = %283, %264
store i32 0, i32* %8
%293 = load i32, i32* %9
%294 = add nsw i32 %293, 1
store i32 %294, i32* %9
br label %190
295: ; preds = %263, %190
%296 = load i32, i32* %10
%297 = load i32, i32* %23
%298 = icmp eq i32 %296, %297
br i1 %298, label %299, label %336
299: ; preds = %295
%300 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%301 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%302 = load double, double* %301
%303 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%304 = load double, double* %303
%305 = fsub double %302, %304
%306 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%307 = load double, double* %306
%308 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%309 = load double, double* %308
%310 = fsub double %307, %309
%311 = fdiv double %310, 1.000000e+06
%312 = fadd double %305, %311
store double %312, double* %11
%313 = load i32, i32* %10
%314 = load double, double* %11
%315 = load i32, i32* %10
%316 = mul nsw i32 %315, 8
%317 = sitofp i32 %316 to double
%318 = load double, double* %11
%319 = fdiv double %317, %318
%320 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.8, i64 0, i64 0), i32 %313, double %314, double %319)
%321 = load i32, i32* %16
%322 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%323 = call i32 @sendto(i32 %321, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 0, %struct.sockaddr* %322, i32 12)
store i32 %323, i32* %21
%324 = load i32, i32* %21
%325 = icmp sle i32 %324, 0
br i1 %325, label %326, label %335
326: ; preds = %299
%327 = load i32, i32* @stderr
%328 = load i32, i32* @errno
%329 = call i32 (i32, i8*, ...) @fprintf(i32 %327, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i32 %328)
%330 = load i32, i32* %15
%331 = call i32 @close(i32 %330)
%332 = load i32, i32* %16
%333 = call i32 @close(i32 %332)
%334 = call i32 @exit(i32 1)
unreachable
335: ; preds = %299
br label %339
336: ; preds = %295
%337 = load i32, i32* @stderr
%338 = call i32 (i32, i8*, ...) @fprintf(i32 %337, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
br label %339
339: ; preds = %336, %335
%340 = load i32, i32* %15
%341 = call i32 @close(i32 %340)
%342 = load i8, i8* %25
%343 = icmp ne i8 %342, 0
br i1 %343, label %344, label %345
344: ; preds = %339
br label %347
345: ; preds = %339
br label %346
346: ; preds = %345, %136, %131, %126
br label %113
347: ; preds = %344
%348 = load i32, i32* %16
%349 = call i32 @close(i32 %348)
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_DGRAM = global i32 0
@INADDR_ANY = global i32 0
@stderr = global i32 0
@.str.1 = [43 x i8] c"! Fail to recv: ret:%d, err:%d; quiting..\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"Accepted client at %s\0A\00"
@.str.3 = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.4 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.5 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.6 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.7 = [50 x i8] c"! Fail to send: ret:%d, err:%d; wait for 100us..\0A\00"
@.str.8 = [52 x i8] c"sent(bytes):%d\0Aduration(s):%lf\0Athroughput(bps):%lf\0A\00"
@.str.9 = [5 x i8] c"=?!\0A\00"
@.str.10 = [49 x i8] c"! Unable to initialize data transfer. errno:%d.\0A\00"
@.str.11 = [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_DGRAM
%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 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
store i32 12, i32* %11
%84 = call i32 @recvfrom(i32 %69, i8* %16, i32 4096, i32 0, %struct.sockaddr* %83, i32* %11)
%85 = icmp slt i32 %84, 1
br i1 %85, label %97, label %86
86: ; preds = %64
%87 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 1
%88 = getelementptr inbounds [65536 x i8], [65536 x i8]* %8, i64 0, i64 2
%89 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i64 0, i32 0, i32 0
%90 = getelementptr inbounds i8*, i8** %1, i64 2
%91 = getelementptr inbounds %struct.stat, %struct.stat* %12, i64 0, i32 0
%92 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%93 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 0
%94 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 1
%95 = getelementptr inbounds <2 x double>, <2 x double>* %3, i64 0, i64 1
%96 = icmp eq i8 %48, 0
br label %103
97: ; preds = %229, %64
%98 = phi i32 [ %84, %64 ], [ %231, %229 ]
%99 = load i32, i32* @stderr
%100 = load i32, i32* @errno
%101 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %98, i32 %100)
%102 = call i32 @exit(i32 1)
unreachable
103: ; preds = %86, %229
%104 = phi i32 [ %65, %86 ], [ %230, %229 ]
%105 = load i8, i8* %16
%106 = icmp eq i8 %105, 33
%107 = load i8, i8* %87
%108 = icmp eq i8 %107, 63
%109 = select i1 %106, i1 %108, i1 false
%110 = load i8, i8* %88
%111 = icmp eq i8 %110, 61
%112 = select i1 %109, i1 %111, i1 false
br i1 %112, label %113, label %229
113: ; preds = %103
%114 = load i32, i32* %89
%115 = call i8* @inet_ntoa(i32 %114)
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %115)
%117 = load i8*, i8** %90
%118 = call i64 @isNumber(i8* %117)
%119 = icmp eq i64 %118, 0
%120 = load i8*, i8** %90
br i1 %119, label %130, label %121
121: ; preds = %113
%122 = call i32 @atoi(i8* %120)
%123 = load i32, i32* @O_RDONLY
%124 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %123)
%125 = icmp eq i32 %124, -1
br i1 %125, label %126, label %143
126: ; preds = %121
%127 = load i32, i32* @stderr
%128 = call i32 (i32, i8*, ...) @fprintf(i32 %127, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
%129 = call i32 @exit(i32 1)
unreachable
130: ; preds = %113
%131 = load i32, i32* @O_RDONLY
%132 = call i32 @open(i8* %120, i32 %131)
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %139
134: ; preds = %130
%135 = load i32, i32* @stderr
%136 = load i8*, i8** %90
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %136)
%138 = call i32 @exit(i32 1)
unreachable
139: ; preds = %130
%140 = call i32 @fstat(i32 %132, %struct.stat* %12)
%141 = load i32, i32* %91
%142 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0), i32 %141)
br label %143
143: ; preds = %121, %139
%144 = phi i32 [ %124, %121 ], [ %132, %139 ]
%145 = phi i32 [ %122, %121 ], [ %141, %139 ]
%146 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%147 = icmp sgt i32 %145, 0
br i1 %147, label %148, label %196
148: ; preds = %143
%149 = load double, double* %93
%150 = load double, double* %95
br label %151
151: ; preds = %148, %193
%152 = phi i32 [ 0, %148 ], [ %177, %193 ]
%153 = phi i32 [ 1, %148 ], [ %194, %193 ]
%154 = phi i32 [ %104, %148 ], [ %157, %193 ]
%155 = sub nsw i32 %145, %152
%156 = icmp slt i32 %155, %154
%157 = select i1 %156, i32 %155, i32 %154
%158 = icmp sgt i32 %157, 0
br i1 %158, label %159, label %176
159: ; preds = %151, %172
%160 = phi i32 [ %173, %172 ], [ %152, %151 ]
%161 = phi i32 [ %174, %172 ], [ 0, %151 ]
%162 = sub nsw i32 %157, %161
%163 = icmp slt i32 %162, %50
%164 = select i1 %163, i32 %162, i32 %50
%165 = call i32 @read(i32 %144, i8* %16, i32 %164)
%166 = call i32 @sendto(i32 %69, i8* %16, i32 %164, i32 0, %struct.sockaddr* %83, i32 12)
%167 = icmp slt i32 %166, 1
br i1 %167, label %168, label %172
168: ; preds = %159
%169 = load i32, i32* @stderr
%170 = load i32, i32* @errno
%171 = call i32 (i32, i8*, ...) @fprintf(i32 %169, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.7, i64 0, i64 0), i32 %166, i32 %170)
br label %222
172: ; preds = %159
%173 = add nsw i32 %166, %160
%174 = add nsw i32 %166, %161
%175 = icmp sgt i32 %157, %174
br i1 %175, label %159, label %176
176: ; preds = %172, %151
%177 = phi i32 [ %152, %151 ], [ %173, %172 ]
%178 = icmp sgt i32 %177, %145
br i1 %178, label %196, label %179
179: ; preds = %176
%180 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%181 = load double, double* %92
%182 = fsub double %181, %149
%183 = load double, double* %94
%184 = fsub double %183, %150
%185 = call double @llvm.fmuladd.f64(double %182, double 1.000000e+06, double %184)
%186 = mul nsw i32 %153, %66
%187 = sitofp i32 %186 to double
%188 = fcmp olt double %185, %187
br i1 %188, label %189, label %193
189: ; preds = %179
%190 = fsub double %187, %185
%191 = fptosi double %190 to i32
%192 = call i32 @usleep(i32 %191)
br label %193
193: ; preds = %189, %179
%194 = add nuw nsw i32 %153, 1
%195 = icmp sgt i32 %145, %177
br i1 %195, label %151, label %196
196: ; preds = %193, %176, %143
%197 = phi i32 [ %104, %143 ], [ %157, %176 ], [ %157, %193 ]
%198 = phi i32 [ 0, %143 ], [ %177, %176 ], [ %177, %193 ]
%199 = icmp eq i32 %198, %145
br i1 %199, label %200, label %222
200: ; preds = %196
%201 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%202 = load <2 x double>, <2 x double>* %5
%203 = load <2 x double>, <2 x double>* %3
%204 = fsub <2 x double> %202, %203
%205 = extractelement <2 x double> %204, i64 1
%206 = fdiv double %205, 1.000000e+06
%207 = extractelement <2 x double> %204, i64 0
%208 = fadd double %207, %206
%209 = shl nsw i32 %145, 3
%210 = sitofp i32 %209 to double
%211 = fdiv double %210, %208
%212 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.8, i64 0, i64 0), i32 %145, double %208, double %211)
%213 = call i32 @sendto(i32 %69, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 4, i32 0, %struct.sockaddr* %83, i32 12)
%214 = icmp slt i32 %213, 1
br i1 %214, label %215, label %226
215: ; preds = %200
%216 = load i32, i32* @stderr
%217 = load i32, i32* @errno
%218 = call i32 (i32, i8*, ...) @fprintf(i32 %216, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.10, i64 0, i64 0), i32 %217)
%219 = call i32 @close(i32 %144)
%220 = call i32 @close(i32 %69)
%221 = call i32 @exit(i32 1)
unreachable
222: ; preds = %168, %196
%223 = phi i32 [ %157, %168 ], [ %197, %196 ]
%224 = load i32, i32* @stderr
%225 = call i32 (i32, i8*, ...) @fprintf(i32 %224, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
br label %226
226: ; preds = %200, %222
%227 = phi i32 [ %197, %200 ], [ %223, %222 ]
%228 = call i32 @close(i32 %144)
br i1 %96, label %229, label %233
229: ; preds = %226, %103
%230 = phi i32 [ %227, %226 ], [ %104, %103 ]
store i32 12, i32* %11
%231 = call i32 @recvfrom(i32 %69, i8* %16, i32 4096, i32 0, %struct.sockaddr* %83, i32* %11)
%232 = icmp slt i32 %231, 1
br i1 %232, label %97, label %103
233: ; preds = %226
%234 = call i32 @close(i32 %69)
ret i32 0
}