#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__ clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ const clock();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
double calls_per_sec(void) {
  static clock_t s_end;
  static int s_iter;
  clock_t const present = clock();
  int const iter = s_iter++;
  if (iter <= 1) {
    if (CLOCKS_PER_SEC < 10) {
      fprintf(stderr, "Not enough clock() resolution\n");
      exit(EXIT_FAILURE);
    }
    while (clock() == present) {
    }
    s_end = clock() + CLOCKS_PER_SEC;
  } else if (present >= s_end) {
    s_iter = 0;
    return (double)(iter - 1) * CLOCKS_PER_SEC /
           (present - s_end + CLOCKS_PER_SEC);
  }
  return 0;
}


x86 assembly (clang, -O0):
<calls_per_sec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    0x2eff(%rip),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,0x2ef4(%rip)
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     11cf <calls_per_sec+0x9f>
mov    0x2e80(%rip),%rax
cmpl   $0xa,(%rax)
jge    1194 <calls_per_sec+0x64>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe7f(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    1199 <calls_per_sec+0x69>
mov    $0x0,%al
call   1030 <clock@plt>
cmp    -0x10(%rbp),%rax
jne    11af <calls_per_sec+0x7f>
jmp    1199 <calls_per_sec+0x69>
mov    $0x0,%al
call   1030 <clock@plt>
mov    0x2e2b(%rip),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
mov    %rax,0x2e76(%rip)
jmp    1233 <calls_per_sec+0x103>
mov    -0x10(%rbp),%rax
cmp    0x2e66(%rip),%rax
jl     122e <calls_per_sec+0xfe>
movl   $0x0,0x2e5e(%rip)
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    0x2ded(%rip),%rax
cvtsi2sdl (%rax),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
sub    0x2e32(%rip),%rax
mov    0x2dd3(%rip),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    123b <calls_per_sec+0x10b>
jmp    1233 <calls_per_sec+0x103>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calls_per_sec>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    0x2f04(%rip),%eax
lea    0x1(%rax),%ecx
mov    %ecx,0x2efb(%rip)
cmp    $0x1,%eax
jg     1186 <calls_per_sec+0x56>
mov    0x2e8f(%rip),%r14
cmpl   $0xa,(%r14)
jl     11d0 <calls_per_sec+0xa0>
nop
xor    %eax,%eax
call   1030 <clock@plt>
cmp    %rbx,%rax
je     1160 <calls_per_sec+0x30>
xor    %eax,%eax
call   1030 <clock@plt>
movslq (%r14),%rcx
add    %rax,%rcx
mov    %rcx,0x2ec0(%rip)
xorpd  %xmm0,%xmm0
jmp    11c8 <calls_per_sec+0x98>
xorpd  %xmm0,%xmm0
sub    0x2eaf(%rip),%rbx
jl     11c8 <calls_per_sec+0x98>
movl   $0x0,0x2eab(%rip)
add    $0xffffffff,%eax
cvtsi2sd %eax,%xmm1
mov    0x2e3d(%rip),%rax
movslq (%rax),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  %xmm1,%xmm0
add    %rax,%rbx
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
divsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
lea    0xe20(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@calls_per_sec.s_end = internal global i64 0
@calls_per_sec.s_iter = internal global i32 0
@CLOCKS_PER_SEC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Not enough clock() resolution\0A\00"
@EXIT_FAILURE = global i32 0
define double @calls_per_sec() {
%1 = alloca double
%2 = alloca i64
%3 = alloca i32
%4 = call i64 (...) @clock()
store i64 %4, i64* %2
%5 = load i32, i32* @calls_per_sec.s_iter
%6 = add nsw i32 %5, 1
store i32 %6, i32* @calls_per_sec.s_iter
store i32 %5, i32* %3
%7 = load i32, i32* %3
%8 = icmp sle i32 %7, 1
br i1 %8, label %9, label %28
9: ; preds = %0
%10 = load i32, i32* @CLOCKS_PER_SEC
%11 = icmp slt i32 %10, 10
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %9
br label %18
18: ; preds = %22, %17
%19 = call i64 (...) @clock()
%20 = load i64, i64* %2
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %18
br label %18
23: ; preds = %18
%24 = call i64 (...) @clock()
%25 = load i32, i32* @CLOCKS_PER_SEC
%26 = sext i32 %25 to i64
%27 = add nsw i64 %24, %26
store i64 %27, i64* @calls_per_sec.s_end
br label %48
28: ; preds = %0
%29 = load i64, i64* %2
%30 = load i64, i64* @calls_per_sec.s_end
%31 = icmp sge i64 %29, %30
br i1 %31, label %32, label %47
32: ; preds = %28
store i32 0, i32* @calls_per_sec.s_iter
%33 = load i32, i32* %3
%34 = sub nsw i32 %33, 1
%35 = sitofp i32 %34 to double
%36 = load i32, i32* @CLOCKS_PER_SEC
%37 = sitofp i32 %36 to double
%38 = fmul double %35, %37
%39 = load i64, i64* %2
%40 = load i64, i64* @calls_per_sec.s_end
%41 = sub nsw i64 %39, %40
%42 = load i32, i32* @CLOCKS_PER_SEC
%43 = sext i32 %42 to i64
%44 = add nsw i64 %41, %43
%45 = sitofp i64 %44 to double
%46 = fdiv double %38, %45
store double %46, double* %1
br label %49
47: ; preds = %28
br label %48
48: ; preds = %47, %23
store double 0.000000e+00, double* %1
br label %49
49: ; preds = %48, %32
%50 = load double, double* %1
ret double %50
}

LLVM IR (-O2):
@calls_per_sec.s_end = internal unnamed_addr global i64 0
@calls_per_sec.s_iter = internal unnamed_addr global i32 0
@CLOCKS_PER_SEC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Not enough clock() resolution\0A\00"
@EXIT_FAILURE = global i32 0
define double @calls_per_sec() {
%1 = tail call i64 (...) @clock()
%2 = load i32, i32* @calls_per_sec.s_iter
%3 = add nsw i32 %2, 1
store i32 %3, i32* @calls_per_sec.s_iter
%4 = icmp slt i32 %2, 2
br i1 %4, label %5, label %21
5: ; preds = %0
%6 = load i32, i32* @CLOCKS_PER_SEC
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %5, %13
%14 = tail call i64 (...) @clock()
%15 = icmp eq i64 %14, %1
br i1 %15, label %13, label %16
16: ; preds = %13
%17 = tail call i64 (...) @clock()
%18 = load i32, i32* @CLOCKS_PER_SEC
%19 = sext i32 %18 to i64
%20 = add nsw i64 %17, %19
store i64 %20, i64* @calls_per_sec.s_end
br label %35
21: ; preds = %0
%22 = load i64, i64* @calls_per_sec.s_end
%23 = icmp slt i64 %1, %22
br i1 %23, label %35, label %24
24: ; preds = %21
store i32 0, i32* @calls_per_sec.s_iter
%25 = add nsw i32 %2, -1
%26 = sitofp i32 %25 to double
%27 = load i32, i32* @CLOCKS_PER_SEC
%28 = sitofp i32 %27 to double
%29 = fmul double %26, %28
%30 = sub i64 %1, %22
%31 = sext i32 %27 to i64
%32 = add nsw i64 %30, %31
%33 = sitofp i64 %32 to double
%34 = fdiv double %29, %33
br label %35
35: ; preds = %16, %21, %24
%36 = phi double [ %34, %24 ], [ 0.000000e+00, %21 ], [ 0.000000e+00, %16 ]
ret double %36
}