#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 int /*<<< orphan*/ uint8_t;
struct timeval {
  scalar_t__ tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double measure(void (*func)(volatile uint8_t *, size_t), volatile uint8_t *ptr,
               size_t size) {
  struct timeval t1;
  struct timeval t2;
  struct timeval t;
  double speed;
  gettimeofday(&t1, NULL);
  func(ptr, size);
  gettimeofday(&t2, NULL);
  t.tv_sec = t2.tv_sec - t1.tv_sec;
  if (t1.tv_sec > t2.tv_sec) {
    t.tv_sec--;
    t.tv_usec = 1000000.0 - t1.tv_usec + t2.tv_usec;
  } else {
    t.tv_usec = t2.tv_usec - t1.tv_usec;
  }
  speed = ((double)1000 / ((double)t.tv_sec * 1000000.0 + (double)t.tv_usec)) *
          1000000.0;
  return speed;
}


x86 assembly (clang, -O0):
<measure>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
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,-0x48(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x38(%rbp),%rax
jle    118e <measure+0x7e>
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
movsd  0xe86(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    119d <measure+0x8d>
movsd  -0x30(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvtsi2sdq -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
movsd  0xe50(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe48(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  0xe34(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   *%r15
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%rax
sub    0x10(%rsp),%rax
jge    1166 <measure+0x56>
add    $0xffffffffffffffff,%rax
movsd  0xea8(%rip),%xmm0
subsd  0x18(%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
jmp    1172 <measure+0x62>
movsd  0x8(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
cvtsi2sd %rax,%xmm1
movsd  0xe81(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  0xe79(%rip),%xmm0
divsd  %xmm1,%xmm0
mulsd  %xmm2,%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, double }
define double @measure(void (i32*, i64)* %0, i32* %1, i64 %2) {
%4 = alloca void (i32*, i64)*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca %struct.timeval
%8 = alloca %struct.timeval
%9 = alloca %struct.timeval
%10 = alloca double
store void (i32*, i64)* %0, void (i32*, i64)** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%11 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%12 = load void (i32*, i64)*, void (i32*, i64)** %4
%13 = load i32*, i32** %5
%14 = load i64, i64* %6
%15 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%19 = load i64, i64* %18
%20 = sub nsw i64 %17, %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
store i64 %20, i64* %21
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%25 = load i64, i64* %24
%26 = icmp sgt i64 %23, %25
br i1 %26, label %27, label %38
27: ; preds = %3
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%29 = load i64, i64* %28
%30 = add nsw i64 %29, -1
store i64 %30, i64* %28
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%32 = load double, double* %31
%33 = fsub double 1.000000e+06, %32
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%35 = load double, double* %34
%36 = fadd double %33, %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store double %36, double* %37
br label %45
38: ; preds = %3
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%40 = load double, double* %39
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%42 = load double, double* %41
%43 = fsub double %40, %42
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
store double %43, double* %44
br label %45
45: ; preds = %38, %27
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to double
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 1
%50 = load double, double* %49
%51 = call double @llvm.fmuladd.f64(double %48, double 1.000000e+06, double %50)
%52 = fdiv double 1.000000e+03, %51
%53 = fmul double %52, 1.000000e+06
store double %53, double* %10
%54 = load double, double* %10
ret double %54
}

LLVM IR (-O2):
%struct.timeval = type { i64, double }
define double @measure(void (i32*, i64)* nocapture %0, i32* %1, i64 %2) {
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %4 to i8*
%7 = bitcast %struct.timeval* %5 to i8*
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
tail call void %0(i32* %1, i64 %2)
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sub nsw i64 %11, %13
%15 = icmp slt i64 %11, %13
br i1 %15, label %16, label %24
16: ; preds = %3
%17 = add nsw i64 %14, -1
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%19 = load double, double* %18
%20 = fsub double 1.000000e+06, %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%22 = load double, double* %21
%23 = fadd double %20, %22
br label %30
24: ; preds = %3
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 1
%26 = load double, double* %25
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%28 = load double, double* %27
%29 = fsub double %26, %28
br label %30
30: ; preds = %24, %16
%31 = phi i64 [ %17, %16 ], [ %14, %24 ]
%32 = phi double [ %23, %16 ], [ %29, %24 ]
%33 = sitofp i64 %31 to double
%34 = tail call double @llvm.fmuladd.f64(double %33, double 1.000000e+06, double %32)
%35 = fdiv double 1.000000e+03, %34
%36 = fmul double %35, 1.000000e+06
ret double %36
}