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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
double wallclock_time(void) {
  struct timeval s_val;
  static struct timeval b_val;
  double time;
  static int base = 0;
  gettimeofday(&s_val, 0);
  if (!base) {
    b_val = s_val;
    base = 1;
    return 0.0;
  }
  time = (double)(s_val.tv_sec - b_val.tv_sec) +
         (double)(1e-6 * ((double)s_val.tv_usec - (double)b_val.tv_usec));
  return (double)time;
}


x86 assembly (clang, -O0):
<wallclock_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x0,0x2f16(%rip)
jne    115d <wallclock_time+0x4d>
mov    -0x18(%rbp),%rax
mov    %rax,0x2ef5(%rip)
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef2(%rip)
movl   $0x1,0x2ef0(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    119f <wallclock_time+0x8f>
mov    -0x10(%rbp),%rax
sub    0x2ed0(%rip),%rax
cvtsi2sd %rax,%xmm1
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq 0x2eb4(%rip),%xmm2
subsd  %xmm2,%xmm0
movsd  0xe78(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wallclock_time>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cmpb   $0x0,0x2f19(%rip)
je     115f <wallclock_time+0x4f>
mov    0x10(%rsp),%rax
sub    0x2f03(%rip),%rax
cvtsi2sd %rax,%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
cvtsi2sdq 0x2ee6(%rip),%xmm2
subsd  %xmm2,%xmm0
mulsd  0xeaa(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
movups 0x8(%rsp),%xmm0
movups %xmm0,0x2ec5(%rip)
movb   $0x1,0x2ece(%rip)
xorps  %xmm0,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@wallclock_time.b_val = internal global %struct.timeval zeroinitializer
@wallclock_time.base = internal global i32 0
define double @wallclock_time() {
%1 = alloca double
%2 = alloca %struct.timeval
%3 = alloca double
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%5 = load i32, i32* @wallclock_time.base
%6 = icmp ne i32 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %0
%8 = bitcast %struct.timeval* %2 to i8*
store i32 1, i32* @wallclock_time.base
store double 0.000000e+00, double* %1
br label %23
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%11 = load i64, i64* %10
%12 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.b_val, i32 0, i32 1)
%13 = sub nsw i64 %11, %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.b_val, i32 0, i32 0)
%19 = sitofp i64 %18 to double
%20 = fsub double %17, %19
%21 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %20, double %14)
store double %21, double* %3
%22 = load double, double* %3
store double %22, double* %1
br label %23
23: ; preds = %9, %7
%24 = load double, double* %1
ret double %24
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@wallclock_time.b_val = internal unnamed_addr global %struct.timeval zeroinitializer
@wallclock_time.base = internal unnamed_addr global i1 false
define double @wallclock_time() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = load i1, i1* @wallclock_time.base
br i1 %4, label %6, label %5
5: ; preds = %0
store i1 true, i1* @wallclock_time.base
br label %19
6: ; preds = %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i64, i64* %7
%9 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.b_val, i64 0, i32 1)
%10 = sub nsw i64 %8, %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.b_val, i64 0, i32 0)
%16 = sitofp i64 %15 to double
%17 = fsub double %14, %16
%18 = call double @llvm.fmuladd.f64(double %17, double 0x3EB0C6F7A0B5ED8D, double %11)
br label %19
19: ; preds = %6, %5
%20 = phi double [ %18, %6 ], [ 0.000000e+00, %5 ]
ret double %20
}