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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void bench(double *b) {
  static struct timeval thistime, lasttime;
  static double x = 0;
  static double *lastclock = &x;
  lasttime = thistime;
  gettimeofday(&thistime, NULL);
  *lastclock += (thistime.tv_sec - lasttime.tv_sec) +
                0.000001 * (thistime.tv_usec - lasttime.tv_usec);
  lastclock = b;
}


x86 assembly (clang, -O0):
<bench>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2f15(%rip),%rax
mov    %rax,0x2f1e(%rip)
mov    0x2f0f(%rip),%rax
mov    %rax,0x2f18(%rip)
lea    0x2ef9(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    0x2ef1(%rip),%rax
sub    0x2efa(%rip),%rax
cvtsi2sd %rax,%xmm1
movsd  0x2ed5(%rip),%xmm0
subsd  0x2edd(%rip),%xmm0
movsd  0xe8d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x2ea6(%rip),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x8(%rbp),%rax
mov    %rax,0x2e93(%rip)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bench>:
push   %rbx
mov    %rdi,%rbx
movups 0x2f1d(%rip),%xmm0
movups %xmm0,0x2f26(%rip)
lea    0x2f0f(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f09(%rip),%rax
sub    0x2f12(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x2eea(%rip),%xmm1
subsd  0x2ef2(%rip),%xmm1
mulsd  0xea2(%rip),%xmm1
addsd  %xmm0,%xmm1
mov    0x2ebf(%rip),%rax
addsd  (%rax),%xmm1
movsd  %xmm1,(%rax)
mov    %rbx,0x2eb0(%rip)
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@bench.thistime = internal global %struct.timeval zeroinitializer
@bench.lasttime = internal global %struct.timeval zeroinitializer
@bench.x = internal global double 0.000000e+00
@bench.lastclock = internal global double* @bench.x
define void @bench(double* %0) {
%2 = alloca double*
store double* %0, double** %2
%3 = call i32 @gettimeofday(%struct.timeval* @bench.thistime, i32* null)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.thistime, i32 0, i32 1)
%5 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.lasttime, i32 0, i32 1)
%6 = sub nsw i64 %4, %5
%7 = sitofp i64 %6 to double
%8 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.thistime, i32 0, i32 0)
%9 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.lasttime, i32 0, i32 0)
%10 = fsub double %8, %9
%11 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %10, double %7)
%12 = load double*, double** @bench.lastclock
%13 = load double, double* %12
%14 = fadd double %13, %11
store double %14, double* %12
%15 = load double*, double** %2
store double* %15, double** @bench.lastclock
ret void
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@bench.thistime = internal global %struct.timeval zeroinitializer
@bench.lasttime = internal unnamed_addr global %struct.timeval zeroinitializer
@bench.x = internal global double 0.000000e+00
@bench.lastclock = internal unnamed_addr global double* @bench.x
define void @bench(double* %0) {
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 dereferenceable(16) bitcast (%struct.timeval* @bench.lasttime to i8*), i8* align 8 dereferenceable(16) bitcast (%struct.timeval* @bench.thistime to i8*), i64 16, i1 false)
%2 = tail call i32 @gettimeofday(%struct.timeval* @bench.thistime, i32* null)
%3 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.thistime, i64 0, i32 1)
%4 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.lasttime, i64 0, i32 1)
%5 = sub nsw i64 %3, %4
%6 = sitofp i64 %5 to double
%7 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.thistime, i64 0, i32 0)
%8 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @bench.lasttime, i64 0, i32 0)
%9 = fsub double %7, %8
%10 = tail call double @llvm.fmuladd.f64(double %9, double 0x3EB0C6F7A0B5ED8D, double %6)
%11 = load double*, double** @bench.lastclock
%12 = load double, double* %11
%13 = fadd double %12, %10
store double %13, double* %11
store double* %0, double** @bench.lastclock
ret void
}