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

/* Variables and functions */
int /*<<< orphan*/ free(char *);
double gettime();
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int rand32();
int /*<<< orphan*/ random_dual_read_test(char *, int, int);
int /*<<< orphan*/ random_read_test(char *, int, int);
double sqrt(double);
int latency_bench(int size, int count, int use_hugepage) {
  double t, t2, t_before, t_after, t_noaccess, t_noaccess2;
  double xs, xs0, xs1, xs2;
  double ys, ys0, ys1, ys2;
  double min_t, min_t2;
  int nbits, n;
  char *buffer, *buffer_alloc;
  if (use_hugepage)
    return 0;
  buffer_alloc = (char *)malloc(size + 4095);
  if (!buffer_alloc)
    return 0;
  buffer = (char *)(((uintptr_t)buffer_alloc + 4095) & ~(uintptr_t)4095);
  memset(buffer, 0, size);
  for (n = 1; n <= 10; n++) {
    t_before = gettime();
    random_read_test(buffer, count, 1);
    t_after = gettime();
    if (n == 1 || t_after - t_before < t_noaccess)
      t_noaccess = t_after - t_before;
    t_before = gettime();
    random_dual_read_test(buffer, count, 1);
    t_after = gettime();
    if (n == 1 || t_after - t_before < t_noaccess2)
      t_noaccess2 = t_after - t_before;
  }
  printf("\nblock size : single random read / dual random read");
  if (use_hugepage > 0)
    printf(", [MADV_HUGEPAGE]\n");
  else if (use_hugepage < 0)
    printf(", [MADV_NOHUGEPAGE]\n");
  else
    printf("\n");
  for (nbits = 10; (1 << nbits) <= size; nbits++) {
    int testsize = 1 << nbits;
    xs1 = xs2 = ys = ys1 = ys2 = 0;
    for (n = 1; n <= 10; n++) {
      int testoffs = (rand32() % (size / testsize)) * testsize;
      t_before = gettime();
      random_read_test(buffer + testoffs, count, nbits);
      t_after = gettime();
      t = t_after - t_before - t_noaccess;
      if (t < 0)
        t = 0;
      xs1 += t;
      xs2 += t * t;
      if (n == 1 || t < min_t)
        min_t = t;
      t_before = gettime();
      random_dual_read_test(buffer + testoffs, count, nbits);
      t_after = gettime();
      t2 = t_after - t_before - t_noaccess2;
      if (t2 < 0)
        t2 = 0;
      ys1 += t2;
      ys2 += t2 * t2;
      if (n == 1 || t2 < min_t2)
        min_t2 = t2;
      if (n > 2) {
        xs = sqrt((xs2 * n - xs1 * xs1) / (n * (n - 1)));
        ys = sqrt((ys2 * n - ys1 * ys1) / (n * (n - 1)));
        if (xs < min_t / 1000. && ys < min_t2 / 1000.)
          break;
      }
    }
    printf("%10d : %6.1f ns          /  %6.1f ns \n", (1 << nbits),
           min_t * 1000000000. / count, min_t2 * 1000000000. / count);
  }
  free(buffer_alloc);
  return 1;
}


