#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_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double timer() {
  static double last_call = 0;
  static struct timeval arg;
  gettimeofday(&arg, NULL);
  double ret = arg.tv_sec * 1000.0 + arg.tv_usec / 1000.0 - last_call;
  last_call = arg.tv_sec * 1000.0 + arg.tv_usec / 1000.0;
  return ret;
}


x86 assembly (clang, -O0):
<timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0x2f19(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f08(%rip),%xmm0
movsd  0x2f08(%rip),%xmm1
movsd  0xec0(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xeb4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  0x2ed4(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  0x2ecf(%rip),%xmm0
movsd  0x2ecf(%rip),%xmm1
movsd  0xe87(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe7b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,0x2e9b(%rip)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer>:
push   %rax
lea    0x2f20(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f19(%rip),%xmm0
movsd  0xed1(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  0x2efd(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
subsd  0x2ee5(%rip),%xmm0
movsd  %xmm1,0x2edd(%rip)
pop    %rax
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@timer.last_call = internal global double 0.000000e+00
@timer.arg = internal global %struct.timeval zeroinitializer
define double @timer() {
%1 = alloca double
%2 = call i32 @gettimeofday(%struct.timeval* @timer.arg, i32* null)
%3 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i32 0, i32 0)
%4 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i32 0, i32 1)
%5 = fdiv double %4, 1.000000e+03
%6 = call double @llvm.fmuladd.f64(double %3, double 1.000000e+03, double %5)
%7 = load double, double* @timer.last_call
%8 = fsub double %6, %7
store double %8, double* %1
%9 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i32 0, i32 0)
%10 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i32 0, i32 1)
%11 = fdiv double %10, 1.000000e+03
%12 = call double @llvm.fmuladd.f64(double %9, double 1.000000e+03, double %11)
store double %12, double* @timer.last_call
%13 = load double, double* %1
ret double %13
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@timer.last_call = internal unnamed_addr global double 0.000000e+00
@timer.arg = internal global %struct.timeval zeroinitializer
define double @timer() {
%1 = tail call i32 @gettimeofday(%struct.timeval* @timer.arg, i32* null)
%2 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i64 0, i32 0)
%3 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @timer.arg, i64 0, i32 1)
%4 = fdiv double %3, 1.000000e+03
%5 = tail call double @llvm.fmuladd.f64(double %2, double 1.000000e+03, double %4)
%6 = load double, double* @timer.last_call
%7 = fsub double %5, %6
store double %5, double* @timer.last_call
ret double %7
}