#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 get_timer();
int /*<<< orphan*/ printf(char *, int, double, int);
int /*<<< orphan*/ start_timer();
void run_timer() {
  int i = 0;
  double t1, t2, t3, t4;
  start_timer();
  t1 = get_timer();
  do {
    t2 = get_timer();
  } while (t2 == t1);
  do {
    t3 = get_timer();
    i++;
  } while (t3 == t2);
  printf("Time = %f usecs, in %d iterations, %f usec/iteration\n",
         1e6 * (t3 - t2), i, 1e6 * (t3 - t2) / i);
  start_timer();
  i = 0;
  do {
    t4 = get_timer();
    i++;
  } while (t4 < 1.0);
  printf("%d iterations in %f secs = %f usec/iteration\n", i, t4, 1e6 * t4 / i);
}


x86 assembly (clang, -O0):
<run_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <start_timer@plt>
mov    $0x0,%al
call   1040 <get_timer@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <get_timer@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1179 <run_timer+0x49>
jp     1179 <run_timer+0x49>
jmp    1152 <run_timer+0x22>
jmp    117e <run_timer+0x4e>
mov    $0x0,%al
call   1040 <get_timer@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    11ae <run_timer+0x7e>
jp     11ae <run_timer+0x7e>
jmp    117e <run_timer+0x4e>
movsd  -0x20(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  0xe40(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%esi
cvtsi2sdl -0x4(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  0xe21(%rip),%xmm1
mulsd  %xmm2,%xmm1
cvtsi2sdl -0x4(%rbp),%xmm2
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edx
lea    0xe19(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <start_timer@plt>
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1040 <get_timer@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movsd  0xde1(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
ja     120a <run_timer+0xda>
mov    -0x4(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  0xdbe(%rip),%xmm1
mulsd  -0x28(%rbp),%xmm1
cvtsi2sdl -0x4(%rbp),%xmm2
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edx
lea    0xdeb(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_timer>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <start_timer@plt>
xor    %eax,%eax
call   1040 <get_timer@plt>
movsd  %xmm0,(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <get_timer@plt>
ucomisd (%rsp),%xmm0
jne    1160 <run_timer+0x30>
jnp    1150 <run_timer+0x20>
movapd %xmm0,%xmm1
xor    %ebx,%ebx
movsd  %xmm0,0x8(%rsp)
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <get_timer@plt>
movsd  0x8(%rsp),%xmm1
add    $0x1,%ebx
ucomisd %xmm1,%xmm0
jne    1188 <run_timer+0x58>
jnp    1170 <run_timer+0x40>
subsd  %xmm1,%xmm0
mulsd  0xe6c(%rip),%xmm0
cvttsd2si %xmm0,%esi
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
lea    0xe62(%rip),%rdi
movapd %xmm1,%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <start_timer@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <get_timer@plt>
add    $0x1,%ebx
movsd  0xe36(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     11c0 <run_timer+0x90>
movapd %xmm0,%xmm1
mulsd  0xe1c(%rip),%xmm1
cvtsi2sd %ebx,%xmm2
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edx
lea    0xe4f(%rip),%rdi
mov    %ebx,%esi
add    $0x10,%rsp
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [54 x i8] c"Time = %f usecs, in %d iterations, %f usec/iteration\0A\00"
@.str.1 = [46 x i8] c"%d iterations in %f secs = %f usec/iteration\0A\00"
define void @run_timer() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store i32 0, i32* %1
%6 = call i32 (...) @start_timer()
%7 = call double (...) @get_timer()
store double %7, double* %2
br label %8
8: ; preds = %10, %0
%9 = call double (...) @get_timer()
store double %9, double* %3
br label %10
10: ; preds = %8
%11 = load double, double* %3
%12 = load double, double* %2
%13 = fcmp oeq double %11, %12
br i1 %13, label %8, label %14
14: ; preds = %10
br label %15
15: ; preds = %19, %14
%16 = call double (...) @get_timer()
store double %16, double* %4
%17 = load i32, i32* %1
%18 = add nsw i32 %17, 1
store i32 %18, i32* %1
br label %19
19: ; preds = %15
%20 = load double, double* %4
%21 = load double, double* %3
%22 = fcmp oeq double %20, %21
br i1 %22, label %15, label %23
23: ; preds = %19
%24 = load double, double* %4
%25 = load double, double* %3
%26 = fsub double %24, %25
%27 = fmul double 1.000000e+06, %26
%28 = fptosi double %27 to i32
%29 = load i32, i32* %1
%30 = sitofp i32 %29 to double
%31 = load double, double* %4
%32 = load double, double* %3
%33 = fsub double %31, %32
%34 = fmul double 1.000000e+06, %33
%35 = load i32, i32* %1
%36 = sitofp i32 %35 to double
%37 = fdiv double %34, %36
%38 = fptosi double %37 to i32
%39 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %28, double %30, i32 %38)
%40 = call i32 (...) @start_timer()
store i32 0, i32* %1
br label %41
41: ; preds = %45, %23
%42 = call double (...) @get_timer()
store double %42, double* %5
%43 = load i32, i32* %1
%44 = add nsw i32 %43, 1
store i32 %44, i32* %1
br label %45
45: ; preds = %41
%46 = load double, double* %5
%47 = fcmp olt double %46, 1.000000e+00
br i1 %47, label %41, label %48
48: ; preds = %45
%49 = load i32, i32* %1
%50 = load double, double* %5
%51 = load double, double* %5
%52 = fmul double 1.000000e+06, %51
%53 = load i32, i32* %1
%54 = sitofp i32 %53 to double
%55 = fdiv double %52, %54
%56 = fptosi double %55 to i32
%57 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %49, double %50, i32 %56)
ret void
}

LLVM IR (-O2):
@.str = [54 x i8] c"Time = %f usecs, in %d iterations, %f usec/iteration\0A\00"
@.str.1 = [46 x i8] c"%d iterations in %f secs = %f usec/iteration\0A\00"
define void @run_timer() {
%1 = tail call i32 (...) @start_timer()
%2 = tail call double (...) @get_timer()
br label %3
3: ; preds = %3, %0
%4 = tail call double (...) @get_timer()
%5 = fcmp oeq double %4, %2
br i1 %5, label %3, label %6
6: ; preds = %3, %6
%7 = phi i32 [ %9, %6 ], [ 0, %3 ]
%8 = tail call double (...) @get_timer()
%9 = add nuw nsw i32 %7, 1
%10 = fcmp oeq double %8, %4
br i1 %10, label %6, label %11
11: ; preds = %6
%12 = fsub double %8, %4
%13 = fmul double %12, 1.000000e+06
%14 = fptosi double %13 to i32
%15 = sitofp i32 %9 to double
%16 = fdiv double %13, %15
%17 = fptosi double %16 to i32
%18 = tail call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %14, double %15, i32 %17)
%19 = tail call i32 (...) @start_timer()
br label %20
20: ; preds = %20, %11
%21 = phi i32 [ 0, %11 ], [ %23, %20 ]
%22 = tail call double (...) @get_timer()
%23 = add nuw nsw i32 %21, 1
%24 = fcmp olt double %22, 1.000000e+00
br i1 %24, label %20, label %25
25: ; preds = %20
%26 = fmul double %22, 1.000000e+06
%27 = sitofp i32 %23 to double
%28 = fdiv double %26, %27
%29 = fptosi double %28 to i32
%30 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %23, double %22, i32 %29)
ret void
}