#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;
};
struct internal_bench {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ abort();
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ run_body(struct internal_bench *, long);
double measure_once(struct internal_bench *b, long iterations) {
  struct timeval tv_before, tv_after;
  int rv;
  double time;
  rv = gettimeofday(&tv_before, NULL);
  if (rv) {
    perror("gettimeofday");
    abort();
  }
  run_body(b, iterations);
  rv = gettimeofday(&tv_after, NULL);
  if (rv) {
    perror("gettimeofday");
    abort();
  }
  tv_after.tv_sec -= tv_before.tv_sec;
  time = tv_after.tv_sec * 1E6 + tv_after.tv_usec;
  time -= tv_before.tv_usec;
  time *= 1000;
  return time;
}


x86 assembly (clang, -O0):
<measure_once>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     117d <measure_once+0x3d>
lea    0xe9f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <run_body@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     11b7 <measure_once+0x77>
lea    0xe65(%rip),%rdi
call   1060 <perror@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%ecx
mov    -0x20(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
cvtsi2sdl -0x20(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
movsd  0xe34(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe04(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<measure_once>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %eax,%eax
jne    11b0 <measure_once+0x70>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <run_body@plt>
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
test   %eax,%eax
jne    11b0 <measure_once+0x70>
mov    0x8(%rsp),%eax
sub    0x10(%rsp),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdl 0xc(%rsp),%xmm1
mulsd  0xe6e(%rip),%xmm0
cvtsi2sdl 0x14(%rsp),%xmm2
addsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
mulsd  0xe60(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe59(%rip),%rdi
call   1060 <perror@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
%struct.internal_bench = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"gettimeofday\00"
define double @measure_once(%struct.internal_bench* %0, i64 %1) {
%3 = alloca %struct.internal_bench*
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca double
store %struct.internal_bench* %0, %struct.internal_bench** %3
store i64 %1, i64* %4
%9 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%14 = call i32 (...) @abort()
unreachable
15: ; preds = %2
%16 = load %struct.internal_bench*, %struct.internal_bench** %3
%17 = load i64, i64* %4
%18 = call i32 @run_body(%struct.internal_bench* %16, i64 %17)
%19 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%24 = call i32 (...) @abort()
unreachable
25: ; preds = %15
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sub nsw i32 %29, %27
store i32 %30, i32* %28
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%32 = load i32, i32* %31
%33 = sitofp i32 %32 to double
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%35 = load i32, i32* %34
%36 = sitofp i32 %35 to double
%37 = call double @llvm.fmuladd.f64(double %33, double 1.000000e+06, double %36)
store double %37, double* %8
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%39 = load i32, i32* %38
%40 = sitofp i32 %39 to double
%41 = load double, double* %8
%42 = fsub double %41, %40
store double %42, double* %8
%43 = load double, double* %8
%44 = fmul double %43, 1.000000e+03
store double %44, double* %8
%45 = load double, double* %8
ret double %45
}

LLVM IR (-O2):
%struct.internal_bench = type { i32 }
%struct.timeval = type { i32, i32 }
@.str = [13 x i8] c"gettimeofday\00"
define double @measure_once(%struct.internal_bench* %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 (...) @abort()
unreachable
12: ; preds = %2
%13 = tail call i32 @run_body(%struct.internal_bench* %0, i64 %1)
%14 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%15 = icmp eq i32 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = tail call i32 (...) @abort()
unreachable
19: ; preds = %12
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%23 = load i32, i32* %22
%24 = sub nsw i32 %23, %21
%25 = sitofp i32 %24 to double
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%27 = load i32, i32* %26
%28 = sitofp i32 %27 to double
%29 = tail call double @llvm.fmuladd.f64(double %25, double 1.000000e+06, double %28)
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%31 = load i32, i32* %30
%32 = sitofp i32 %31 to double
%33 = fsub double %29, %32
%34 = fmul double %33, 1.000000e+03
ret double %34
}