#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 */
double fabs(double);
double hpctimer_wtime();
int /*<<< orphan*/ sleep(int);
int hpctimer_sanity_check() {
  enum { NTESTS = 4 };
  double start, stop, currtime, prevtime = 0.0, err = 0.05;
  int sanity = 1, delay;
  for (delay = 1; delay < NTESTS; delay++) {
    start = hpctimer_wtime();
    sleep(delay);
    stop = hpctimer_wtime();
    currtime = stop - start;
    if (delay > 1) {
      if (fabs(prevtime - currtime / delay) > prevtime * err) {
        sanity = 0;
      }
    }
    prevtime = currtime / delay;
  }
  return sanity;
}


x86 assembly (clang, -O0):
<hpctimer_sanity_check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xec8(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
cmpl   $0x4,-0x30(%rbp)
jge    11f1 <hpctimer_sanity_check+0xd1>
mov    $0x0,%al
call   1030 <hpctimer_wtime@plt>
movsd  %xmm0,-0x8(%rbp)
mov    -0x30(%rbp),%edi
call   1040 <sleep@plt>
mov    $0x0,%al
call   1030 <hpctimer_wtime@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x1,-0x30(%rbp)
jle    11d0 <hpctimer_sanity_check+0xb0>
movsd  -0x20(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
cvtsi2sdl -0x30(%rbp),%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movaps 0xe64(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
mulsd  -0x28(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11cb <hpctimer_sanity_check+0xab>
movl   $0x0,-0x2c(%rbp)
jmp    11d0 <hpctimer_sanity_check+0xb0>
movsd  -0x18(%rbp),%xmm0
cvtsi2sdl -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    114b <hpctimer_sanity_check+0x2b>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpctimer_sanity_check>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
movsd  %xmm0,(%rsp)
mov    $0x1,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
subsd  (%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
movsd  %xmm0,(%rsp)
mov    $0x2,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
subsd  (%rsp),%xmm0
mulsd  0xe89(%rip),%xmm0
movsd  %xmm0,(%rsp)
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
andpd  0xe8e(%rip),%xmm1
mulsd  0xe6e(%rip),%xmm2
ucomisd %xmm2,%xmm1
setbe  %bl
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x3,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
call   1030 <hpctimer_wtime@plt>
subsd  0x8(%rsp),%xmm0
divsd  0xe43(%rip),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm1,%xmm0
andpd  0xe42(%rip),%xmm0
mulsd  0xe22(%rip),%xmm1
ucomisd %xmm1,%xmm0
setbe  %al
and    %bl,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @hpctimer_sanity_check() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double 0.000000e+00, double* %4
store double 5.000000e-02, double* %5
store i32 1, i32* %6
store i32 1, i32* %7
br label %8
8: ; preds = %40, %0
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 4
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = call double (...) @hpctimer_wtime()
store double %12, double* %1
%13 = load i32, i32* %7
%14 = call i32 @sleep(i32 %13)
%15 = call double (...) @hpctimer_wtime()
store double %15, double* %2
%16 = load double, double* %2
%17 = load double, double* %1
%18 = fsub double %16, %17
store double %18, double* %3
%19 = load i32, i32* %7
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %35
21: ; preds = %11
%22 = load double, double* %4
%23 = load double, double* %3
%24 = load i32, i32* %7
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
%27 = fsub double %22, %26
%28 = call double @llvm.fabs.f64(double %27)
%29 = load double, double* %4
%30 = load double, double* %5
%31 = fmul double %29, %30
%32 = fcmp ogt double %28, %31
br i1 %32, label %33, label %34
33: ; preds = %21
store i32 0, i32* %6
br label %34
34: ; preds = %33, %21
br label %35
35: ; preds = %34, %11
%36 = load double, double* %3
%37 = load i32, i32* %7
%38 = sitofp i32 %37 to double
%39 = fdiv double %36, %38
store double %39, double* %4
br label %40
40: ; preds = %35
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %8
43: ; preds = %8
%44 = load i32, i32* %6
ret i32 %44
}

LLVM IR (-O2):
define i32 @hpctimer_sanity_check() {
%1 = tail call double (...) @hpctimer_wtime()
%2 = tail call i32 @sleep(i32 1)
%3 = tail call double (...) @hpctimer_wtime()
%4 = fsub double %3, %1
%5 = tail call double (...) @hpctimer_wtime()
%6 = tail call i32 @sleep(i32 2)
%7 = tail call double (...) @hpctimer_wtime()
%8 = fsub double %7, %5
%9 = fmul double %8, 5.000000e-01
%10 = fsub double %4, %9
%11 = tail call double @llvm.fabs.f64(double %10)
%12 = fmul double %4, 5.000000e-02
%13 = fcmp ule double %11, %12
%14 = tail call double (...) @hpctimer_wtime()
%15 = tail call i32 @sleep(i32 3)
%16 = tail call double (...) @hpctimer_wtime()
%17 = fsub double %16, %14
%18 = fdiv double %17, 3.000000e+00
%19 = fsub double %9, %18
%20 = tail call double @llvm.fabs.f64(double %19)
%21 = fmul double %9, 5.000000e-02
%22 = fcmp ule double %20, %21
%23 = select i1 %22, i1 %13, i1 false
%24 = zext i1 %23 to i32
ret i32 %24
}