#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 */
typedef scalar_t__ uint64_t;

/* Variables and functions */
scalar_t__ hpctimer_gettsc();
uint64_t hpctimer_measure_overhead() {
  enum { TSC_OVERHEAD_NTESTS = 10 };
  int i;
  uint64_t count, overhead = (uint64_t)~0x01;
  for (i = 0; i < TSC_OVERHEAD_NTESTS; i++) {
    count = hpctimer_gettsc();
    count = hpctimer_gettsc() - count;
    if (count < overhead) {
      overhead = count;
    }
  }
  return overhead;
}


x86 assembly (clang, -O0):
<hpctimer_measure_overhead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0xfffffffffffffffe,-0x18(%rbp)
ff
movl   $0x0,-0x4(%rbp)
cmpl   $0xa,-0x4(%rbp)
jge    1174 <hpctimer_measure_overhead+0x64>
mov    $0x0,%al
call   1030 <hpctimer_gettsc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <hpctimer_gettsc@plt>
sub    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    1161 <hpctimer_measure_overhead+0x51>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    1166 <hpctimer_measure_overhead+0x56>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1127 <hpctimer_measure_overhead+0x17>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hpctimer_measure_overhead>:
push   %r15
push   %r14
push   %rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r15
sub    %r14,%r15
cmp    $0xfffffffffffffffe,%r15
mov    $0xfffffffffffffffe,%rax
cmovge %rax,%r15
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    %r15,%rbx
cmovge %r15,%rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r15
sub    %r14,%r15
cmp    %rbx,%r15
cmovge %rbx,%r15
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    %r15,%rbx
cmovge %r15,%rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r15
sub    %r14,%r15
cmp    %rbx,%r15
cmovge %rbx,%r15
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    %r15,%rbx
cmovge %r15,%rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r15
sub    %r14,%r15
cmp    %rbx,%r15
cmovge %rbx,%r15
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%rbx
sub    %r14,%rbx
cmp    %r15,%rbx
cmovge %r15,%rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%r15
sub    %r14,%r15
cmp    %rbx,%r15
cmovge %rbx,%r15
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <hpctimer_gettsc@plt>
sub    %rbx,%rax
cmp    %r15,%rax
cmovge %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @hpctimer_measure_overhead() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
store i64 -2, i64* %3
store i32 0, i32* %1
br label %4
4: ; preds = %18, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 10
br i1 %6, label %7, label %21
7: ; preds = %4
%8 = call i64 (...) @hpctimer_gettsc()
store i64 %8, i64* %2
%9 = call i64 (...) @hpctimer_gettsc()
%10 = load i64, i64* %2
%11 = sub nsw i64 %9, %10
store i64 %11, i64* %2
%12 = load i64, i64* %2
%13 = load i64, i64* %3
%14 = icmp slt i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = load i64, i64* %2
store i64 %16, i64* %3
br label %17
17: ; preds = %15, %7
br label %18
18: ; preds = %17
%19 = load i32, i32* %1
%20 = add nsw i32 %19, 1
store i32 %20, i32* %1
br label %4
21: ; preds = %4
%22 = load i64, i64* %3
ret i64 %22
}

LLVM IR (-O2):
define i64 @hpctimer_measure_overhead() {
%1 = tail call i64 (...) @hpctimer_gettsc()
%2 = tail call i64 (...) @hpctimer_gettsc()
%3 = sub nsw i64 %2, %1
%4 = icmp slt i64 %3, -2
%5 = select i1 %4, i64 %3, i64 -2
%6 = tail call i64 (...) @hpctimer_gettsc()
%7 = tail call i64 (...) @hpctimer_gettsc()
%8 = sub nsw i64 %7, %6
%9 = icmp slt i64 %8, %5
%10 = select i1 %9, i64 %8, i64 %5
%11 = tail call i64 (...) @hpctimer_gettsc()
%12 = tail call i64 (...) @hpctimer_gettsc()
%13 = sub nsw i64 %12, %11
%14 = icmp slt i64 %13, %10
%15 = select i1 %14, i64 %13, i64 %10
%16 = tail call i64 (...) @hpctimer_gettsc()
%17 = tail call i64 (...) @hpctimer_gettsc()
%18 = sub nsw i64 %17, %16
%19 = icmp slt i64 %18, %15
%20 = select i1 %19, i64 %18, i64 %15
%21 = tail call i64 (...) @hpctimer_gettsc()
%22 = tail call i64 (...) @hpctimer_gettsc()
%23 = sub nsw i64 %22, %21
%24 = icmp slt i64 %23, %20
%25 = select i1 %24, i64 %23, i64 %20
%26 = tail call i64 (...) @hpctimer_gettsc()
%27 = tail call i64 (...) @hpctimer_gettsc()
%28 = sub nsw i64 %27, %26
%29 = icmp slt i64 %28, %25
%30 = select i1 %29, i64 %28, i64 %25
%31 = tail call i64 (...) @hpctimer_gettsc()
%32 = tail call i64 (...) @hpctimer_gettsc()
%33 = sub nsw i64 %32, %31
%34 = icmp slt i64 %33, %30
%35 = select i1 %34, i64 %33, i64 %30
%36 = tail call i64 (...) @hpctimer_gettsc()
%37 = tail call i64 (...) @hpctimer_gettsc()
%38 = sub nsw i64 %37, %36
%39 = icmp slt i64 %38, %35
%40 = select i1 %39, i64 %38, i64 %35
%41 = tail call i64 (...) @hpctimer_gettsc()
%42 = tail call i64 (...) @hpctimer_gettsc()
%43 = sub nsw i64 %42, %41
%44 = icmp slt i64 %43, %40
%45 = select i1 %44, i64 %43, i64 %40
%46 = tail call i64 (...) @hpctimer_gettsc()
%47 = tail call i64 (...) @hpctimer_gettsc()
%48 = sub nsw i64 %47, %46
%49 = icmp slt i64 %48, %45
%50 = select i1 %49, i64 %48, i64 %45
ret i64 %50
}