#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 {
  long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
double calc_elapsed_time(struct timespec tsi, struct timespec tsf) {
  double elaps_s = difftime(tsf.tv_sec, tsi.tv_sec);
  long elaps_ns = tsf.tv_nsec - tsi.tv_nsec;
  return elaps_s + ((double)elaps_ns) / 1.0e9;
}


x86 assembly (clang, -O0):
<calc_elapsed_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1030 <difftime@plt>
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
movsd  0xeab(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_elapsed_time>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
mov    %ecx,%edi
call   1030 <difftime@plt>
sub    %r14,%rbx
cvtsi2sd %rbx,%xmm1
divsd  0xecf(%rip),%xmm1
addsd  %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define double @calc_elapsed_time(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = tail call double @difftime(i32 %3, i32 %1)
%6 = sub nsw i64 %2, %0
%7 = sitofp i64 %6 to double
%8 = fdiv double %7, 1.000000e+09
%9 = fadd double %8, %5
ret double %9
}