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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
double gettimeinseconds(struct timespec *now) {
  struct timespec tmp;
  if (!now) {
    now = &tmp;
  }
  clock_gettime(CLOCK_REALTIME, now);
  return (double)now->tv_sec + (double)now->tv_nsec * .000000001;
}


x86 assembly (clang, -O0):
<gettimeinseconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    112f <gettimeinseconds+0x1f>
lea    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    0x2eaa(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
movsd  0xea4(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettimeinseconds>:
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
mov    %rsp,%rbx
cmovne %rdi,%rbx
mov    0x2eba(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq 0x8(%rbx),%xmm1
cvtsi2sdq (%rbx),%xmm0
mulsd  0xebd(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
define double @gettimeinseconds(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %2
%4 = load %struct.timespec*, %struct.timespec** %2
%5 = icmp ne %struct.timespec* %4, null
br i1 %5, label %7, label %6
6: ; preds = %1
store %struct.timespec* %3, %struct.timespec** %2
br label %7
7: ; preds = %6, %1
%8 = load i32, i32* @CLOCK_REALTIME
%9 = load %struct.timespec*, %struct.timespec** %2
%10 = call i32 @clock_gettime(i32 %8, %struct.timespec* %9)
%11 = load %struct.timespec*, %struct.timespec** %2
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = load %struct.timespec*, %struct.timespec** %2
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = call double @llvm.fmuladd.f64(double %18, double 1.000000e-09, double %14)
ret double %19
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
define double @gettimeinseconds(%struct.timespec* %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = icmp eq %struct.timespec* %0, null
%5 = select i1 %4, %struct.timespec* %2, %struct.timespec* %0
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %5)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%10 = select i1 %4, i64* %8, i64* %9
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%15 = select i1 %4, i64* %13, i64* %14
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = call double @llvm.fmuladd.f64(double %17, double 1.000000e-09, double %12)
ret double %18
}