#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;
  double tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
double GetTime(struct timespec *start) {
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);
  if (now.tv_nsec > start->tv_nsec) {
    return (now.tv_sec - start->tv_sec) +
           (now.tv_nsec - start->tv_nsec) * 1.0e-9;
  } else {
    return (now.tv_sec - start->tv_sec - 1) +
           (1e9 + now.tv_nsec - start->tv_nsec) * 1.0e-9;
  }
}


x86 assembly (clang, -O0):
<GetTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jle    1177 <GetTime+0x67>
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe9b(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c5 <GetTime+0xb5>
movsd  -0x18(%rbp),%xmm1
mov    -0x10(%rbp),%rax
subsd  0x8(%rax),%xmm1
movsd  0xe83(%rip),%xmm0
subsd  %xmm0,%xmm1
cvtsi2sdq -0x20(%rbp),%xmm2
movsd  0xe69(%rip),%xmm0
addsd  %xmm2,%xmm0
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm2
subsd  %xmm2,%xmm0
movsd  0xe48(%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):
<GetTime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%rcx
mov    (%rbx),%rax
mov    %rcx,%rdx
movsd  0x8(%rsp),%xmm1
subsd  0x8(%rbx),%xmm1
sub    %rax,%rdx
jle    114a <GetTime+0x3a>
cvtsi2sd %rdx,%xmm0
jmp    1168 <GetTime+0x58>
addsd  0xeae(%rip),%xmm1
cvtsi2sd %rcx,%xmm0
addsd  0xea9(%rip),%xmm0
cvtsi2sd %rax,%xmm2
subsd  %xmm2,%xmm0
mulsd  0xea0(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, double }
@CLOCK_MONOTONIC = global i32 0
define double @GetTime(%struct.timespec* %0) {
%2 = alloca double
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %3
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %4)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt i64 %8, %11
br i1 %12, label %13, label %28
13: ; preds = %1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%15 = load double, double* %14
%16 = load %struct.timespec*, %struct.timespec** %3
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load double, double* %17
%19 = fsub double %15, %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load %struct.timespec*, %struct.timespec** %3
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = sub nsw i64 %21, %24
%26 = sitofp i64 %25 to double
%27 = call double @llvm.fmuladd.f64(double %26, double 1.000000e-09, double %19)
store double %27, double* %2
br label %46
28: ; preds = %1
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%30 = load double, double* %29
%31 = load %struct.timespec*, %struct.timespec** %3
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 1
%33 = load double, double* %32
%34 = fsub double %30, %33
%35 = fsub double %34, 1.000000e+00
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
%39 = fadd double 1.000000e+09, %38
%40 = load %struct.timespec*, %struct.timespec** %3
%41 = getelementptr inbounds %struct.timespec, %struct.timespec* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = sitofp i64 %42 to double
%44 = fsub double %39, %43
%45 = call double @llvm.fmuladd.f64(double %44, double 1.000000e-09, double %35)
store double %45, double* %2
br label %46
46: ; preds = %28, %13
%47 = load double, double* %2
ret double %47
}

LLVM IR (-O2):
%struct.timespec = type { i64, double }
@CLOCK_MONOTONIC = global i32 0
define double @GetTime(%struct.timespec* nocapture %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp sgt i64 %7, %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%12 = load double, double* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%14 = load double, double* %13
%15 = fsub double %12, %14
br i1 %10, label %16, label %20
16: ; preds = %1
%17 = sub nsw i64 %7, %9
%18 = sitofp i64 %17 to double
%19 = call double @llvm.fmuladd.f64(double %18, double 1.000000e-09, double %15)
br label %27
20: ; preds = %1
%21 = fadd double %15, -1.000000e+00
%22 = sitofp i64 %7 to double
%23 = fadd double %22, 1.000000e+09
%24 = sitofp i64 %9 to double
%25 = fsub double %23, %24
%26 = call double @llvm.fmuladd.f64(double %25, double 1.000000e-09, double %21)
br label %27
27: ; preds = %20, %16
%28 = phi double [ %19, %16 ], [ %26, %20 ]
ret double %28
}