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

/* Type definitions */
typedef int uint;
struct timeval {
  double tv_sec;
  double tv_usec;
};
struct stat {
  int st_size;
};
struct sockaddr_in {
  int dummy;
};
struct iphdr {
  int dummy;
};
struct ether_header {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int atoi(char *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ fstat(int, struct stat *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ isNumber(char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
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 sockfd;
  char sendbuf[4096];
  struct sockaddr_in servaddr;
  struct ether_header *eh = (struct ether_header *)sendbuf;
  struct iphdr *iph = (struct iphdr *)(sendbuf + sizeof(struct ether_header));
  int ret;
  int bytes2send = 0;
  struct stat st;
  if (argc < 2) {
    printf("Usage: %s <bytes2send/file2send> <[optional] bandwidth (bps)>\n",
           argv[0]);
    exit(0);
  }
  if (argc > 2)
    quota = atoi(argv[2]) / 8 / (1000000 / slotLength);
  if (isNumber(argv[1])) {
    bytes2send = atoi(argv[1]);
    fd = open("/data/local/tmp/bigfile", O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "! Unable to open /data/local/tmp/bigfile.\n");
      exit(1);
    }
  } else {
    fd = open(argv[1], O_RDONLY);
    if (fd == -1) {
      fprintf(stderr, "! Unable to open file %s.\n", argv[1]);
      exit(1);
    }
    fstat(fd, &st);
    bytes2send = st.st_size;
    printf("bytes2send:%d\n", bytes2send);
  }
  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 < 4096) ? (quota - sentInSlot) : 4096);
      ret = (quota - sentInSlot < 4096) ? (quota - sentInSlot) : 4096;
      total_bytes_sent += ret;
      sentInSlot += ret;
    }
    if (total_bytes_sent < bytes2send) {
      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;
  }
  gettimeofday(&t_end, NULL);
  elapsedTime = (t_end.tv_sec - t_start.tv_sec) +
                (t_end.tv_usec - t_start.tv_usec) / 1000000.0;
  printf("duration(s):%lf\nthroughput(bps):%lf\n", elapsedTime,
         total_bytes_sent * 8 / elapsedTime);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10c0,%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)
