#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 internal_bench {
  int dummy;
};

/* Variables and functions */
double measure_once(struct internal_bench *, long);
double run_benchmark(struct internal_bench *b) {
  long iterations = 128;
  double nsec;
  while (1) {
    nsec = measure_once(b, iterations);
    if (nsec > 0.3E9) {
      break;
    }
    iterations <<= 1;
  }
  while (nsec < 3E9) {
    iterations = (long)(iterations * 3E9 * 1.1 / nsec);
    nsec = measure_once(b, iterations);
  }
  return nsec / iterations;
}


x86 assembly (clang, -O0):
<run_benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x80,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <measure_once@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xebd(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1152 <run_benchmark+0x42>
jmp    1163 <run_benchmark+0x53>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <run_benchmark+0x14>
jmp    1168 <run_benchmark+0x58>
movsd  0xe98(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    11be <run_benchmark+0xae>
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7b(%rip),%xmm1
mulsd  %xmm1,%xmm0
divsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <measure_once@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1168 <run_benchmark+0x58>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_benchmark>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    $0x80,%eax
nopl   0x0(%rax)
mov    %rax,%rbx
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <measure_once@plt>
lea    (%rbx,%rbx,1),%rax
ucomisd 0xec6(%rip),%xmm0
jbe    1120 <run_benchmark+0x10>
jmp    1160 <run_benchmark+0x50>
xchg   %ax,%ax
mulsd  %xmm2,%xmm1
mulsd  0xec4(%rip),%xmm1
divsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rbx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <measure_once@plt>
movsd  0xea0(%rip),%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
ucomisd %xmm0,%xmm2
ja     1140 <run_benchmark+0x30>
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.internal_bench = type { i32 }
define double @run_benchmark(%struct.internal_bench* %0) {
%2 = alloca %struct.internal_bench*
%3 = alloca i64
%4 = alloca double
store %struct.internal_bench* %0, %struct.internal_bench** %2
store i64 128, i64* %3
br label %5
5: ; preds = %1, %12
%6 = load %struct.internal_bench*, %struct.internal_bench** %2
%7 = load i64, i64* %3
%8 = call double @measure_once(%struct.internal_bench* %6, i64 %7)
store double %8, double* %4
%9 = load double, double* %4
%10 = fcmp ogt double %9, 3.000000e+08
br i1 %10, label %11, label %12
11: ; preds = %5
br label %15
12: ; preds = %5
%13 = load i64, i64* %3
%14 = shl i64 %13, 1
store i64 %14, i64* %3
br label %5
15: ; preds = %11
br label %16
16: ; preds = %19, %15
%17 = load double, double* %4
%18 = fcmp olt double %17, 3.000000e+09
br i1 %18, label %19, label %30
19: ; preds = %16
%20 = load i64, i64* %3
%21 = sitofp i64 %20 to double
%22 = fmul double %21, 3.000000e+09
%23 = fmul double %22, 1.100000e+00
%24 = load double, double* %4
%25 = fdiv double %23, %24
%26 = fptosi double %25 to i64
store i64 %26, i64* %3
%27 = load %struct.internal_bench*, %struct.internal_bench** %2
%28 = load i64, i64* %3
%29 = call double @measure_once(%struct.internal_bench* %27, i64 %28)
store double %29, double* %4
br label %16
30: ; preds = %16
%31 = load double, double* %4
%32 = load i64, i64* %3
%33 = sitofp i64 %32 to double
%34 = fdiv double %31, %33
ret double %34
}

LLVM IR (-O2):
%struct.internal_bench = type { i32 }
define double @run_benchmark(%struct.internal_bench* %0) {
br label %2
2: ; preds = %2, %1
%3 = phi i64 [ 128, %1 ], [ %6, %2 ]
%4 = tail call double @measure_once(%struct.internal_bench* %0, i64 %3)
%5 = fcmp ogt double %4, 3.000000e+08
%6 = shl i64 %3, 1
br i1 %5, label %7, label %2
7: ; preds = %2
%8 = fcmp olt double %4, 3.000000e+09
br i1 %8, label %9, label %19
9: ; preds = %7, %9
%10 = phi double [ %17, %9 ], [ %4, %7 ]
%11 = phi i64 [ %16, %9 ], [ %3, %7 ]
%12 = sitofp i64 %11 to double
%13 = fmul double %12, 3.000000e+09
%14 = fmul double %13, 1.100000e+00
%15 = fdiv double %14, %10
%16 = fptosi double %15 to i64
%17 = tail call double @measure_once(%struct.internal_bench* %0, i64 %16)
%18 = fcmp olt double %17, 3.000000e+09
br i1 %18, label %9, label %19
19: ; preds = %9, %7
%20 = phi i64 [ %3, %7 ], [ %16, %9 ]
%21 = phi double [ %4, %7 ], [ %17, %9 ]
%22 = sitofp i64 %20 to double
%23 = fdiv double %21, %22
ret double %23
}