x86 assembly (clang, -O0):
<latency_bench>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11ba <latency_bench+0x2a>
movl   $0x0,-0x4(%rbp)
jmp    171a <latency_bench+0x58a>
mov    -0x8(%rbp),%edi
add    $0xfff,%edi
call   1080 <malloc@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    11e9 <latency_bench+0x59>
movl   $0x0,-0x4(%rbp)
jmp    171a <latency_bench+0x58a>
mov    -0xa8(%rbp),%rax
add    $0xfff,%rax
and    $0xfffffffffffff000,%rax
mov    %rax,-0xa0(%rbp)
mov    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
movl   $0x1,-0x98(%rbp)
cmpl   $0xa,-0x98(%rbp)
jg     1306 <latency_bench+0x176>
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1040 <random_read_test@plt>
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x1,-0x98(%rbp)
je     127d <latency_bench+0xed>
movsd  -0x30(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    128c <latency_bench+0xfc>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0xa0(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   10a0 <random_dual_read_test@plt>
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x1,-0x98(%rbp)
je     12de <latency_bench+0x14e>
movsd  -0x30(%rbp),%xmm1
subsd  -0x28(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    12ed <latency_bench+0x15d>
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    12f2 <latency_bench+0x162>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    121e <latency_bench+0x8e>
lea    0xd03(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x10(%rbp)
jle    1331 <latency_bench+0x1a1>
lea    0xd1f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1361 <latency_bench+0x1d1>
cmpl   $0x0,-0x10(%rbp)
jge    134e <latency_bench+0x1be>
lea    0xd15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    135c <latency_bench+0x1cc>
lea    0xd3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1361 <latency_bench+0x1d1>
movl   $0xa,-0x94(%rbp)
mov    -0x94(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
cmp    -0x8(%rbp),%eax
jg     1707 <latency_bench+0x577>
mov    -0x94(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0xac(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
movl   $0x1,-0x98(%rbp)
cmpl   $0xa,-0x98(%rbp)
jg     16a6 <latency_bench+0x516>
mov    $0x0,%al
call   1070 <rand32@plt>
mov    %eax,-0xb4(%rbp)
mov    -0x8(%rbp),%eax
cltd
idivl  -0xac(%rbp)
mov    %eax,%ecx
mov    -0xb4(%rbp),%eax
cltd
idiv   %ecx
imul   -0xac(%rbp),%edx
mov    %edx,-0xb0(%rbp)
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0xa0(%rbp),%rdi
movslq -0xb0(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
mov    -0x94(%rbp),%edx
call   1040 <random_read_test@plt>
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1463 <latency_bench+0x2d3>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
cmpl   $0x1,-0x98(%rbp)
je     14b2 <latency_bench+0x322>
movsd  -0x18(%rbp),%xmm1
movsd  -0x88(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    14bf <latency_bench+0x32f>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0xa0(%rbp),%rdi
movslq -0xb0(%rbp),%rax
add    %rax,%rdi
mov    -0xc(%rbp),%esi
mov    -0x94(%rbp),%edx
call   10a0 <random_dual_read_test@plt>
mov    $0x0,%al
call   10b0 <gettime@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1520 <latency_bench+0x390>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
movsd  -0x80(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
cmpl   $0x1,-0x98(%rbp)
je     156f <latency_bench+0x3df>
movsd  -0x20(%rbp),%xmm1
movsd  -0x90(%rbp),%xmm0
ff
ucomisd %xmm1,%xmm0
jbe    157c <latency_bench+0x3ec>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
cmpl   $0x2,-0x98(%rbp)
jle    168d <latency_bench+0x4fd>
movsd  -0x60(%rbp),%xmm0
cvtsi2sdl -0x98(%rbp),%xmm2
ff
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x98(%rbp),%eax
mov    -0x98(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x80(%rbp),%xmm0
cvtsi2sdl -0x98(%rbp),%xmm2
ff
movsd  -0x78(%rbp),%xmm1
mulsd  -0x78(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x98(%rbp),%eax
mov    -0x98(%rbp),%ecx
sub    $0x1,%ecx
imul   %ecx,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1090 <sqrt@plt>
movsd  %xmm0,-0x68(%rbp)
movsd  -0x48(%rbp),%xmm1
movsd  -0x88(%rbp),%xmm0
ff
movsd  0x9ae(%rip),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1688 <latency_bench+0x4f8>
movsd  -0x68(%rbp),%xmm1
movsd  -0x90(%rbp),%xmm0
ff
movsd  0x98b(%rip),%xmm2
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1688 <latency_bench+0x4f8>
jmp    16a6 <latency_bench+0x516>
jmp    168d <latency_bench+0x4fd>
jmp    1692 <latency_bench+0x502>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    13c6 <latency_bench+0x236>
mov    -0x94(%rbp),%ecx
mov    $0x1,%esi
shl    %cl,%esi
movsd  0x94d(%rip),%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
cvtsi2sdl -0xc(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0x934(%rip),%xmm1
mulsd  -0x90(%rbp),%xmm1
ff
cvtsi2sdl -0xc(%rbp),%xmm2
divsd  %xmm2,%xmm1
lea    0x980(%rip),%rdi
mov    $0x2,%al
call   1050 <printf@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    136b <latency_bench+0x1db>
mov    -0xa8(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latency_bench>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
xor    %ebx,%ebx
test   %edx,%edx
jne    12db <latency_bench+0x13b>
mov    %esi,%r13d
mov    %edi,%ebp
lea    0xfff(%rbp),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     12db <latency_bench+0x13b>
mov    %rax,0x68(%rsp)
mov    %rax,%rdi
add    $0xfff,%rdi
and    $0xfffffffffffff000,%rdi
mov    %rdi,0x60(%rsp)
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
mov    $0xa,%r14d
mov    0x60(%rsp),%rbx
jmp    1220 <latency_bench+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm0,0x40(%rsp)
add    $0xffffffff,%r14d
je     12a7 <latency_bench+0x107>
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  %xmm0,0x28(%rsp)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
call   1050 <random_read_test@plt>
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  %xmm0,0x20(%rsp)
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  %xmm0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    $0x1,%edx
call   10b0 <random_dual_read_test@plt>
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  0x20(%rsp),%xmm1
subsd  0x28(%rsp),%xmm1
cmp    $0xa,%r14d
je     1286 <latency_bench+0xe6>
minsd  0x48(%rsp),%xmm1
movsd  %xmm1,0x48(%rsp)
movsd  0x10(%rsp),%xmm1
subsd  %xmm1,%xmm0
je     1210 <latency_bench+0x70>
minsd  0x40(%rsp),%xmm0
jmp    1210 <latency_bench+0x70>
lea    0xd6a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%ebx
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x400,%ebp
jge    12ec <latency_bench+0x14c>
mov    0x68(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorps  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm0
movsd  %xmm0,0x70(%rsp)
movl   $0x400,0xc(%rsp)
mov    %r13d,0x5c(%rsp)
jmp    1362 <latency_bench+0x1c2>
nopl   0x0(%rax)
movapd %xmm3,%xmm0
movsd  0xcec(%rip),%xmm3
mulsd  %xmm3,%xmm0
movsd  0x70(%rsp),%xmm2
divsd  %xmm2,%xmm0
movapd %xmm4,%xmm1
mulsd  %xmm3,%xmm1
divsd  %xmm2,%xmm1
lea    0xd0f(%rip),%rdi
mov    0xc(%rsp),%esi
mov    $0x2,%al
call   1060 <printf@plt>
lea    0x1(%rbx),%eax
mov    $0x2,%edx
mov    %ebx,%ecx
shl    %cl,%edx
mov    %eax,%ebx
mov    %edx,0xc(%rsp)
cmp    %ebp,%edx
jg     12cc <latency_bench+0x12c>
xor    %r15d,%r15d
movsd  (%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x28(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x20(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x50(%rsp)
jmp    13af <latency_bench+0x20f>
nopw   0x0(%rax,%rax,1)
mov    %r12d,%r15d
movsd  %xmm4,0x38(%rsp)
movsd  %xmm3,0x30(%rsp)
lea    0x1(%r15),%r12d
xor    %eax,%eax
call   1080 <rand32@plt>
mov    %eax,%ecx
mov    %rbp,%r14
mov    %ebp,%eax
cltd
idivl  0xc(%rsp)
mov    %eax,%esi
mov    %ecx,%eax
cltd
idiv   %esi
mov    %edx,%r13d
mov    %ebx,%ecx
shl    %cl,%r13d
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  %xmm0,(%rsp)
movslq %r13d,%rbp
add    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    0x5c(%rsp),%r13d
mov    %r13d,%esi
mov    %ebx,%edx
call   1050 <random_read_test@plt>
xor    %eax,%eax
call   10c0 <gettime@plt>
subsd  (%rsp),%xmm0
subsd  0x48(%rsp),%xmm0
xorpd  %xmm1,%xmm1
maxsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  %xmm0,(%rsp)
mov    %rbp,%rdi
mov    %r13d,%esi
mov    %ebx,%edx
call   10b0 <random_dual_read_test@plt>
xor    %eax,%eax
call   10c0 <gettime@plt>
movsd  0x18(%rsp),%xmm2
movapd %xmm2,%xmm3
test   %r15d,%r15d
je     1454 <latency_bench+0x2b4>
movapd %xmm2,%xmm3
minsd  0x30(%rsp),%xmm3
subsd  (%rsp),%xmm0
subsd  0x40(%rsp),%xmm0
xorpd  %xmm1,%xmm1
maxsd  %xmm0,%xmm1
movapd %xmm1,%xmm4
je     1477 <latency_bench+0x2d7>
movapd %xmm1,%xmm4
minsd  0x38(%rsp),%xmm4
movsd  0x50(%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x50(%rsp)
mulsd  %xmm2,%xmm2
movsd  0x10(%rsp),%xmm0
addsd  %xmm2,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  0x20(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x20(%rsp)
mulsd  %xmm1,%xmm1
movsd  0x28(%rsp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x28(%rsp)
cmp    $0x3,%r12d
mov    %r14,%rbp
jb     13a0 <latency_bench+0x200>
xorps  %xmm2,%xmm2
cvtsi2sd %r12d,%xmm2
movsd  0x50(%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm2,%xmm0
imul   %r12d,%r15d
cvtsi2sd %r15d,%xmm6
subsd  %xmm1,%xmm0
divsd  %xmm6,%xmm0
ucomisd 0xb0f(%rip),%xmm0
movsd  %xmm3,0x30(%rsp)
movsd  %xmm4,(%rsp)
jb     1520 <latency_bench+0x380>
sqrtsd %xmm0,%xmm5
jmp    1541 <latency_bench+0x3a1>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsd  %xmm2,0x18(%rsp)
movsd  %xmm6,0x38(%rsp)
call   10a0 <sqrt@plt>
movsd  0x38(%rsp),%xmm6
movsd  0x18(%rsp),%xmm2
movapd %xmm0,%xmm5
movsd  0x20(%rsp),%xmm0
mulsd  %xmm0,%xmm0
mulsd  0x28(%rsp),%xmm2
subsd  %xmm0,%xmm2
divsd  %xmm6,%xmm2
ucomisd 0xaaf(%rip),%xmm2
jb     1570 <latency_bench+0x3d0>
xorps  %xmm0,%xmm0
sqrtsd %xmm2,%xmm0
jmp    1585 <latency_bench+0x3e5>
nopl   0x0(%rax)
movapd %xmm2,%xmm0
movsd  %xmm5,0x18(%rsp)
call   10a0 <sqrt@plt>
movsd  0x18(%rsp),%xmm5
movsd  0x30(%rsp),%xmm3
movsd  (%rsp),%xmm4
movapd %xmm3,%xmm1
movsd  0xa64(%rip),%xmm2
divsd  %xmm2,%xmm1
ucomisd %xmm5,%xmm1
setbe  %al
movapd %xmm4,%xmm1
divsd  %xmm2,%xmm1
ucomisd %xmm0,%xmm1
setbe  %cl
or     %al,%cl
cmp    $0x1,%cl
jne    1310 <latency_bench+0x170>
cmp    $0x9,%r12d
jbe    13a0 <latency_bench+0x200>
jmp    1310 <latency_bench+0x170>

LLVM IR (-O0):
@.str = [52 x i8] c"\0Ablock size : single random read / dual random read\00"
@.str.1 = [19 x i8] c", [MADV_HUGEPAGE]\0A\00"
@.str.2 = [21 x i8] c", [MADV_NOHUGEPAGE]\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [39 x i8] c"%10d : %6.1f ns / %6.1f ns \0A\00"
define i32 @latency_bench(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca double
%22 = alloca double
%23 = alloca double
%24 = alloca i32
%25 = alloca i32
%26 = alloca i8*
%27 = alloca i8*
%28 = alloca i32
%29 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%30 = load i32, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %3
store i32 0, i32* %4
br label %263
33: ; preds = %3
%34 = load i32, i32* %5
%35 = add nsw i32 %34, 4095
%36 = call i64 @malloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %27
%38 = load i8*, i8** %27
%39 = icmp ne i8* %38, null
br i1 %39, label %41, label %40
40: ; preds = %33
store i32 0, i32* %4
br label %263
41: ; preds = %33
%42 = load i8*, i8** %27
%43 = ptrtoint i8* %42 to i64
%44 = add i64 %43, 4095
%45 = and i64 %44, -4096
%46 = inttoptr i64 %45 to i8*
store i8* %46, i8** %26
%47 = load i8*, i8** %26
%48 = load i32, i32* %5
%49 = call i32 @memset(i8* %47, i32 0, i32 %48)
store i32 1, i32* %25
br label %50
50: ; preds = %90, %41
%51 = load i32, i32* %25
%52 = icmp sle i32 %51, 10
br i1 %52, label %53, label %93
53: ; preds = %50
%54 = call double (...) @gettime()
store double %54, double* %10
%55 = load i8*, i8** %26
%56 = load i32, i32* %6
%57 = call i32 @random_read_test(i8* %55, i32 %56, i32 1)
%58 = call double (...) @gettime()
store double %58, double* %11
%59 = load i32, i32* %25
%60 = icmp eq i32 %59, 1
br i1 %60, label %67, label %61
61: ; preds = %53
%62 = load double, double* %11
%63 = load double, double* %10
%64 = fsub double %62, %63
%65 = load double, double* %12
%66 = fcmp olt double %64, %65
br i1 %66, label %67, label %71
67: ; preds = %61, %53
%68 = load double, double* %11
%69 = load double, double* %10
%70 = fsub double %68, %69
store double %70, double* %12
br label %71
71: ; preds = %67, %61
%72 = call double (...) @gettime()
store double %72, double* %10
%73 = load i8*, i8** %26
%74 = load i32, i32* %6
%75 = call i32 @random_dual_read_test(i8* %73, i32 %74, i32 1)
%76 = call double (...) @gettime()
store double %76, double* %11
%77 = load i32, i32* %25
%78 = icmp eq i32 %77, 1
br i1 %78, label %85, label %79
79: ; preds = %71
%80 = load double, double* %11
%81 = load double, double* %10
%82 = fsub double %80, %81
%83 = load double, double* %13
%84 = fcmp olt double %82, %83
br i1 %84, label %85, label %89
85: ; preds = %79, %71
%86 = load double, double* %11
%87 = load double, double* %10
%88 = fsub double %86, %87
store double %88, double* %13
br label %89
89: ; preds = %85, %79
br label %90
90: ; preds = %89
%91 = load i32, i32* %25
%92 = add nsw i32 %91, 1
store i32 %92, i32* %25
br label %50
93: ; preds = %50
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%95 = load i32, i32* %7
%96 = icmp sgt i32 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %93
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %107
99: ; preds = %93
%100 = load i32, i32* %7
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %99
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %106
104: ; preds = %99
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %106
106: ; preds = %104, %102
br label %107
107: ; preds = %106, %97
store i32 10, i32* %24
br label %108
108: ; preds = %257, %107
%109 = load i32, i32* %24
%110 = shl i32 1, %109
%111 = load i32, i32* %5
%112 = icmp sle i32 %110, %111
br i1 %112, label %113, label %260
113: ; preds = %108
%114 = load i32, i32* %24
%115 = shl i32 1, %114
store i32 %115, i32* %28
store double 0.000000e+00, double* %21
store double 0.000000e+00, double* %20
store double 0.000000e+00, double* %18
store double 0.000000e+00, double* %17
store double 0.000000e+00, double* %16
store i32 1, i32* %25
br label %116
116: ; preds = %240, %113
%117 = load i32, i32* %25
%118 = icmp sle i32 %117, 10
br i1 %118, label %119, label %243
119: ; preds = %116
%120 = call i32 (...) @rand32()
%121 = load i32, i32* %5
%122 = load i32, i32* %28
%123 = sdiv i32 %121, %122
%124 = srem i32 %120, %123
%125 = load i32, i32* %28
%126 = mul nsw i32 %124, %125
store i32 %126, i32* %29
%127 = call double (...) @gettime()
store double %127, double* %10
%128 = load i8*, i8** %26
%129 = load i32, i32* %29
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds i8, i8* %128, i64 %130
%132 = load i32, i32* %6
%133 = load i32, i32* %24
%134 = call i32 @random_read_test(i8* %131, i32 %132, i32 %133)
%135 = call double (...) @gettime()
store double %135, double* %11
%136 = load double, double* %11
%137 = load double, double* %10
%138 = fsub double %136, %137
%139 = load double, double* %12
%140 = fsub double %138, %139
store double %140, double* %8
%141 = load double, double* %8
%142 = fcmp olt double %141, 0.000000e+00
br i1 %142, label %143, label %144
143: ; preds = %119
store double 0.000000e+00, double* %8
br label %144
144: ; preds = %143, %119
%145 = load double, double* %8
%146 = load double, double* %16
%147 = fadd double %146, %145
store double %147, double* %16
%148 = load double, double* %8
%149 = load double, double* %8
%150 = load double, double* %17
%151 = call double @llvm.fmuladd.f64(double %148, double %149, double %150)
store double %151, double* %17
%152 = load i32, i32* %25
%153 = icmp eq i32 %152, 1
br i1 %153, label %158, label %154
154: ; preds = %144
%155 = load double, double* %8
%156 = load double, double* %22
%157 = fcmp olt double %155, %156
br i1 %157, label %158, label %160
158: ; preds = %154, %144
%159 = load double, double* %8
store double %159, double* %22
br label %160
160: ; preds = %158, %154
%161 = call double (...) @gettime()
store double %161, double* %10
%162 = load i8*, i8** %26
%163 = load i32, i32* %29
%164 = sext i32 %163 to i64
%165 = getelementptr inbounds i8, i8* %162, i64 %164
%166 = load i32, i32* %6
%167 = load i32, i32* %24
%168 = call i32 @random_dual_read_test(i8* %165, i32 %166, i32 %167)
%169 = call double (...) @gettime()
store double %169, double* %11
%170 = load double, double* %11
%171 = load double, double* %10
%172 = fsub double %170, %171
%173 = load double, double* %13
%174 = fsub double %172, %173
store double %174, double* %9
%175 = load double, double* %9
%176 = fcmp olt double %175, 0.000000e+00
br i1 %176, label %177, label %178
177: ; preds = %160
store double 0.000000e+00, double* %9
br label %178
178: ; preds = %177, %160
%179 = load double, double* %9
%180 = load double, double* %20
%181 = fadd double %180, %179
store double %181, double* %20
%182 = load double, double* %9
%183 = load double, double* %9
%184 = load double, double* %21
%185 = call double @llvm.fmuladd.f64(double %182, double %183, double %184)
store double %185, double* %21
%186 = load i32, i32* %25
%187 = icmp eq i32 %186, 1
br i1 %187, label %192, label %188
188: ; preds = %178
%189 = load double, double* %9
%190 = load double, double* %23
%191 = fcmp olt double %189, %190
br i1 %191, label %192, label %194
192: ; preds = %188, %178
%193 = load double, double* %9
store double %193, double* %23
br label %194
194: ; preds = %192, %188
%195 = load i32, i32* %25
%196 = icmp sgt i32 %195, 2
br i1 %196, label %197, label %239
197: ; preds = %194
%198 = load double, double* %17
%199 = load i32, i32* %25
%200 = sitofp i32 %199 to double
%201 = load double, double* %16
%202 = load double, double* %16
%203 = fmul double %201, %202
%204 = fneg double %203
%205 = call double @llvm.fmuladd.f64(double %198, double %200, double %204)
%206 = load i32, i32* %25
%207 = load i32, i32* %25
%208 = sub nsw i32 %207, 1
%209 = mul nsw i32 %206, %208
%210 = sitofp i32 %209 to double
%211 = fdiv double %205, %210
%212 = call double @sqrt(double %211)
store double %212, double* %14
%213 = load double, double* %21
%214 = load i32, i32* %25
%215 = sitofp i32 %214 to double
%216 = load double, double* %20
%217 = load double, double* %20
%218 = fmul double %216, %217
%219 = fneg double %218
%220 = call double @llvm.fmuladd.f64(double %213, double %215, double %219)
%221 = load i32, i32* %25
%222 = load i32, i32* %25
%223 = sub nsw i32 %222, 1
%224 = mul nsw i32 %221, %223
%225 = sitofp i32 %224 to double
%226 = fdiv double %220, %225
%227 = call double @sqrt(double %226)
store double %227, double* %18
%228 = load double, double* %14
%229 = load double, double* %22
%230 = fdiv double %229, 1.000000e+03
%231 = fcmp olt double %228, %230
br i1 %231, label %232, label %238
232: ; preds = %197
%233 = load double, double* %18
%234 = load double, double* %23
%235 = fdiv double %234, 1.000000e+03
%236 = fcmp olt double %233, %235
br i1 %236, label %237, label %238
237: ; preds = %232
br label %243
238: ; preds = %232, %197
br label %239
239: ; preds = %238, %194
br label %240
240: ; preds = %239
%241 = load i32, i32* %25
%242 = add nsw i32 %241, 1
store i32 %242, i32* %25
br label %116
243: ; preds = %237, %116
%244 = load i32, i32* %24
%245 = shl i32 1, %244
%246 = load double, double* %22
%247 = fmul double %246, 1.000000e+09
%248 = load i32, i32* %6
%249 = sitofp i32 %248 to double
%250 = fdiv double %247, %249
%251 = load double, double* %23
%252 = fmul double %251, 1.000000e+09
%253 = load i32, i32* %6
%254 = sitofp i32 %253 to double
%255 = fdiv double %252, %254
%256 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %245, double %250, double %255)
br label %257
257: ; preds = %243
%258 = load i32, i32* %24
%259 = add nsw i32 %258, 1
store i32 %259, i32* %24
br label %108
260: ; preds = %108
%261 = load i8*, i8** %27
%262 = call i32 @free(i8* %261)
store i32 1, i32* %4
br label %263
263: ; preds = %260, %40, %32
%264 = load i32, i32* %4
ret i32 %264
}

LLVM IR (-O2):
@.str = [52 x i8] c"\0Ablock size : single random read / dual random read\00"
@.str.4 = [39 x i8] c"%10d : %6.1f ns / %6.1f ns \0A\00"
define i32 @latency_bench(i32 %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %5, label %122
5: ; preds = %3
%6 = add nsw i32 %0, 4095
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i8*
%9 = icmp eq i64 %7, 0
br i1 %9, label %122, label %10
10: ; preds = %5
%11 = add i64 %7, 4095
%12 = and i64 %11, -4096
%13 = inttoptr i64 %12 to i8*
%14 = tail call i32 @memset(i8* %13, i32 0, i32 %0)
br label %15
15: ; preds = %10, %15
%16 = phi i32 [ 1, %10 ], [ %34, %15 ]
%17 = phi double [ undef, %10 ], [ %26, %15 ]
%18 = phi double [ undef, %10 ], [ %33, %15 ]
%19 = tail call double (...) @gettime()
%20 = tail call i32 @random_read_test(i8* %13, i32 %1, i32 1)
%21 = tail call double (...) @gettime()
%22 = icmp eq i32 %16, 1
%23 = fsub double %21, %19
%24 = fcmp olt double %23, %17
%25 = select i1 %22, i1 true, i1 %24
%26 = select i1 %25, double %23, double %17
%27 = tail call double (...) @gettime()
%28 = tail call i32 @random_dual_read_test(i8* %13, i32 %1, i32 1)
%29 = tail call double (...) @gettime()
%30 = fsub double %29, %27
%31 = fcmp olt double %30, %18
%32 = select i1 %22, i1 true, i1 %31
%33 = select i1 %32, double %30, double %18
%34 = add nuw nsw i32 %16, 1
%35 = icmp eq i32 %34, 11
br i1 %35, label %36, label %15
36: ; preds = %15
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%38 = tail call i32 @putchar(i32 10)
%39 = icmp slt i32 %0, 1024
br i1 %39, label %120, label %40
40: ; preds = %36
%41 = sitofp i32 %1 to double
br label %42
42: ; preds = %40, %111
%43 = phi i32 [ 1024, %40 ], [ %118, %111 ]
%44 = phi i32 [ 10, %40 ], [ %117, %111 ]
%45 = phi double [ undef, %40 ], [ %85, %111 ]
%46 = phi double [ undef, %40 ], [ %73, %111 ]
br label %47
47: ; preds = %109, %42
%48 = phi i32 [ 1, %42 ], [ %110, %109 ]
%49 = phi double [ %45, %42 ], [ %85, %109 ]
%50 = phi double [ %46, %42 ], [ %73, %109 ]
%51 = phi double [ 0.000000e+00, %42 ], [ %82, %109 ]
%52 = phi double [ 0.000000e+00, %42 ], [ %81, %109 ]
%53 = phi double [ 0.000000e+00, %42 ], [ %69, %109 ]
%54 = phi double [ 0.000000e+00, %42 ], [ %68, %109 ]
%55 = tail call i32 (...) @rand32()
%56 = sdiv i32 %0, %43
%57 = srem i32 %55, %56
%58 = shl i32 %57, %44
%59 = tail call double (...) @gettime()
%60 = sext i32 %58 to i64
%61 = getelementptr inbounds i8, i8* %13, i64 %60
%62 = tail call i32 @random_read_test(i8* %61, i32 %1, i32 %44)
%63 = tail call double (...) @gettime()
%64 = fsub double %63, %59
%65 = fsub double %64, %26
%66 = fcmp olt double %65, 0.000000e+00
%67 = select i1 %66, double 0.000000e+00, double %65
%68 = fadd double %54, %67
%69 = tail call double @llvm.fmuladd.f64(double %67, double %67, double %53)
%70 = icmp eq i32 %48, 1
%71 = fcmp olt double %67, %50
%72 = select i1 %70, i1 true, i1 %71
%73 = select i1 %72, double %67, double %50
%74 = tail call double (...) @gettime()
%75 = tail call i32 @random_dual_read_test(i8* %61, i32 %1, i32 %44)
%76 = tail call double (...) @gettime()
%77 = fsub double %76, %74
%78 = fsub double %77, %33
%79 = fcmp olt double %78, 0.000000e+00
%80 = select i1 %79, double 0.000000e+00, double %78
%81 = fadd double %52, %80
%82 = tail call double @llvm.fmuladd.f64(double %80, double %80, double %51)
%83 = fcmp olt double %80, %49
%84 = select i1 %70, i1 true, i1 %83
%85 = select i1 %84, double %80, double %49
%86 = icmp ugt i32 %48, 2
br i1 %86, label %87, label %109
87: ; preds = %47
%88 = sitofp i32 %48 to double
%89 = fneg double %68
%90 = fmul double %68, %89
%91 = tail call double @llvm.fmuladd.f64(double %69, double %88, double %90)
%92 = add nsw i32 %48, -1
%93 = mul nuw nsw i32 %92, %48
%94 = sitofp i32 %93 to double
%95 = fdiv double %91, %94
%96 = tail call double @sqrt(double %95)
%97 = fneg double %81
%98 = fmul double %81, %97
%99 = tail call double @llvm.fmuladd.f64(double %82, double %88, double %98)
%100 = fdiv double %99, %94
%101 = tail call double @sqrt(double %100)
%102 = fdiv double %73, 1.000000e+03
%103 = fcmp uge double %96, %102
%104 = fdiv double %85, 1.000000e+03
%105 = fcmp uge double %101, %104
%106 = select i1 %103, i1 true, i1 %105
%107 = icmp ult i32 %48, 10
%108 = select i1 %106, i1 %107, i1 false
br i1 %108, label %109, label %111
109: ; preds = %47, %87
%110 = add nuw nsw i32 %48, 1
br label %47
111: ; preds = %87
%112 = fmul double %73, 1.000000e+09
%113 = fdiv double %112, %41
%114 = fmul double %85, 1.000000e+09
%115 = fdiv double %114, %41
%116 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %43, double %113, double %115)
%117 = add nuw nsw i32 %44, 1
%118 = shl i32 2, %44
%119 = icmp sgt i32 %118, %0
br i1 %119, label %120, label %42
120: ; preds = %111, %36
%121 = tail call i32 @free(i8* %8)
br label %122
122: ; preds = %5, %3, %120
%123 = phi i32 [ 1, %120 ], [ 0, %3 ], [ 0, %5 ]
ret i32 %123
}