lea    -0x1070(%rbp),%rax
mov    %rax,-0x1080(%rbp)
lea    -0x1070(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x1088(%rbp)
movl   $0x0,-0x1090(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    123c <main+0x8c>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jle    1278 <main+0xc8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10a0 <atoi@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x109c(%rbp)
mov    $0xf4240,%eax
cltd
idivl  -0x14(%rbp)
mov    %eax,%ecx
mov    -0x109c(%rbp),%eax
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <isNumber@plt>
cmp    $0x0,%rax
je     12ea <main+0x13a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <atoi@plt>
mov    %eax,-0x1090(%rbp)
mov    0x2d3f(%rip),%rax
mov    (%rax),%esi
lea    0xd95(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    12e5 <main+0x135>
mov    0x2d0d(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1365 <main+0x1b5>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2cef(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0xffffffff,-0x64(%rbp)
jne    1336 <main+0x186>
mov    0x2cc4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x64(%rbp),%edi
lea    -0x1098(%rbp),%rsi
call   10c0 <fstat@plt>
mov    -0x1098(%rbp),%eax
mov    %eax,-0x1090(%rbp)
mov    -0x1090(%rbp),%esi
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x24(%rbp),%eax
cmp    -0x1090(%rbp),%eax
jge    14fe <main+0x34e>
mov    -0x1090(%rbp),%eax
sub    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    139f <main+0x1ef>
mov    -0x1090(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    %eax,-0x18(%rbp)
jmp    13a4 <main+0x1f4>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    146c <main+0x2bc>
mov    -0x64(%rbp),%eax
mov    %eax,-0x10ac(%rbp)
lea    -0x1070(%rbp),%rax
mov    %rax,-0x10a8(%rbp)
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x1000,%eax
jge    13e9 <main+0x239>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x10b0(%rbp)
jmp    13f9 <main+0x249>
mov    $0x1000,%eax
mov    %eax,-0x10b0(%rbp)
jmp    13f9 <main+0x249>
mov    -0x10a8(%rbp),%rsi
mov    -0x10ac(%rbp),%edi
mov    -0x10b0(%rbp),%edx
call   1060 <read@plt>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
cmp    $0x1000,%eax
jge    1433 <main+0x283>
mov    -0x18(%rbp),%eax
sub    -0x1c(%rbp),%eax
mov    %eax,-0x10b4(%rbp)
jmp    1443 <main+0x293>
mov    $0x1000,%eax
mov    %eax,-0x10b4(%rbp)
jmp    1443 <main+0x293>
mov    -0x10b4(%rbp),%eax
mov    %eax,-0x108c(%rbp)
mov    -0x108c(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x108c(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    13a4 <main+0x1f4>
mov    -0x24(%rbp),%eax
cmp    -0x1090(%rbp),%eax
jge    14e9 <main+0x339>
lea    -0x60(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x60(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xb5c(%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    14e4 <main+0x334>
mov    -0x14(%rbp),%eax
imul   -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
subsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   10d0 <usleep@plt>
jmp    14e9 <main+0x339>
movl   $0x0,-0x1c(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1372 <main+0x1c2>
lea    -0x50(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
subsd  -0x38(%rbp),%xmm1
movsd  0xad9(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x24(%rbp),%eax
shl    $0x3,%eax
cvtsi2sd %eax,%xmm1
divsd  -0x30(%rbp),%xmm1
lea    0xb65(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x10c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1068,%rsp
mov    %rsi,%rbp
cmp    $0x1,%edi
jle    13e8 <main+0x238>
mov    $0x3b9aca00,%ebx
cmp    $0x2,%edi
je     11f6 <main+0x46>
mov    0x10(%rbp),%rdi
call   10a0 <atoi@plt>
cltq
imul   $0x51eb851f,%rax,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x28,%rbx
add    %eax,%ebx
mov    0x8(%rbp),%rdi
call   1070 <isNumber@plt>
mov    0x8(%rbp),%rdi
test   %rax,%rax
je     1233 <main+0x83>
call   10a0 <atoi@plt>
mov    %eax,%r14d
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
lea    0xe27(%rip),%rdi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1401 <main+0x251>
mov    %eax,%r13d
jmp    126c <main+0xbc>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1422 <main+0x272>
mov    %eax,%r13d
mov    %rsp,%rsi
mov    %eax,%edi
call   10c0 <fstat@plt>
mov    (%rsp),%r14d
lea    0xe43(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %r15d,%r15d
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
test   %r14d,%r14d
jle    1376 <main+0x1c6>
movapd 0x20(%rsp),%xmm2
movapd %xmm2,%xmm0
unpckhpd %xmm2,%xmm0
movapd %xmm0,0x40(%rsp)
xor    %r15d,%r15d
mov    $0x1,%ebp
mov    $0x1000,%ecx
lea    0x60(%rsp),%r12
mov    %r14d,0x8(%rsp)
movapd %xmm2,0x10(%rsp)
jmp    12c8 <main+0x118>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
mov    $0x1000,%ecx
mov    %ebp,0xc(%rsp)
mov    %ebx,%eax
mov    %r14d,%ebx
sub    %r15d,%ebx
cmp    %eax,%ebx
cmovge %eax,%ebx
test   %ebx,%ebx
jle    130b <main+0x15b>
xor    %r14d,%r14d
mov    %ebx,%ebp
sub    %r14d,%ebp
cmp    $0x1000,%ebp
cmovge %ecx,%ebp
mov    %r13d,%edi
mov    %r12,%rsi
mov    %ebp,%edx
call   1060 <read@plt>
mov    $0x1000,%ecx
add    %ebp,%r15d
add    %ebp,%r14d
cmp    %r14d,%ebx
jg     12e0 <main+0x130>
mov    0x8(%rsp),%r14d
cmp    %r14d,%r15d
jge    1382 <main+0x1d2>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x30(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
subsd  %xmm2,%xmm0
subsd  0x40(%rsp),%xmm1
mulsd  0xcbb(%rip),%xmm0
addsd  %xmm1,%xmm0
mov    0xc(%rsp),%ebp
imul   $0x2710,%ebp,%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
ucomisd %xmm0,%xmm1
jbe    12c0 <main+0x110>
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%edi
call   10d0 <usleep@plt>
jmp    12c0 <main+0x110>
movapd 0x20(%rsp),%xmm0
movapd %xmm0,0x10(%rsp)
lea    0x50(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movapd 0x50(%rsp),%xmm1
subpd  0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
divsd  0xc56(%rip),%xmm0
addsd  %xmm1,%xmm0
shl    $0x3,%r15d
xorps  %xmm1,%xmm1
cvtsi2sd %r15d,%xmm1
divsd  %xmm0,%xmm1
lea    0xcef(%rip),%rdi
mov    $0x2,%al
call   1030 <printf@plt>
mov    %r13d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x1068,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%rsi
lea    0xc15(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %edi,%edi
call   10b0 <exit@plt>
mov    0x2bd0(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2baf(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rbp),%rdx
lea    0xc54(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { double, double }
%struct.sockaddr_in = type { i32 }
%struct.ether_header = type { i32 }
%struct.iphdr = type { i32 }
%struct.stat = type { i32 }
@.str = [63 x i8] c"Usage: %s <bytes2send/file2send> <[optional] bandwidth (bps)>\0A\00"
@.str.1 = [24 x i8] c"/data/local/tmp/bigfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.3 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.4 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.5 = [37 x i8] c"duration(s):%lf\0Athroughput(bps):%lf\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca 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 [4096 x i8]
%18 = alloca %struct.sockaddr_in
%19 = alloca %struct.ether_header*
%20 = alloca %struct.iphdr*
%21 = alloca i32
%22 = alloca i32
%23 = alloca %struct.stat
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
%24 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%25 = bitcast i8* %24 to %struct.ether_header*
store %struct.ether_header* %25, %struct.ether_header** %19
%26 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%27 = getelementptr inbounds i8, i8* %26, i64 4
%28 = bitcast i8* %27 to %struct.iphdr*
store %struct.iphdr* %28, %struct.iphdr** %20
store i32 0, i32* %22
%29 = load i32, i32* %4
%30 = icmp slt i32 %29, 2
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 ([63 x i8], [63 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, 2
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 2
%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 i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = call i64 @isNumber(i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %69
55: ; preds = %49
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i32 @atoi(i8* %58)
store i32 %59, i32* %22
%60 = load i32, i32* @O_RDONLY
%61 = call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %60)
store i32 %61, i32* %15
%62 = load i32, i32* %15
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %55
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %55
br label %91
69: ; preds = %49
%70 = load i8**, i8*** %5
%71 = getelementptr inbounds i8*, i8** %70, i64 1
%72 = load i8*, i8** %71
%73 = load i32, i32* @O_RDONLY
%74 = call i32 @open(i8* %72, i32 %73)
store i32 %74, i32* %15
%75 = load i32, i32* %15
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %84
77: ; preds = %69
%78 = load i32, i32* @stderr
%79 = load i8**, i8*** %5
%80 = getelementptr inbounds i8*, i8** %79, i64 1
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %81)
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %69
%85 = load i32, i32* %15
%86 = call i32 @fstat(i32 %85, %struct.stat* %23)
%87 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 0
%88 = load i32, i32* %87
store i32 %88, i32* %22
%89 = load i32, i32* %22
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %89)
br label %91
91: ; preds = %84, %68
%92 = call i32 @gettimeofday(%struct.timeval* %12, i32* null)
br label %93
93: ; preds = %177, %91
%94 = load i32, i32* %10
%95 = load i32, i32* %22
%96 = icmp slt i32 %94, %95
br i1 %96, label %97, label %180
97: ; preds = %93
%98 = load i32, i32* %22
%99 = load i32, i32* %10
%100 = sub nsw i32 %98, %99
%101 = load i32, i32* %7
%102 = icmp slt i32 %100, %101
br i1 %102, label %103, label %107
103: ; preds = %97
%104 = load i32, i32* %22
%105 = load i32, i32* %10
%106 = sub nsw i32 %104, %105
store i32 %106, i32* %7
br label %107
107: ; preds = %103, %97
br label %108
108: ; preds = %136, %107
%109 = load i32, i32* %8
%110 = load i32, i32* %7
%111 = icmp slt i32 %109, %110
br i1 %111, label %112, label %144
112: ; preds = %108
%113 = load i32, i32* %15
%114 = getelementptr inbounds [4096 x i8], [4096 x i8]* %17, i64 0, i64 0
%115 = load i32, i32* %7
%116 = load i32, i32* %8
%117 = sub nsw i32 %115, %116
%118 = icmp slt i32 %117, 4096
br i1 %118, label %119, label %123
119: ; preds = %112
%120 = load i32, i32* %7
%121 = load i32, i32* %8
%122 = sub nsw i32 %120, %121
br label %124
123: ; preds = %112
br label %124
124: ; preds = %123, %119
%125 = phi i32 [ %122, %119 ], [ 4096, %123 ]
%126 = call i32 @read(i32 %113, i8* %114, i32 %125)
%127 = load i32, i32* %7
%128 = load i32, i32* %8
%129 = sub nsw i32 %127, %128
%130 = icmp slt i32 %129, 4096
br i1 %130, label %131, label %135
131: ; preds = %124
%132 = load i32, i32* %7
%133 = load i32, i32* %8
%134 = sub nsw i32 %132, %133
br label %136
135: ; preds = %124
br label %136
136: ; preds = %135, %131
%137 = phi i32 [ %134, %131 ], [ 4096, %135 ]
store i32 %137, i32* %21
%138 = load i32, i32* %21
%139 = load i32, i32* %10
%140 = add nsw i32 %139, %138
store i32 %140, i32* %10
%141 = load i32, i32* %21
%142 = load i32, i32* %8
%143 = add nsw i32 %142, %141
store i32 %143, i32* %8
br label %108
144: ; preds = %108
%145 = load i32, i32* %10
%146 = load i32, i32* %22
%147 = icmp slt i32 %145, %146
br i1 %147, label %148, label %177
148: ; preds = %144
%149 = call i32 @gettimeofday(%struct.timeval* %14, i32* null)
%150 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%151 = load double, double* %150
%152 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%153 = load double, double* %152
%154 = fsub double %151, %153
%155 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%156 = load double, double* %155
%157 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%158 = load double, double* %157
%159 = fsub double %156, %158
%160 = call double @llvm.fmuladd.f64(double %154, double 1.000000e+06, double %159)
store double %160, double* %11
%161 = load double, double* %11
%162 = load i32, i32* %6
%163 = load i32, i32* %9
%164 = mul nsw i32 %162, %163
%165 = sitofp i32 %164 to double
%166 = fcmp olt double %161, %165
br i1 %166, label %167, label %176
167: ; preds = %148
%168 = load i32, i32* %6
%169 = load i32, i32* %9
%170 = mul nsw i32 %168, %169
%171 = sitofp i32 %170 to double
%172 = load double, double* %11
%173 = fsub double %171, %172
%174 = fptosi double %173 to i32
%175 = call i32 @usleep(i32 %174)
br label %176
176: ; preds = %167, %148
br label %177
177: ; preds = %176, %144
store i32 0, i32* %8
%178 = load i32, i32* %9
%179 = add nsw i32 %178, 1
store i32 %179, i32* %9
br label %93
180: ; preds = %93
%181 = call i32 @gettimeofday(%struct.timeval* %13, i32* null)
%182 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%183 = load double, double* %182
%184 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 0
%185 = load double, double* %184
%186 = fsub double %183, %185
%187 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%188 = load double, double* %187
%189 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%190 = load double, double* %189
%191 = fsub double %188, %190
%192 = fdiv double %191, 1.000000e+06
%193 = fadd double %186, %192
store double %193, double* %11
%194 = load double, double* %11
%195 = load i32, i32* %10
%196 = mul nsw i32 %195, 8
%197 = sitofp i32 %196 to double
%198 = load double, double* %11
%199 = fdiv double %197, %198
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), double %194, double %199)
%201 = load i32, i32* %15
%202 = call i32 @close(i32 %201)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
%struct.stat = type { i32 }
@.str = [63 x i8] c"Usage: %s <bytes2send/file2send> <[optional] bandwidth (bps)>\0A\00"
@.str.1 = [24 x i8] c"/data/local/tmp/bigfile\00"
@O_RDONLY = global i32 0
@stderr = global i32 0
@.str.2 = [43 x i8] c"! Unable to open /data/local/tmp/bigfile.\0A\00"
@.str.3 = [27 x i8] c"! Unable to open file %s.\0A\00"
@.str.4 = [15 x i8] c"bytes2send:%d\0A\00"
@.str.5 = [37 x i8] c"duration(s):%lf\0Athroughput(bps):%lf\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca <2 x double>
%4 = bitcast <2 x double>* %3 to %struct.timeval*
%5 = alloca <2 x double>
%6 = alloca %struct.timeval
%7 = alloca [4096 x i8]
%8 = alloca %struct.stat
%9 = bitcast <2 x double>* %3 to i8*
%10 = bitcast <2 x double>* %5 to i8*
%11 = bitcast %struct.timeval* %6 to i8*
%12 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%13 = bitcast %struct.stat* %8 to i8*
%14 = icmp slt i32 %0, 2
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** %1
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = icmp eq i32 %0, 2
br i1 %20, label %26, label %21
21: ; preds = %19
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = tail call i32 @atoi(i8* %23)
%25 = sdiv i32 %24, 800
br label %26
26: ; preds = %21, %19
%27 = phi i32 [ %25, %21 ], [ 1000000000, %19 ]
%28 = getelementptr inbounds i8*, i8** %1, i64 1
%29 = load i8*, i8** %28
%30 = tail call i64 @isNumber(i8* %29)
%31 = icmp eq i64 %30, 0
%32 = load i8*, i8** %28
br i1 %31, label %42, label %33
33: ; preds = %26
%34 = tail call i32 @atoi(i8* %32)
%35 = load i32, i32* @O_RDONLY
%36 = tail call i32 @open(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %56
38: ; preds = %33
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0))
%41 = tail call i32 @exit(i32 1)
unreachable
42: ; preds = %26
%43 = load i32, i32* @O_RDONLY
%44 = tail call i32 @open(i8* %32, i32 %43)
%45 = icmp eq i32 %44, -1
br i1 %45, label %46, label %51
46: ; preds = %42
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %28
%49 = tail call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %48)
%50 = tail call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = call i32 @fstat(i32 %44, %struct.stat* %8)
%53 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%54 = load i32, i32* %53
%55 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i32 %54)
br label %56
56: ; preds = %33, %51
%57 = phi i32 [ %36, %33 ], [ %44, %51 ]
%58 = phi i32 [ %34, %33 ], [ %54, %51 ]
%59 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%60 = icmp sgt i32 %58, 0
br i1 %60, label %63, label %61
61: ; preds = %56
%62 = load <2 x double>, <2 x double>* %3
br label %106
63: ; preds = %56
%64 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%65 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%66 = load <2 x double>, <2 x double>* %3
%67 = extractelement <2 x double> %66, i64 0
%68 = extractelement <2 x double> %66, i64 1
br label %69
69: ; preds = %104, %63
%70 = phi i32 [ %27, %63 ], [ %75, %104 ]
%71 = phi i32 [ 1, %63 ], [ %105, %104 ]
%72 = phi i32 [ 0, %63 ], [ %88, %104 ]
%73 = sub nsw i32 %58, %72
%74 = icmp slt i32 %73, %70
%75 = select i1 %74, i32 %73, i32 %70
%76 = icmp sgt i32 %75, 0
br i1 %76, label %77, label %87
77: ; preds = %69, %77
%78 = phi i32 [ %85, %77 ], [ 0, %69 ]
%79 = phi i32 [ %84, %77 ], [ %72, %69 ]
%80 = sub nsw i32 %75, %78
%81 = icmp slt i32 %80, 4096
%82 = select i1 %81, i32 %80, i32 4096
%83 = call i32 @read(i32 %57, i8* %12, i32 %82)
%84 = add nsw i32 %82, %79
%85 = add nsw i32 %82, %78
%86 = icmp sgt i32 %75, %85
br i1 %86, label %77, label %87
87: ; preds = %77, %69
%88 = phi i32 [ %72, %69 ], [ %84, %77 ]
%89 = icmp slt i32 %88, %58
br i1 %89, label %90, label %106
90: ; preds = %87
%91 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%92 = load double, double* %64
%93 = fsub double %92, %67
%94 = load double, double* %65
%95 = fsub double %94, %68
%96 = tail call double @llvm.fmuladd.f64(double %93, double 1.000000e+06, double %95)
%97 = mul nsw i32 %71, 10000
%98 = sitofp i32 %97 to double
%99 = fcmp olt double %96, %98
br i1 %99, label %100, label %104
100: ; preds = %90
%101 = fsub double %98, %96
%102 = fptosi double %101 to i32
%103 = tail call i32 @usleep(i32 %102)
br label %104
104: ; preds = %90, %100
%105 = add nuw nsw i32 %71, 1
br label %69
106: ; preds = %87, %61
%107 = phi i32 [ 0, %61 ], [ %88, %87 ]
%108 = phi <2 x double> [ %62, %61 ], [ %66, %87 ]
%109 = bitcast <2 x double>* %5 to %struct.timeval*
%110 = call i32 @gettimeofday(%struct.timeval* %109, i32* null)
%111 = load <2 x double>, <2 x double>* %5
%112 = fsub <2 x double> %111, %108
%113 = extractelement <2 x double> %112, i64 1
%114 = fdiv double %113, 1.000000e+06
%115 = extractelement <2 x double> %112, i64 0
%116 = fadd double %115, %114
%117 = shl nsw i32 %107, 3
%118 = sitofp i32 %117 to double
%119 = fdiv double %118, %116
%120 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), double %116, double %119)
%121 = tail call i32 @close(i32 %57)
ret i32 0
}