#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*/ access_counter(unsigned int *, unsigned int *);
double cycle_time(int start_end) {
  static unsigned int lo1, hi1, lo2, hi2;
  unsigned ulo, uhi, borrow;
  double t;
  if (start_end == 0) {
    access_counter(&hi1, &lo1);
    return 0;
  } else {
    access_counter(&hi2, &lo2);
    ulo = lo2 - lo1;
    borrow = ulo > lo2;
    uhi = hi2 - hi1 - borrow;
    t = (double)uhi * (1 << 30) * 4 + ulo;
    return t;
  }
}


x86 assembly (clang, -O0):
<cycle_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1145 <cycle_time+0x35>
lea    0x2f04(%rip),%rdi
lea    0x2ef9(%rip),%rsi
call   1030 <access_counter@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11ce <cycle_time+0xbe>
lea    0x2eec(%rip),%rdi
lea    0x2ee1(%rip),%rsi
call   1030 <access_counter@plt>
mov    0x2ed6(%rip),%eax
mov    0x2ec8(%rip),%ecx
sub    %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    0x2ec2(%rip),%ecx
sub    %ecx,%eax
seta   %al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
mov    0x2eb5(%rip),%eax
mov    0x2ea7(%rip),%ecx
sub    %ecx,%eax
mov    -0x18(%rbp),%ecx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xe65(%rip),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%eax
cvtsi2sd %rax,%xmm1
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cycle_time>:
push   %rax
test   %edi,%edi
je     1160 <cycle_time+0x50>
lea    0x2f1c(%rip),%rdi
lea    0x2f11(%rip),%rsi
call   1030 <access_counter@plt>
mov    0x2f06(%rip),%eax
sub    0x2ef8(%rip),%eax
mov    0x2efe(%rip),%ecx
sbb    0x2ef0(%rip),%ecx
cvtsi2sd %rcx,%xmm0
mulsd  0xeb3(%rip),%xmm0
cvtsi2sd %rax,%xmm1
mulsd  0xeae(%rip),%xmm0
addsd  %xmm1,%xmm0
pop    %rax
ret
lea    0x2ec9(%rip),%rdi
lea    0x2ebe(%rip),%rsi
call   1030 <access_counter@plt>
xorps  %xmm0,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@cycle_time.lo1 = internal global i32 0
@cycle_time.hi1 = internal global i32 0
@cycle_time.lo2 = internal global i32 0
@cycle_time.hi2 = internal global i32 0
define double @cycle_time(i32 %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = call i32 @access_counter(i32* @cycle_time.hi1, i32* @cycle_time.lo1)
store double 0.000000e+00, double* %2
br label %33
12: ; preds = %1
%13 = call i32 @access_counter(i32* @cycle_time.hi2, i32* @cycle_time.lo2)
%14 = load i32, i32* @cycle_time.lo2
%15 = load i32, i32* @cycle_time.lo1
%16 = sub i32 %14, %15
store i32 %16, i32* %4
%17 = load i32, i32* %4
%18 = load i32, i32* @cycle_time.lo2
%19 = icmp ugt i32 %17, %18
%20 = zext i1 %19 to i32
store i32 %20, i32* %6
%21 = load i32, i32* @cycle_time.hi2
%22 = load i32, i32* @cycle_time.hi1
%23 = sub i32 %21, %22
%24 = load i32, i32* %6
%25 = sub i32 %23, %24
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = uitofp i32 %26 to double
%28 = fmul double %27, 0x41D0000000000000
%29 = load i32, i32* %4
%30 = uitofp i32 %29 to double
%31 = call double @llvm.fmuladd.f64(double %28, double 4.000000e+00, double %30)
store double %31, double* %7
%32 = load double, double* %7
store double %32, double* %2
br label %33
33: ; preds = %12, %10
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@cycle_time.lo1 = internal global i32 0
@cycle_time.hi1 = internal global i32 0
@cycle_time.lo2 = internal global i32 0
@cycle_time.hi2 = internal global i32 0
define double @cycle_time(i32 %0) {
%2 = icmp eq i32 %0, 0
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @access_counter(i32* @cycle_time.hi1, i32* @cycle_time.lo1)
br label %20
5: ; preds = %1
%6 = tail call i32 @access_counter(i32* @cycle_time.hi2, i32* @cycle_time.lo2)
%7 = load i32, i32* @cycle_time.lo2
%8 = load i32, i32* @cycle_time.lo1
%9 = sub i32 %7, %8
%10 = icmp ult i32 %7, %8
%11 = sext i1 %10 to i32
%12 = load i32, i32* @cycle_time.hi2
%13 = load i32, i32* @cycle_time.hi1
%14 = sub i32 %12, %13
%15 = add i32 %14, %11
%16 = uitofp i32 %15 to double
%17 = fmul double %16, 0x41D0000000000000
%18 = uitofp i32 %9 to double
%19 = tail call double @llvm.fmuladd.f64(double %17, double 4.000000e+00, double %18)
br label %20
20: ; preds = %5, %3
%21 = phi double [ 0.000000e+00, %3 ], [ %19, %5 ]
ret double %21
}