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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
double clock_mono() {
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
    return -1;
  }
  double rv = ts.tv_sec + (ts.tv_nsec * 1e-9);
  return rv;
}


x86 assembly (clang, -O0):
<clock_mono>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1146 <clock_mono+0x36>
movsd  0xecc(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    116f <clock_mono+0x5f>
cvtsi2sdl -0x10(%rbp),%xmm1
cvtsi2sdl -0xc(%rbp),%xmm0
movsd  0xea8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_mono>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
je     1131 <clock_mono+0x21>
movsd  0xed1(%rip),%xmm0
pop    %rax
ret
cvtsi2sdl (%rsp),%xmm1
cvtsi2sdl 0x4(%rsp),%xmm0
mulsd  0xec4(%rip),%xmm0
addsd  %xmm1,%xmm0
pop    %rax
ret

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

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