#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 */
struct timeval {
  long tv_usec;
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
float timeit(void (*func)(long)) {
  long count, elapsed;
  struct timeval start, end;
  count = 10;
  while (1) {
    gettimeofday(&start, NULL);
    func(count);
    gettimeofday(&end, NULL);
    elapsed = end.tv_usec - start.tv_usec;
    elapsed += 1000000 * (end.tv_sec - start.tv_sec);
    if (elapsed > 1000000)
      break;
    count *= 2;
  }
  return 1000000.0 * count / elapsed;
}


x86 assembly (clang, -O0):
<timeit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0xa,-0x10(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
lea    -0x38(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x30(%rbp),%eax
sub    -0x20(%rbp),%eax
imul   $0xf4240,%eax,%eax
cltq
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0xf4240,-0x18(%rbp)
jle    117d <timeit+0x6d>
jmp    118e <timeit+0x7e>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1124 <timeit+0x14>
cvtsi2sdq -0x10(%rbp),%xmm1
movsd  0xe64(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeit>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r12
mov    $0xa,%ecx
lea    0x18(%rsp),%r14
lea    0x8(%rsp),%r15
nopl   (%rax)
mov    %rcx,%rbx
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
call   *%r12
mov    %r15,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rcx
sub    0x18(%rsp),%rcx
movslq 0x10(%rsp),%rax
movslq 0x20(%rsp),%rdx
sub    %rdx,%rax
imul   $0xf4240,%rax,%rax
add    %rcx,%rax
lea    (%rbx,%rbx,1),%rcx
cmp    $0xf4241,%rax
jl     1130 <timeit+0x20>
cvtsi2sd %rbx,%xmm0
mulsd  0xe79(%rip),%xmm0
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define float @timeit(void (i64)* %0) {
%2 = alloca void (i64)*
%3 = alloca i64
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
store void (i64)* %0, void (i64)** %2
store i64 10, i64* %3
br label %7
7: ; preds = %1, %29
%8 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%9 = load void (i64)*, void (i64)** %2
%10 = load i64, i64* %3
%11 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%15 = load i64, i64* %14
%16 = sub nsw i64 %13, %15
store i64 %16, i64* %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%20 = load i32, i32* %19
%21 = sub nsw i32 %18, %20
%22 = mul nsw i32 1000000, %21
%23 = sext i32 %22 to i64
%24 = load i64, i64* %4
%25 = add nsw i64 %24, %23
store i64 %25, i64* %4
%26 = load i64, i64* %4
%27 = icmp sgt i64 %26, 1000000
br i1 %27, label %28, label %29
28: ; preds = %7
br label %32
29: ; preds = %7
%30 = load i64, i64* %3
%31 = mul nsw i64 %30, 2
store i64 %31, i64* %3
br label %7
32: ; preds = %28
%33 = load i64, i64* %3
%34 = sitofp i64 %33 to double
%35 = fmul double 1.000000e+06, %34
%36 = load i64, i64* %4
%37 = sitofp i64 %36 to double
%38 = fdiv double %35, %37
%39 = fptrunc double %38 to float
ret float %39
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define float @timeit(void (i64)* nocapture %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
br label %10
10: ; preds = %10, %1
%11 = phi i64 [ 10, %1 ], [ %24, %10 ]
%12 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
tail call void %0(i64 %11)
%13 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%14 = load i64, i64* %6
%15 = load i64, i64* %7
%16 = sub nsw i64 %14, %15
%17 = load i32, i32* %8
%18 = load i32, i32* %9
%19 = sub nsw i32 %17, %18
%20 = mul nsw i32 %19, 1000000
%21 = sext i32 %20 to i64
%22 = add nsw i64 %16, %21
%23 = icmp sgt i64 %22, 1000000
%24 = shl nsw i64 %11, 1
br i1 %23, label %25, label %10
25: ; preds = %10
%26 = sitofp i64 %11 to double
%27 = fmul double %26, 1.000000e+06
%28 = sitofp i64 %22 to double
%29 = fdiv double %27, %28
%30 = fptrunc double %29 to float
ret float %30
}