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

/* Variables and functions */
double benchTimer();
int timerTest(double *overhead, double *threshold_lo, double *threshold_hi) {
  int i;
  double tstart, tend, tmax, tdelta, resolution;
  struct timespec res;
  tstart = benchTimer();
  for (i = 0; i < 1000000UL; i++) {
    tdelta = benchTimer();
  }
  tend = benchTimer();
  *overhead = (tend - tstart) / (double)1000000UL;
  *threshold_lo = *overhead * 100.0;
  *threshold_hi = *overhead * 1000.0;
  return 0;
}


x86 assembly (clang, -O0):
<timerTest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1030 <benchTimer@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0xf4240,%rax
jae    1161 <timerTest+0x51>
mov    $0x0,%al
call   1030 <benchTimer@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1137 <timerTest+0x27>
mov    $0x0,%al
call   1030 <benchTimer@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  0xe91(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe71(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
movsd  0xe51(%rip),%xmm0
mulsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timerTest>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
xor    %eax,%eax
call   1030 <benchTimer@plt>
movsd  %xmm0,(%rsp)
mov    $0xf4240,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <benchTimer@plt>
add    $0xffffffff,%ebp
jne    1140 <timerTest+0x30>
xor    %eax,%eax
call   1030 <benchTimer@plt>
subsd  (%rsp),%xmm0
divsd  0xea0(%rip),%xmm0
movsd  %xmm0,(%rbx)
mulsd  0xe9c(%rip),%xmm0
movsd  %xmm0,(%r15)
movsd  (%rbx),%xmm0
mulsd  0xe93(%rip),%xmm0
movsd  %xmm0,(%r14)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @timerTest(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca %struct.timespec
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%14 = call double (...) @benchTimer()
store double %14, double* %8
store i32 0, i32* %7
br label %15
15: ; preds = %21, %3
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = icmp ult i64 %17, 1000000
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = call double (...) @benchTimer()
store double %20, double* %11
br label %21
21: ; preds = %19
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %15
24: ; preds = %15
%25 = call double (...) @benchTimer()
store double %25, double* %9
%26 = load double, double* %9
%27 = load double, double* %8
%28 = fsub double %26, %27
%29 = fdiv double %28, 1.000000e+06
%30 = load double*, double** %4
store double %29, double* %30
%31 = load double*, double** %4
%32 = load double, double* %31
%33 = fmul double %32, 1.000000e+02
%34 = load double*, double** %5
store double %33, double* %34
%35 = load double*, double** %4
%36 = load double, double* %35
%37 = fmul double %36, 1.000000e+03
%38 = load double*, double** %6
store double %37, double* %38
ret i32 0
}

LLVM IR (-O2):
define i32 @timerTest(double* nocapture %0, double* nocapture writeonly %1, double* nocapture writeonly %2) {
%4 = tail call double (...) @benchTimer()
br label %5
5: ; preds = %3, %5
%6 = phi i32 [ 0, %3 ], [ %8, %5 ]
%7 = tail call double (...) @benchTimer()
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, 1000000
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = tail call double (...) @benchTimer()
%12 = fsub double %11, %4
%13 = fdiv double %12, 1.000000e+06
store double %13, double* %0
%14 = fmul double %13, 1.000000e+02
store double %14, double* %1
%15 = load double, double* %0
%16 = fmul double %15, 1.000000e+03
store double %16, double* %2
ret i32 0
}