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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double wallclock_time(void) {
  struct timeval now;
  static struct timeval tv0;
  gettimeofday(&now, NULL);
  if (tv0.tv_sec == 0)
    tv0 = now;
  return (now.tv_sec - tv0.tv_sec) + 1e-6 * (now.tv_usec - tv0.tv_usec);
}


x86 assembly (clang, -O0):
<wallclock_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpq   $0x0,0x2f03(%rip)
jne    1149 <wallclock_time+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef2(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2eef(%rip)
mov    -0x10(%rbp),%rax
sub    0x2edc(%rip),%rax
cvtsi2sd %rax,%xmm1
mov    -0x8(%rbp),%eax
sub    0x2ed6(%rip),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe92(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wallclock_time>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f09(%rip),%rax
test   %rax,%rax
jne    113f <wallclock_time+0x2f>
movups 0x8(%rsp),%xmm0
movups %xmm0,0x2ef8(%rip)
mov    0x2ef1(%rip),%rax
mov    0x8(%rsp),%rcx
sub    %rax,%rcx
cvtsi2sd %rcx,%xmm1
mov    0x10(%rsp),%eax
sub    0x2ee2(%rip),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0xe9b(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
@wallclock_time.tv0 = internal global %struct.timeval zeroinitializer
define double @wallclock_time() {
%1 = alloca %struct.timeval
%2 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%3 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.tv0, i32 0, i32 0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = bitcast %struct.timeval* %1 to i8*
br label %7
7: ; preds = %5, %0
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.tv0, i32 0, i32 0)
%11 = sub nsw i64 %9, %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @wallclock_time.tv0, i32 0, i32 1)
%16 = sub nsw i32 %14, %15
%17 = sitofp i32 %16 to double
%18 = call double @llvm.fmuladd.f64(double 0x3EB0C6F7A0B5ED8D, double %17, double %12)
ret double %18
}

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