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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double second() {
  struct timeval tm;
  double t;
  static int base_sec = 0, base_usec = 0;
  gettimeofday(&tm, NULL);
  if (base_sec == 0 && base_usec == 0) {
    base_sec = tm.tv_sec;
    base_usec = tm.tv_usec;
    t = 0.0;
  } else {
    t = (double)(tm.tv_sec - base_sec) +
        ((double)(tm.tv_usec - base_usec)) / 1.0e6;
  }
  return t;
}


x86 assembly (clang, -O0):
<second>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x0,0x2f00(%rip)
jne    115e <second+0x4e>
cmpl   $0x0,0x2ef7(%rip)
jne    115e <second+0x4e>
mov    -0x8(%rbp),%eax
mov    %eax,0x2ee4(%rip)
mov    -0x4(%rbp),%eax
mov    %eax,0x2edf(%rip)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    118d <second+0x7d>
mov    -0x8(%rbp),%eax
sub    0x2ec5(%rip),%eax
cvtsi2sd %eax,%xmm0
mov    -0x4(%rbp),%eax
sub    0x2ebc(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  0xe80(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<second>:
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f0b(%rip),%edx
mov    0x2f09(%rip),%eax
mov    (%rsp),%ecx
mov    %edx,%esi
or     %eax,%esi
jne    1145 <second+0x35>
mov    %ecx,0x2ef6(%rip)
mov    0x4(%rsp),%eax
mov    %eax,0x2ef0(%rip)
xorps  %xmm0,%xmm0
pop    %rax
ret
sub    %edx,%ecx
cvtsi2sd %ecx,%xmm1
mov    0x4(%rsp),%ecx
sub    %eax,%ecx
cvtsi2sd %ecx,%xmm0
divsd  0xea3(%rip),%xmm0
addsd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@second.base_sec = internal global i32 0
@second.base_usec = internal global i32 0
define double @second() {
%1 = alloca %struct.timeval
%2 = alloca double
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i32, i32* @second.base_sec
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = load i32, i32* @second.base_usec
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%11 = load i32, i32* %10
store i32 %11, i32* @second.base_sec
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%13 = load i32, i32* %12
store i32 %13, i32* @second.base_usec
store double 0.000000e+00, double* %2
br label %27
14: ; preds = %6, %0
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @second.base_sec
%18 = sub nsw i32 %16, %17
%19 = sitofp i32 %18 to double
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%21 = load i32, i32* %20
%22 = load i32, i32* @second.base_usec
%23 = sub nsw i32 %21, %22
%24 = sitofp i32 %23 to double
%25 = fdiv double %24, 1.000000e+06
%26 = fadd double %19, %25
store double %26, double* %2
br label %27
27: ; preds = %14, %9
%28 = load double, double* %2
ret double %28
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@second.base_sec = internal unnamed_addr global i32 0
@second.base_usec = internal unnamed_addr global i32 0
define double @second() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i32, i32* @second.base_sec
%5 = icmp eq i32 %4, 0
%6 = load i32, i32* @second.base_usec
%7 = icmp eq i32 %6, 0
%8 = select i1 %5, i1 %7, i1 false
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i32, i32* %9
br i1 %8, label %11, label %14
11: ; preds = %0
store i32 %10, i32* @second.base_sec
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%13 = load i32, i32* %12
store i32 %13, i32* @second.base_usec
br label %23
14: ; preds = %0
%15 = sub nsw i32 %10, %4
%16 = sitofp i32 %15 to double
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = sub nsw i32 %18, %6
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %21, %16
br label %23
23: ; preds = %14, %11
%24 = phi double [ 0.000000e+00, %11 ], [ %22, %14 ]
ret double %24
}