#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*/ fflush(int /*<<< orphan*/);
int floor(double);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
double uclock_sec();
void run_bench(const char *s, int (*fn)()) {
  printf("benching %20s ..", s);
  fflush(stdout);
  double t0 = uclock_sec(), t1, tmax = 1.0;
  double niter = 0;
  do {
    niter += fn();
    t1 = uclock_sec();
  } while (t1 - t0 < tmax);
  printf(" -> %6.1f millions of vector evaluations/second over %g iters -> "
         "%3.0f cycles/value on a %gMHz computer\n",
         floor(niter / (t1 - t0) / 1e5) / 10, niter,
         (t1 - t0) * 2000.0 * 1e6 / niter / 4, 2000.0);
}


x86 assembly (clang, -O0):
<run_bench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    $0x0,%al
call   1040 <uclock_sec@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  0xe7c(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   *-0x10(%rbp)
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <uclock_sec@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1191 <run_bench+0x51>
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  0xe3c(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1060 <floor@plt>
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
movsd  -0x30(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xdfa(%rip),%xmm2
mulsd  %xmm2,%xmm1
movsd  0xdfe(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  -0x30(%rbp),%xmm1
movsd  0xde5(%rip),%xmm2
divsd  %xmm2,%xmm1
lea    0xe03(%rip),%rdi
movsd  0xdca(%rip),%xmm2
mov    $0x3,%al
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_bench>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rsi
lea    0xed6(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
xor    %eax,%eax
call   1040 <uclock_sec@plt>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopl   (%rax)
xor    %eax,%eax
call   *%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <uclock_sec@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movsd  0xe4e(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1180 <run_bench+0x40>
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
divsd  0xe3f(%rip),%xmm0
movsd  %xmm1,0x8(%rsp)
call   1060 <floor@plt>
cltq
imul   $0x66666667,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x22,%rsi
add    %eax,%esi
movsd  0xe1e(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
mulsd  %xmm2,%xmm1
mulsd  0xe14(%rip),%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm0,%xmm1
mulsd  0xe0b(%rip),%xmm1
lea    0xe1d(%rip),%rdi
mov    $0x3,%al
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"benching %20s ..\00"
@stdout = global i32 0
@.str.1 = [105 x i8] c" -> %6.1f millions of vector evaluations/second over %g iters -> %3.0f cycles/value on a %gMHz computer\0A\00"
define void @run_bench(i8* %0, i32 (...)* %1) {
%3 = alloca i8*
%4 = alloca i32 (...)*
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store i8* %0, i8** %3
store i32 (...)* %1, i32 (...)** %4
%9 = load i8*, i8** %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @stdout
%12 = call i32 @fflush(i32 %11)
%13 = call double (...) @uclock_sec()
store double %13, double* %5
store double 1.000000e+00, double* %7
store double 0.000000e+00, double* %8
br label %14
14: ; preds = %21, %2
%15 = load i32 (...)*, i32 (...)** %4
%16 = call i32 (...) %15()
%17 = sitofp i32 %16 to double
%18 = load double, double* %8
%19 = fadd double %18, %17
store double %19, double* %8
%20 = call double (...) @uclock_sec()
store double %20, double* %6
br label %21
21: ; preds = %14
%22 = load double, double* %6
%23 = load double, double* %5
%24 = fsub double %22, %23
%25 = load double, double* %7
%26 = fcmp olt double %24, %25
br i1 %26, label %14, label %27
27: ; preds = %21
%28 = load double, double* %8
%29 = load double, double* %6
%30 = load double, double* %5
%31 = fsub double %29, %30
%32 = fdiv double %28, %31
%33 = fdiv double %32, 1.000000e+05
%34 = call i32 @floor(double %33)
%35 = sdiv i32 %34, 10
%36 = load double, double* %8
%37 = load double, double* %6
%38 = load double, double* %5
%39 = fsub double %37, %38
%40 = fmul double %39, 2.000000e+03
%41 = fmul double %40, 1.000000e+06
%42 = load double, double* %8
%43 = fdiv double %41, %42
%44 = fdiv double %43, 4.000000e+00
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([105 x i8], [105 x i8]* @.str.1, i64 0, i64 0), i32 %35, double %36, double %44, double 2.000000e+03)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"benching %20s ..\00"
@stdout = global i32 0
@.str.1 = [105 x i8] c" -> %6.1f millions of vector evaluations/second over %g iters -> %3.0f cycles/value on a %gMHz computer\0A\00"
define void @run_bench(i8* %0, i32 (...)* nocapture %1) {
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
%4 = load i32, i32* @stdout
%5 = tail call i32 @fflush(i32 %4)
%6 = tail call double (...) @uclock_sec()
br label %7
7: ; preds = %7, %2
%8 = phi double [ 0.000000e+00, %2 ], [ %11, %7 ]
%9 = tail call i32 (...) %1()
%10 = sitofp i32 %9 to double
%11 = fadd double %8, %10
%12 = tail call double (...) @uclock_sec()
%13 = fsub double %12, %6
%14 = fcmp olt double %13, 1.000000e+00
br i1 %14, label %7, label %15
15: ; preds = %7
%16 = fdiv double %11, %13
%17 = fdiv double %16, 1.000000e+05
%18 = tail call i32 @floor(double %17)
%19 = sdiv i32 %18, 10
%20 = fmul double %13, 2.000000e+03
%21 = fmul double %20, 1.000000e+06
%22 = fdiv double %21, %11
%23 = fmul double %22, 2.500000e-01
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([105 x i8], [105 x i8]* @.str.1, i64 0, i64 0), i32 %19, double %11, double %23, double 2.000000e+03)
ret void
}