#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 */
typedef int const uint64_t;
struct timespec {
  int const tv_sec;
  int tv_nsec;
};

/* Variables and functions */
uint64_t get_elapsed_ns(const struct timespec *const start_time,
                        const struct timespec *const end_time) {
  const uint64_t nsecs_per_sec = 1000000000;
  const uint64_t start_time_ns =
      (start_time->tv_sec * nsecs_per_sec) + start_time->tv_nsec;
  const uint64_t end_time_ns =
      (end_time->tv_sec * nsecs_per_sec) + end_time->tv_nsec;
  return end_time_ns - start_time_ns;
}


x86 assembly (clang, -O0):
<get_elapsed_ns>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x3b9aca00,-0x14(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
mov    -0x10(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    -0x18(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_elapsed_ns>:
mov    (%rsi),%ecx
mov    0x4(%rsi),%eax
sub    (%rdi),%ecx
imul   $0x3b9aca00,%ecx,%ecx
sub    0x4(%rdi),%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @get_elapsed_ns(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
store i32 1000000000, i32* %5
%8 = load %struct.timespec*, %struct.timespec** %3
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = load i32, i32* %9
%11 = mul nsw i32 %10, 1000000000
%12 = load %struct.timespec*, %struct.timespec** %3
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 1
%14 = load i32, i32* %13
%15 = add nsw i32 %11, %14
store i32 %15, i32* %6
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, 1000000000
%20 = load %struct.timespec*, %struct.timespec** %4
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = add nsw i32 %19, %22
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = load i32, i32* %6
%26 = sub nsw i32 %24, %25
ret i32 %26
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @get_elapsed_ns(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = sub i32 %8, %4
%12 = mul i32 %11, 1000000000
%13 = sub i32 %10, %6
%14 = add i32 %13, %12
ret i32 %14
}