#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_SET;
int close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ generate_random_address(int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ print_global_performance(double, int, int);
int /*<<< orphan*/ printf(char *, double, ...);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int system(char *);
int measure_random_buffered_read(const char *testfile_name, int request_size,
                                 int requests_number, int limit) {
  ssize_t bytes_read, local_request_size, local_requests_number, total_size = 0;
  int i, testfile_descriptor;
  struct timeval start_timer;
  struct timeval stop_timer;
  double time_elapsed;
  double total_time_elapsed = 0;
  char *buff;
  off_t offset;
  if ((local_request_size = request_size * 1024 * sizeof(char)) <= 0)
    local_request_size = 64 * 1024 * sizeof(char);
  if ((local_requests_number = requests_number) <= 0)
    local_requests_number = 50;
  testfile_descriptor = open(testfile_name, O_RDONLY);
  if (testfile_descriptor < 0) {
    perror("open");
    return (EXIT_FAILURE);
  }
  buff = (char *)malloc(local_request_size);
  for (i = 0; i < requests_number; i++) {
    offset = generate_random_address(limit);
    gettimeofday(&start_timer, NULL);
    if ((lseek(testfile_descriptor, offset, SEEK_SET)) < 0) {
      perror("lseek");
      free(buff);
      close(testfile_descriptor);
      return (EXIT_FAILURE);
    }
    bytes_read = read(testfile_descriptor, buff, local_request_size);
    gettimeofday(&stop_timer, NULL);
    if (bytes_read > 0) {
      time_elapsed = (stop_timer.tv_sec - start_timer.tv_sec) * 1000.0;
      time_elapsed += (stop_timer.tv_usec - start_timer.tv_usec) / 1000.0;
      total_time_elapsed += time_elapsed;
      total_size += bytes_read;
      printf("%d\t%f\n", i, time_elapsed);
      if (bytes_read < local_request_size)
        break;
    } else {
      perror("read");
      fprintf(stderr, "Reading problem, abandoning reading measurment\n");
      break;
    }
  }
  gettimeofday(&start_timer, NULL);
  if (close(testfile_descriptor) == -1) {
    perror("close");
    free(buff);
    return EXIT_FAILURE;
  }
  gettimeofday(&stop_timer, NULL);
  time_elapsed = (stop_timer.tv_sec - start_timer.tv_sec) * 1000.0;
  time_elapsed += (stop_timer.tv_usec - start_timer.tv_usec) / 1000.0;
  printf("#close %f\n", time_elapsed);
  total_time_elapsed += time_elapsed;
  gettimeofday(&start_timer, NULL);
  if (system("umount /mnt/flash") == -1) {
    perror("system");
    free(buff);
    return EXIT_FAILURE;
  }
  gettimeofday(&stop_timer, NULL);
  time_elapsed = (stop_timer.tv_sec - start_timer.tv_sec) * 1000.0;
  time_elapsed += (stop_timer.tv_usec - start_timer.tv_usec) / 1000.0;
  printf("#umount %f\n", time_elapsed);
  total_time_elapsed += time_elapsed;
  printf("#total_size %d Bytes\n", (int)total_size);
  printf("#total_time_elapsed %f ms\n", total_time_elapsed);
  print_global_performance(total_time_elapsed, total_size, request_size);
  free(buff);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<measure_random_buffered_read>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0x0,-0x2c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
cltq
shl    $0x0,%rax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jg     1216 <measure_random_buffered_read+0x46>
movl   $0x10000,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
jg     122c <measure_random_buffered_read+0x5c>
movl   $0x32,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2db1(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jge    1268 <measure_random_buffered_read+0x98>
lea    0xdb6(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1579 <measure_random_buffered_read+0x3a9>
mov    -0x24(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x70(%rbp)
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    13ce <measure_random_buffered_read+0x1fe>
mov    -0x1c(%rbp),%edi
call   1060 <generate_random_address@plt>
mov    %eax,-0x74(%rbp)
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x34(%rbp),%edi
mov    -0x74(%rbp),%esi
mov    0x2d24(%rip),%rax
mov    (%rax),%edx
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    12eb <measure_random_buffered_read+0x11b>
lea    0xd49(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    -0x34(%rbp),%edi
call   1090 <close@plt>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1579 <measure_random_buffered_read+0x3a9>
mov    -0x34(%rbp),%edi
mov    -0x70(%rbp),%rsi
mov    -0x24(%rbp),%edx
call   10a0 <read@plt>
mov    %eax,-0x20(%rbp)
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
cmpl   $0x0,-0x20(%rbp)
jle    1395 <measure_random_buffered_read+0x1c5>
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  0xcda(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xcbf(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x20(%rbp),%eax
add    -0x2c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
cvtsi2sdl -0x30(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm1
lea    0xc9b(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1390 <measure_random_buffered_read+0x1c0>
jmp    13ce <measure_random_buffered_read+0x1fe>
jmp    13bb <measure_random_buffered_read+0x1eb>
lea    0xc7e(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c30(%rip),%rax
mov    (%rax),%edi
lea    0xc6e(%rip),%rsi
call   10b0 <fprintf@plt>
jmp    13ce <measure_random_buffered_read+0x1fe>
jmp    13c0 <measure_random_buffered_read+0x1f0>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    127b <measure_random_buffered_read+0xab>
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
mov    -0x34(%rbp),%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
jne    1412 <measure_random_buffered_read+0x242>
lea    0xc5c(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    0x2bc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1579 <measure_random_buffered_read+0x3a9>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  0xbcf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xbb4(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xbef(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
lea    -0x48(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
lea    0xbd0(%rip),%rdi
call   1040 <system@plt>
cmp    $0xffffffff,%eax
jne    14c4 <measure_random_buffered_read+0x2f4>
lea    0xbcd(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    0x2b0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1579 <measure_random_buffered_read+0x3a9>
lea    -0x58(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1080 <gettimeofday@plt>
movsd  -0x58(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
movsd  0xb1d(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  0xb02(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
lea    0xb61(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
cvtsi2sdl -0x2c(%rbp),%xmm0
lea    0xb4b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x68(%rbp),%xmm0
lea    0xb4e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x68(%rbp),%xmm0
mov    -0x2c(%rbp),%edi
mov    -0x14(%rbp),%esi
call   10f0 <print_global_performance@plt>
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure_random_buffered_read>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,0x8(%rsp)
mov    %edx,%ebp
mov    %esi,%ebx
mov    %esi,%eax
shl    $0xa,%eax
test   %esi,%esi
mov    $0x10000,%r14d
cmovg  %eax,%r14d
mov    0x2dea(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
test   %eax,%eax
js     1320 <measure_random_buffered_read+0x150>
mov    %eax,%r15d
mov    %ebx,0x44(%rsp)
mov    %r14d,%edi
call   10c0 <malloc@plt>
mov    %rax,0x18(%rsp)
test   %ebp,%ebp
jle    1311 <measure_random_buffered_read+0x141>
add    $0xffffffff,%ebp
xor    %r12d,%r12d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %r13d,%r13d
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
call   1060 <generate_random_address@plt>
mov    %eax,%ebx
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %ebx,%esi
call   1070 <lseek@plt>
test   %rax,%rax
js     1338 <measure_random_buffered_read+0x168>
mov    %r15d,%ebx
mov    %r15d,%edi
mov    0x18(%rsp),%rsi
mov    %r14d,%edx
call   10a0 <read@plt>
mov    %eax,%r15d
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
test   %r15d,%r15d
jle    1362 <measure_random_buffered_read+0x192>
movsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
subsd  0x30(%rsp),%xmm0
movsd  0xd48(%rip),%xmm2
mulsd  %xmm2,%xmm0
subsd  0x38(%rsp),%xmm1
divsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
add    %r15d,%r12d
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
lea    0xd27(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
cmp    %r14d,%r15d
jl     1383 <measure_random_buffered_read+0x1b3>
lea    0x1(%r13),%eax
cmp    %r13d,%ebp
mov    %eax,%r13d
mov    %ebx,%r15d
jne    1240 <measure_random_buffered_read+0x70>
jmp    1386 <measure_random_buffered_read+0x1b6>
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %r12d,%r12d
jmp    1386 <measure_random_buffered_read+0x1b6>
lea    0xce1(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c95(%rip),%rax
jmp    14cd <measure_random_buffered_read+0x2fd>
lea    0xcce(%rip),%rdi
call   10e0 <perror@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    %r15d,%edi
call   1090 <close@plt>
mov    0x2c6b(%rip),%rax
jmp    14cd <measure_random_buffered_read+0x2fd>
lea    0xcb1(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c63(%rip),%rax
mov    (%rax),%edi
lea    0xca1(%rip),%rsi
call   10b0 <fprintf@plt>
mov    %ebx,%r15d
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
mov    %r15d,%edi
call   1090 <close@plt>
cmp    $0xffffffff,%eax
je     14de <measure_random_buffered_read+0x30e>
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm0
subsd  0x30(%rsp),%xmm2
movsd  0xc37(%rip),%xmm1
mulsd  %xmm1,%xmm2
subsd  0x38(%rsp),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
lea    0xc73(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
mov    $0x1,%al
call   1050 <printf@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
lea    0xc5e(%rip),%rdi
call   1040 <system@plt>
cmp    $0xffffffff,%eax
je     14e7 <measure_random_buffered_read+0x317>
movsd  0x10(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0x20(%rsp),%rdi
xor    %esi,%esi
call   1080 <gettimeofday@plt>
movsd  0x20(%rsp),%xmm2
movsd  0x28(%rsp),%xmm0
subsd  0x30(%rsp),%xmm2
movsd  0xbb8(%rip),%xmm1
mulsd  %xmm1,%xmm2
subsd  0x38(%rsp),%xmm0
divsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
lea    0xc12(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
lea    0xbf6(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xbfe(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
mov    %r12d,%edi
mov    0x44(%rsp),%esi
call   10f0 <print_global_performance@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x2af3(%rip),%rax
mov    (%rax),%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xb6a(%rip),%rdi
jmp    14ee <measure_random_buffered_read+0x31e>
lea    0xb84(%rip),%rdi
call   10e0 <perror@plt>
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x2ac4(%rip),%rax
jmp    14cd <measure_random_buffered_read+0x2fd>

LLVM IR (-O0):
%struct.timeval = type { double, double }
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [7 x i8] c"%d\09%f\0A\00"
@.str.3 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.4 = [48 x i8] c"Reading problem, abandoning reading measurment\0A\00"
@.str.5 = [6 x i8] c"close\00"
@.str.6 = [11 x i8] c"#close %f\0A\00"
@.str.7 = [18 x i8] c"umount /mnt/flash\00"
@.str.8 = [7 x i8] c"system\00"
@.str.9 = [12 x i8] c"#umount %f\0A\00"
@.str.10 = [22 x i8] c"#total_size %d Bytes\0A\00"
@.str.11 = [27 x i8] c"#total_time_elapsed %f ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @measure_random_buffered_read(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.timeval
%17 = alloca %struct.timeval
%18 = alloca double
%19 = alloca double
%20 = alloca i8*
%21 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %13
store double 0.000000e+00, double* %19
%22 = load i32, i32* %7
%23 = mul nsw i32 %22, 1024
%24 = sext i32 %23 to i64
%25 = mul i64 %24, 1
%26 = trunc i64 %25 to i32
store i32 %26, i32* %11
%27 = icmp sle i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %4
store i32 65536, i32* %11
br label %29
29: ; preds = %28, %4
%30 = load i32, i32* %8
store i32 %30, i32* %12
%31 = icmp sle i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %29
store i32 50, i32* %12
br label %33
33: ; preds = %32, %29
%34 = load i8*, i8** %6
%35 = load i32, i32* @O_RDONLY
%36 = call i32 @open(i8* %34, i32 %35)
store i32 %36, i32* %15
%37 = load i32, i32* %15
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @EXIT_FAILURE
store i32 %41, i32* %5
br label %184
42: ; preds = %33
%43 = load i32, i32* %11
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to i8*
store i8* %45, i8** %20
store i32 0, i32* %14
br label %46
46: ; preds = %109, %42
%47 = load i32, i32* %14
%48 = load i32, i32* %8
%49 = icmp slt i32 %47, %48
br i1 %49, label %50, label %112
50: ; preds = %46
%51 = load i32, i32* %9
%52 = call i32 @generate_random_address(i32 %51)
store i32 %52, i32* %21
%53 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%54 = load i32, i32* %15
%55 = load i32, i32* %21
%56 = load i32, i32* @SEEK_SET
%57 = call i64 @lseek(i32 %54, i32 %55, i32 %56)
%58 = icmp slt i64 %57, 0
br i1 %58, label %59, label %66
59: ; preds = %50
%60 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%61 = load i8*, i8** %20
%62 = call i32 @free(i8* %61)
%63 = load i32, i32* %15
%64 = call i32 @close(i32 %63)
%65 = load i32, i32* @EXIT_FAILURE
store i32 %65, i32* %5
br label %184
66: ; preds = %50
%67 = load i32, i32* %15
%68 = load i8*, i8** %20
%69 = load i32, i32* %11
%70 = call i32 @read(i32 %67, i8* %68, i32 %69)
store i32 %70, i32* %10
%71 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%72 = load i32, i32* %10
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %104
74: ; preds = %66
%75 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%76 = load double, double* %75
%77 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%78 = load double, double* %77
%79 = fsub double %76, %78
%80 = fmul double %79, 1.000000e+03
store double %80, double* %18
%81 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%82 = load double, double* %81
%83 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%84 = load double, double* %83
%85 = fsub double %82, %84
%86 = fdiv double %85, 1.000000e+03
%87 = load double, double* %18
%88 = fadd double %87, %86
store double %88, double* %18
%89 = load double, double* %18
%90 = load double, double* %19
%91 = fadd double %90, %89
store double %91, double* %19
%92 = load i32, i32* %10
%93 = load i32, i32* %13
%94 = add nsw i32 %93, %92
store i32 %94, i32* %13
%95 = load i32, i32* %14
%96 = sitofp i32 %95 to double
%97 = load double, double* %18
%98 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %96, double %97)
%99 = load i32, i32* %10
%100 = load i32, i32* %11
%101 = icmp slt i32 %99, %100
br i1 %101, label %102, label %103
102: ; preds = %74
br label %112
103: ; preds = %74
br label %108
104: ; preds = %66
%105 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%106 = load i32, i32* @stderr
%107 = call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
br label %112
108: ; preds = %103
br label %109
109: ; preds = %108
%110 = load i32, i32* %14
%111 = add nsw i32 %110, 1
store i32 %111, i32* %14
br label %46
112: ; preds = %104, %102, %46
%113 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%114 = load i32, i32* %15
%115 = call i32 @close(i32 %114)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %122
117: ; preds = %112
%118 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%119 = load i8*, i8** %20
%120 = call i32 @free(i8* %119)
%121 = load i32, i32* @EXIT_FAILURE
store i32 %121, i32* %5
br label %184
122: ; preds = %112
%123 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%124 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%125 = load double, double* %124
%126 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%127 = load double, double* %126
%128 = fsub double %125, %127
%129 = fmul double %128, 1.000000e+03
store double %129, double* %18
%130 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%131 = load double, double* %130
%132 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%133 = load double, double* %132
%134 = fsub double %131, %133
%135 = fdiv double %134, 1.000000e+03
%136 = load double, double* %18
%137 = fadd double %136, %135
store double %137, double* %18
%138 = load double, double* %18
%139 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), double %138)
%140 = load double, double* %18
%141 = load double, double* %19
%142 = fadd double %141, %140
store double %142, double* %19
%143 = call i32 @gettimeofday(%struct.timeval* %16, i32* null)
%144 = call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%145 = icmp eq i32 %144, -1
br i1 %145, label %146, label %151
146: ; preds = %122
%147 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%148 = load i8*, i8** %20
%149 = call i32 @free(i8* %148)
%150 = load i32, i32* @EXIT_FAILURE
store i32 %150, i32* %5
br label %184
151: ; preds = %122
%152 = call i32 @gettimeofday(%struct.timeval* %17, i32* null)
%153 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%154 = load double, double* %153
%155 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%156 = load double, double* %155
%157 = fsub double %154, %156
%158 = fmul double %157, 1.000000e+03
store double %158, double* %18
%159 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%160 = load double, double* %159
%161 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%162 = load double, double* %161
%163 = fsub double %160, %162
%164 = fdiv double %163, 1.000000e+03
%165 = load double, double* %18
%166 = fadd double %165, %164
store double %166, double* %18
%167 = load double, double* %18
%168 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %167)
%169 = load double, double* %18
%170 = load double, double* %19
%171 = fadd double %170, %169
store double %171, double* %19
%172 = load i32, i32* %13
%173 = sitofp i32 %172 to double
%174 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), double %173)
%175 = load double, double* %19
%176 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), double %175)
%177 = load double, double* %19
%178 = load i32, i32* %13
%179 = load i32, i32* %7
%180 = call i32 @print_global_performance(double %177, i32 %178, i32 %179)
%181 = load i8*, i8** %20
%182 = call i32 @free(i8* %181)
%183 = load i32, i32* @EXIT_SUCCESS
store i32 %183, i32* %5
br label %184
184: ; preds = %151, %146, %117, %59, %39
%185 = load i32, i32* %5
ret i32 %185
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@O_RDONLY = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [6 x i8] c"lseek\00"
@.str.2 = [7 x i8] c"%d\09%f\0A\00"
@.str.3 = [5 x i8] c"read\00"
@stderr = global i32 0
@.str.4 = [48 x i8] c"Reading problem, abandoning reading measurment\0A\00"
@.str.5 = [6 x i8] c"close\00"
@.str.6 = [11 x i8] c"#close %f\0A\00"
@.str.7 = [18 x i8] c"umount /mnt/flash\00"
@.str.8 = [7 x i8] c"system\00"
@.str.9 = [12 x i8] c"#umount %f\0A\00"
@.str.10 = [22 x i8] c"#total_size %d Bytes\0A\00"
@.str.11 = [27 x i8] c"#total_time_elapsed %f ms\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @measure_random_buffered_read(i8* nocapture %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = bitcast %struct.timeval* %5 to i8*
%8 = bitcast %struct.timeval* %6 to i8*
%9 = shl nsw i32 %1, 10
%10 = icmp slt i32 %1, 1
%11 = select i1 %10, i32 65536, i32 %9
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %0, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %4
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %115
17: ; preds = %4
%18 = tail call i64 @malloc(i32 %11)
%19 = inttoptr i64 %18 to i8*
%20 = icmp sgt i32 %2, 0
br i1 %20, label %21, label %65
21: ; preds = %17
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
br label %26
26: ; preds = %43, %21
%27 = phi double [ 0.000000e+00, %21 ], [ %53, %43 ]
%28 = phi i32 [ 0, %21 ], [ %54, %43 ]
%29 = phi i32 [ 0, %21 ], [ %58, %43 ]
%30 = tail call i32 @generate_random_address(i32 %3)
%31 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%32 = load i32, i32* @SEEK_SET
%33 = tail call i64 @lseek(i32 %13, i32 %30, i32 %32)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %26
%36 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%37 = tail call i32 @free(i8* %19)
%38 = tail call i32 @close(i32 %13)
br label %115
39: ; preds = %26
%40 = tail call i32 @read(i32 %13, i8* %19, i32 %11)
%41 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%42 = icmp sgt i32 %40, 0
br i1 %42, label %43, label %61
43: ; preds = %39
%44 = load double, double* %22
%45 = load double, double* %23
%46 = fsub double %44, %45
%47 = fmul double %46, 1.000000e+03
%48 = load double, double* %24
%49 = load double, double* %25
%50 = fsub double %48, %49
%51 = fdiv double %50, 1.000000e+03
%52 = fadd double %47, %51
%53 = fadd double %27, %52
%54 = add nsw i32 %40, %28
%55 = sitofp i32 %29 to double
%56 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %55, double %52)
%57 = icmp slt i32 %40, %11
%58 = add nuw nsw i32 %29, 1
%59 = icmp eq i32 %58, %2
%60 = select i1 %57, i1 true, i1 %59
br i1 %60, label %65, label %26
61: ; preds = %39
%62 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%63 = load i32, i32* @stderr
%64 = tail call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
br label %65
65: ; preds = %43, %17, %61
%66 = phi i32 [ %28, %61 ], [ 0, %17 ], [ %54, %43 ]
%67 = phi double [ %27, %61 ], [ 0.000000e+00, %17 ], [ %53, %43 ]
%68 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%69 = tail call i32 @close(i32 %13)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %74
71: ; preds = %65
%72 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%73 = tail call i32 @free(i8* %19)
br label %115
74: ; preds = %65
%75 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%76 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%77 = load double, double* %76
%78 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%79 = load double, double* %78
%80 = fsub double %77, %79
%81 = fmul double %80, 1.000000e+03
%82 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 1
%83 = load double, double* %82
%84 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%85 = load double, double* %84
%86 = fsub double %83, %85
%87 = fdiv double %86, 1.000000e+03
%88 = fadd double %81, %87
%89 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), double %88)
%90 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%91 = tail call i32 @system(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %96
93: ; preds = %74
%94 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
%95 = tail call i32 @free(i8* %19)
br label %115
96: ; preds = %74
%97 = fadd double %67, %88
%98 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%99 = load double, double* %76
%100 = load double, double* %78
%101 = fsub double %99, %100
%102 = fmul double %101, 1.000000e+03
%103 = load double, double* %82
%104 = load double, double* %84
%105 = fsub double %103, %104
%106 = fdiv double %105, 1.000000e+03
%107 = fadd double %102, %106
%108 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0), double %107)
%109 = fadd double %97, %107
%110 = sitofp i32 %66 to double
%111 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.10, i64 0, i64 0), double %110)
%112 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.11, i64 0, i64 0), double %109)
%113 = tail call i32 @print_global_performance(double %109, i32 %66, i32 %1)
%114 = tail call i32 @free(i8* %19)
br label %115
115: ; preds = %96, %93, %71, %35, %15
%116 = phi i32* [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %35 ], [ @EXIT_FAILURE, %71 ], [ @EXIT_FAILURE, %93 ], [ @EXIT_SUCCESS, %96 ]
%117 = load i32, i32* %116
ret i32 %117
}