#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_MONOTONIC;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
double getdtime(void) {
  struct timespec tp;
  if (clock_gettime(CLOCK_MONOTONIC, &tp) == -1)
    return (-1);
  return ((double)((&tp)->tv_sec) + (double)((&tp)->tv_nsec) / 1000000000.0);
}


x86 assembly (clang, -O0):
<getdtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1145 <getdtime+0x35>
movsd  0xecd(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1166 <getdtime+0x56>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xea7(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getdtime>:
sub    $0x18,%rsp
mov    0x2ecd(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     114b <getdtime+0x3b>
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
divsd  0xec6(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
movsd  0xead(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
define double @getdtime() {
%1 = alloca double
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %7
6: ; preds = %0
store double -1.000000e+00, double* %1
br label %16
7: ; preds = %0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%9 = load i64, i64* %8
%10 = sitofp i64 %9 to double
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+09
%15 = fadd double %10, %14
store double %15, double* %1
br label %16
16: ; preds = %7, %6
%17 = load double, double* %1
ret double %17
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
define double @getdtime() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %15, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%8 = load i64, i64* %7
%9 = sitofp i64 %8 to double
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = fdiv double %12, 1.000000e+09
%14 = fadd double %13, %9
br label %15
15: ; preds = %0, %6
%16 = phi double [ %14, %6 ], [ -1.000000e+00, %0 ]
ret double %16
}