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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
double elapsed_realtime(void) {
  static struct timeval t0;
  struct timeval tv;
  gettimeofday(&tv, 0);
  if (!t0.tv_sec)
    t0 = tv;
  return tv.tv_sec - t0.tv_sec + (tv.tv_usec - t0.tv_usec) / 1000000.;
}


x86 assembly (clang, -O0):
<elapsed_realtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f05(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1154 <elapsed_realtime+0x44>
jp     1154 <elapsed_realtime+0x44>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ee7(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2ee4(%rip)
movsd  -0x10(%rbp),%xmm0
subsd  0x2ecf(%rip),%xmm0
mov    -0x8(%rbp),%eax
sub    0x2ece(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe8a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_realtime>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f08(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    114a <elapsed_realtime+0x3a>
jp     114a <elapsed_realtime+0x3a>
movupd 0x8(%rsp),%xmm0
movupd %xmm0,0x2eee(%rip)
movsd  0x2ee6(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
mov    0x10(%rsp),%eax
sub    0x2ede(%rip),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
subsd  %xmm1,%xmm2
divsd  0xe93(%rip),%xmm0
addsd  %xmm2,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
@elapsed_realtime.t0 = internal global %struct.timeval zeroinitializer
define double @elapsed_realtime() {
%1 = alloca %struct.timeval
%2 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%3 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 0)
%4 = fcmp une double %3, 0.000000e+00
br i1 %4, label %7, label %5
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 double, double* %8
%10 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 0)
%11 = fsub double %9, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 1)
%15 = sub nsw i32 %13, %14
%16 = sitofp i32 %15 to double
%17 = fdiv double %16, 1.000000e+06
%18 = fadd double %11, %17
ret double %18
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
@elapsed_realtime.t0 = internal unnamed_addr global %struct.timeval zeroinitializer
define double @elapsed_realtime() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32 0)
%4 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i64 0, i32 0)
%5 = fcmp une double %4, 0.000000e+00
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = load double, double* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i64 0, i32 0)
br label %8
8: ; preds = %6, %0
%9 = phi double [ %7, %6 ], [ %4, %0 ]
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load double, double* %10
%12 = fsub double %11, %9
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = load i32, i32* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i64 0, i32 1)
%16 = sub nsw i32 %14, %15
%17 = sitofp i32 %16 to double
%18 = fdiv double %17, 1.000000e+06
%19 = fadd double %12, %18
ret double %19
}