#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 {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, unsigned long long);
unsigned long long rdtsc_ll();
int main() {
  unsigned long long start, stop;
  struct timeval begin, end;
  unsigned long tmp;
  int i;
  start = rdtsc_ll();
  gettimeofday(&begin, NULL);
  for (i = 0; i < 1000000; i++) {
  }
  stop = rdtsc_ll();
  gettimeofday(&end, NULL);
  tmp = (end.tv_sec - begin.tv_sec) * 1000000 + (end.tv_usec - begin.tv_usec);
  printf("%.2f\n", (stop - start) / (tmp * 1000.0));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1050 <rdtsc_ll@plt>
mov    %rax,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xf4240,-0x34(%rbp)
jge    117e <main+0x4e>
jmp    1170 <main+0x40>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    115e <main+0x2e>
xor    %eax,%eax
mov    %eax,-0x38(%rbp)
call   1050 <rdtsc_ll@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%eax
mov    %rcx,-0x18(%rbp)
mov    %eax,%esi
lea    -0x28(%rbp),%rdi
call   1040 <gettimeofday@plt>
mov    -0x28(%rbp),%eax
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%esi
mov    -0x1c(%rbp),%edx
sub    %esi,%eax
imul   $0xf4240,%eax,%eax
sub    %edx,%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movq   %rax,%xmm0
movaps 0xe2e(%rip),%xmm3
punpckldq %xmm3,%xmm0
movapd 0xe32(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x30(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe13(%rip),%xmm2
mulsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rsi
mov    %rsi,%rcx
sar    $0x3f,%rcx
movsd  0xdfc(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
and    %rcx,%rax
or     %rax,%rsi
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <rdtsc_ll@plt>
mov    %rax,%r14
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
xor    %eax,%eax
call   1050 <rdtsc_ll@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%eax
sub    0x10(%rsp),%eax
mov    0xc(%rsp),%ecx
imul   $0xf4240,%eax,%eax
sub    0x14(%rsp),%ecx
add    %eax,%ecx
movslq %ecx,%rax
sub    %r14,%rbx
movq   %rbx,%xmm0
movdqa 0xe72(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xe76(%rip),%xmm2
subpd  %xmm2,%xmm0
movq   %rax,%xmm3
punpckldq %xmm1,%xmm3
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
subpd  %xmm2,%xmm3
movapd %xmm3,%xmm2
unpckhpd %xmm3,%xmm2
addsd  %xmm3,%xmm2
mulsd  0xe59(%rip),%xmm2
addsd  %xmm0,%xmm1
divsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rcx
sar    $0x3f,%rcx
subsd  0xe45(%rip),%xmm1
cvttsd2si %xmm1,%rsi
and    %rcx,%rsi
or     %rax,%rsi
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%.2f\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca i64
%7 = alloca i32
store i32 0, i32* %1
%8 = call i64 (...) @rdtsc_ll()
store i64 %8, i64* %2
%9 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
store i32 0, i32* %7
br label %10
10: ; preds = %14, %0
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 1000000
br i1 %12, label %13, label %17
13: ; preds = %10
br label %14
14: ; preds = %13
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
br label %10
17: ; preds = %10
%18 = call i64 (...) @rdtsc_ll()
store i64 %18, i64* %3
%19 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %21, %23
%25 = mul nsw i32 %24, 1000000
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%29 = load i32, i32* %28
%30 = sub nsw i32 %27, %29
%31 = add nsw i32 %25, %30
%32 = sext i32 %31 to i64
store i64 %32, i64* %6
%33 = load i64, i64* %3
%34 = load i64, i64* %2
%35 = sub i64 %33, %34
%36 = uitofp i64 %35 to double
%37 = load i64, i64* %6
%38 = uitofp i64 %37 to double
%39 = fmul double %38, 1.000000e+03
%40 = fdiv double %36, %39
%41 = fptoui double %40 to i64
%42 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %41)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@.str = [6 x i8] c"%.2f\0A\00"
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = tail call i64 (...) @rdtsc_ll()
%6 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%7 = tail call i64 (...) @rdtsc_ll()
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = mul nsw i32 %13, 1000000
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = sub i32 %16, %18
%20 = add nsw i32 %19, %14
%21 = sext i32 %20 to i64
%22 = sub i64 %7, %5
%23 = uitofp i64 %22 to double
%24 = uitofp i64 %21 to double
%25 = fmul double %24, 1.000000e+03
%26 = fdiv double %23, %25
%27 = fptoui double %26 to i64
%28 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i64 %27)
ret i32 0
}