#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_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_THREAD_CPUTIME_ID;
int /*<<< orphan*/ clock_getres(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
double stopwatch_time(struct timespec *t) {
  struct timespec tr, tn;
  clock_getres(CLOCK_THREAD_CPUTIME_ID, &tr);
  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tn);
  double s = (tn.tv_sec - t->tv_sec);
  s *= 1000000000;
  s += tn.tv_nsec;
  s -= t->tv_nsec;
  s /= 1000000000;
  return s;
}


x86 assembly (clang, -O0):
<stopwatch_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_getres@plt>
mov    0x2ea3(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1030 <clock_gettime@plt>
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe96(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stopwatch_time>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
mov    0x2eb7(%rip),%r14
mov    (%r14),%edi
lea    0x18(%rsp),%rsi
call   1040 <clock_getres@plt>
mov    (%r14),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
movsd  0x8(%rsp),%xmm1
subsd  (%rbx),%xmm1
movsd  0xea3(%rip),%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sdq 0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rbx),%xmm1
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
define double @stopwatch_time(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca double
store %struct.timespec* %0, %struct.timespec** %2
%6 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%7 = call i32 @clock_getres(i32 %6, %struct.timespec* %3)
%8 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %4)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%11 = load double, double* %10
%12 = load %struct.timespec*, %struct.timespec** %2
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%14 = load double, double* %13
%15 = fsub double %11, %14
store double %15, double* %5
%16 = load double, double* %5
%17 = fmul double %16, 1.000000e+09
store double %17, double* %5
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%19 = load i64, i64* %18
%20 = sitofp i64 %19 to double
%21 = load double, double* %5
%22 = fadd double %21, %20
store double %22, double* %5
%23 = load %struct.timespec*, %struct.timespec** %2
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sitofp i64 %25 to double
%27 = load double, double* %5
%28 = fsub double %27, %26
store double %28, double* %5
%29 = load double, double* %5
%30 = fdiv double %29, 1.000000e+09
store double %30, double* %5
%31 = load double, double* %5
ret double %31
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
define double @stopwatch_time(%struct.timespec* nocapture %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%7 = call i32 @clock_getres(i32 %6, %struct.timespec* %2)
%8 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %3)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%11 = load double, double* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%13 = load double, double* %12
%14 = fsub double %11, %13
%15 = fmul double %14, 1.000000e+09
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = fadd double %15, %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%21 = load i64, i64* %20
%22 = sitofp i64 %21 to double
%23 = fsub double %19, %22
%24 = fdiv double %23, 1.000000e+09
ret double %24
}