#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_RAW;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ report_errno(char *, int);
double __attribute__((externally_visible)) get_monotonic(void) {
  struct timespec ts;
  int ret = clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  if (ret) {
    report_errno("clock_gettime", ret);
    return 0.;
  }
  return (double)ts.tv_sec + (double)ts.tv_nsec * .000000001;
}


x86 assembly (clang, -O0):
<get_monotonic>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1163 <get_monotonic+0x43>
mov    -0x1c(%rbp),%esi
lea    0xeb7(%rip),%rdi
call   1040 <report_errno@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1184 <get_monotonic+0x64>
cvtsi2sdq -0x10(%rbp),%xmm1
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  0xe89(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_monotonic>:
sub    $0x18,%rsp
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %eax,%eax
je     1151 <get_monotonic+0x31>
lea    0xec6(%rip),%rdi
mov    %eax,%esi
call   1040 <report_errno@plt>
xorps  %xmm0,%xmm0
add    $0x18,%rsp
ret
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
mulsd  0xe99(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define double @get_monotonic() {
%1 = alloca double
%2 = alloca %struct.timespec
%3 = alloca i32
%4 = load i32, i32* @CLOCK_MONOTONIC_RAW
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = load i32, i32* %3
%10 = call i32 @report_errno(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %9)
store double 0.000000e+00, double* %1
br label %19
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = call double @llvm.fmuladd.f64(double %17, double 1.000000e-09, double %14)
store double %18, double* %1
br label %19
19: ; preds = %11, %8
%20 = load double, double* %1
ret double %20
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
define double @get_monotonic() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC_RAW
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @report_errno(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %16
8: ; preds = %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = call double @llvm.fmuladd.f64(double %14, double 1.000000e-09, double %11)
br label %16
16: ; preds = %8, %6
%17 = phi double [ 0.000000e+00, %6 ], [ %15, %8 ]
ret double %17
}