#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 elapsed_realtime(void) {
  static struct timeval t0;
  struct timeval tv;
  gettimeofday(&tv, 0);
  if (!t0.tv_sec)
    t0 = tv;
  return (double)(tv.tv_sec - t0.tv_sec) +
         (double)(tv.tv_usec - t0.tv_usec) / 1e6;
}


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>
cmpq   $0x0,0x2f0d(%rip)
jne    1147 <elapsed_realtime+0x37>
mov    -0x10(%rbp),%rax
mov    %rax,0x2ef4(%rip)
mov    -0x8(%rbp),%rax
mov    %rax,0x2ef1(%rip)
mov    -0x8(%rbp),%rax
sub    0x2ee6(%rip),%rax
cvtsi2sd %rax,%xmm0
mov    -0x10(%rbp),%rax
sub    0x2ece(%rip),%rax
cvtsi2sd %rax,%xmm1
movsd  0xe91(%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>
mov    0x2f11(%rip),%rax
test   %rax,%rax
jne    113f <elapsed_realtime+0x2f>
movups 0x8(%rsp),%xmm0
movups %xmm0,0x2ef8(%rip)
mov    0x2ef9(%rip),%rax
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
sub    %rax,%rdx
cvtsi2sd %rdx,%xmm1
sub    0x2ed8(%rip),%rcx
xorps  %xmm0,%xmm0
cvtsi2sd %rcx,%xmm0
divsd  0xe98(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@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 i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 1)
%4 = icmp ne i64 %3, 0
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 1
%9 = load i64, i64* %8
%10 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 1)
%11 = sub nsw i64 %9, %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i32 0, i32 0)
%16 = sub nsw i64 %14, %15
%17 = sitofp i64 %16 to double
%18 = fdiv double %17, 1.000000e+06
%19 = fadd double %12, %18
ret double %19
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@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 i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i64 0, i32 1)
%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* @elapsed_realtime.t0, i64 0, i32 1)
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 1
%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 0
%15 = load i64, i64* %14
%16 = load i64, i64* getelementptr inbounds (%struct.timeval, %struct.timeval* @elapsed_realtime.t0, i64 0, i32 0)
%17 = sub nsw i64 %15, %16
%18 = sitofp i64 %17 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %19, %13
ret double %20
}