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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
double timer_end(struct timespec start_time) {
  struct timespec end_time;
  clock_gettime(CLOCK_MONOTONIC, &end_time);
  double diff = ((double)end_time.tv_sec + 1.0e-9 * end_time.tv_nsec) -
                ((double)start_time.tv_sec + 1.0e-9 * start_time.tv_nsec);
  return diff;
}


x86 assembly (clang, -O0):
<timer_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x8(%rbp)
mov    0x2ec0(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  0xeba(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdq -0x8(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
movsd  0xe9f(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_end>:
push   %rbx
sub    $0x20,%rsp
mov    %rdi,%rbx
movsd  %xmm0,0x8(%rsp)
mov    0x2ec3(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq 0x18(%rsp),%xmm1
movsd  0xec0(%rip),%xmm2
movsd  0x10(%rsp),%xmm0
mulsd  %xmm2,%xmm0
cvtsi2sd %rbx,%xmm3
addsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
subsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@CLOCK_MONOTONIC = global i32 0
define double @timer_end(double %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca double
%6 = bitcast %struct.timespec* %3 to { double, i64 }*
%7 = getelementptr inbounds { double, i64 }, { double, i64 }* %6, i32 0, i32 0
store double %0, double* %7
%8 = getelementptr inbounds { double, i64 }, { double, i64 }* %6, i32 0, i32 1
store i64 %1, i64* %8
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* %4)
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%15 = load double, double* %14
%16 = call double @llvm.fmuladd.f64(double 1.000000e-09, double %15, double %13)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%21 = load double, double* %20
%22 = call double @llvm.fmuladd.f64(double 1.000000e-09, double %21, double %19)
%23 = fsub double %16, %22
store double %23, double* %5
%24 = load double, double* %5
ret double %24
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@CLOCK_MONOTONIC = global i32 0
define double @timer_end(double %0, i64 %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %3)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%8 = load i64, i64* %7
%9 = sitofp i64 %8 to double
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%11 = load double, double* %10
%12 = call double @llvm.fmuladd.f64(double %11, double 1.000000e-09, double %9)
%13 = sitofp i64 %1 to double
%14 = call double @llvm.fmuladd.f64(double %0, double 1.000000e-09, double %13)
%15 = fsub double %12, %14
ret double %15
}