#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 get_counter();
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ start_counter();
double mhz_full(int verbose, int sleeptime) {
  double rate;
  start_counter();
  sleep(sleeptime);
  rate = get_counter() / (1e6 * sleeptime);
  if (verbose)
    printf("Processor clock rate ~= %.1f MHz\n", rate);
  return rate;
}


x86 assembly (clang, -O0):
<mhz_full>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <start_counter@plt>
mov    -0x8(%rbp),%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1050 <get_counter@plt>
cvtsi2sd %eax,%xmm0
cvtsi2sdl -0x8(%rbp),%xmm2
movsd  0xe8b(%rip),%xmm1
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     119d <mhz_full+0x5d>
movsd  -0x10(%rbp),%xmm0
lea    0xe70(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mhz_full>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %eax,%eax
call   1030 <start_counter@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1050 <get_counter@plt>
cvtsi2sd %eax,%xmm0
cvtsi2sd %ebx,%xmm1
mulsd  0xe94(%rip),%xmm1
divsd  %xmm1,%xmm0
test   %ebp,%ebp
je     118a <mhz_full+0x4a>
lea    0xe8d(%rip),%rdi
movsd  %xmm0,(%rsp)
call   1040 <printf@plt>
movsd  (%rsp),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Processor clock rate ~= %.1f MHz\0A\00"
define double @mhz_full(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = call i32 (...) @start_counter()
%7 = load i32, i32* %4
%8 = call i32 @sleep(i32 %7)
%9 = call i32 (...) @get_counter()
%10 = sitofp i32 %9 to double
%11 = load i32, i32* %4
%12 = sitofp i32 %11 to double
%13 = fmul double 1.000000e+06, %12
%14 = fdiv double %10, %13
store double %14, double* %5
%15 = load i32, i32* %3
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load double, double* %5
%19 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %18)
br label %20
20: ; preds = %17, %2
%21 = load double, double* %5
ret double %21
}

LLVM IR (-O2):
@.str = [34 x i8] c"Processor clock rate ~= %.1f MHz\0A\00"
define double @mhz_full(i32 %0, i32 %1) {
%3 = tail call i32 (...) @start_counter()
%4 = tail call i32 @sleep(i32 %1)
%5 = tail call i32 (...) @get_counter()
%6 = sitofp i32 %5 to double
%7 = sitofp i32 %1 to double
%8 = fmul double %7, 1.000000e+06
%9 = fdiv double %6, %8
%10 = icmp eq i32 %0, 0
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %9)
br label %13
13: ; preds = %11, %2
ret double %9
}