#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 read_timer() {
  static int initialized = 0;
  static struct timeval start;
  struct timeval end;
  if (!initialized) {
    gettimeofday(&start, NULL);
    initialized = 1;
  }
  gettimeofday(&end, NULL);
  return (end.tv_sec - start.tv_sec) + 1.0e-6 * (end.tv_usec - start.tv_usec);
}


x86 assembly (clang, -O0):
<read_timer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2f11(%rip)
jne    113f <read_timer+0x2f>
lea    0x2f0c(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movl   $0x1,0x2ef1(%rip)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movsd  -0x10(%rbp),%xmm1
subsd  0x2edf(%rip),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  0x2eda(%rip),%xmm0
movsd  0xe92(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_timer>:
sub    $0x18,%rsp
cmpb   $0x0,0x2f15(%rip)
jne    1132 <read_timer+0x22>
lea    0x2f14(%rip),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movb   $0x1,0x2efe(%rip)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x8(%rsp),%xmm1
movsd  0x10(%rsp),%xmm0
subsd  0x2ee6(%rip),%xmm1
subsd  0x2ee6(%rip),%xmm0
mulsd  0xe9e(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@read_timer.initialized = internal global i32 0
@read_timer.start = internal global %struct.timeval zeroinitializer
define double @read_timer() {
%1 = alloca %struct.timeval
%2 = load i32, i32* @read_timer.initialized
%3 = icmp ne i32 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = call i32 @gettimeofday(%struct.timeval* @read_timer.start, i32* null)
store i32 1, i32* @read_timer.initialized
br label %6
6: ; preds = %4, %0
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%9 = load double, double* %8
%10 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @read_timer.start, i32 0, i32 0)
%11 = fsub double %9, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%13 = load double, double* %12
%14 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @read_timer.start, i32 0, i32 1)
%15 = fsub double %13, %14
%16 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %15, double %11)
ret double %16
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@read_timer.initialized = internal unnamed_addr global i1 false
@read_timer.start = internal global %struct.timeval zeroinitializer
define double @read_timer() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = load i1, i1* @read_timer.initialized
br i1 %3, label %6, label %4
4: ; preds = %0
%5 = tail call i32 @gettimeofday(%struct.timeval* @read_timer.start, i32* null)
store i1 true, i1* @read_timer.initialized
br label %6
6: ; preds = %4, %0
%7 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load double, double* %8
%10 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @read_timer.start, i64 0, i32 0)
%11 = fsub double %9, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%13 = load double, double* %12
%14 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @read_timer.start, i64 0, i32 1)
%15 = fsub double %13, %14
%16 = tail call double @llvm.fmuladd.f64(double %15, double 0x3EB0C6F7A0B5ED8D, double %11)
ret double %16
}