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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_THREAD_CPUTIME_ID;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ memset(struct timespec *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, long);
long timer_end(struct timespec start_time) {
  struct timespec end_time;
  long diffInNanos = 0;
  memset((&end_time), 0, sizeof(struct timespec));
  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end_time);
  printf("end: %ld\n", end_time.tv_nsec);
  diffInNanos = end_time.tv_nsec - start_time.tv_nsec;
  return diffInNanos;
}


x86 assembly (clang, -O0):
<timer_end>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8f(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_end>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    0x2e98(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%rsi
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
mov    (%rsp),%rax
sub    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@.str = [10 x i8] c"end: %ld\0A\00"
define i64 @timer_end(i64 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = alloca i64
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
store i64 %0, i64* %5
store i64 0, i64* %4
%6 = call i32 @memset(%struct.timespec* %3, i32 0, i32 8)
%7 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %3)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%10 = load i64, i64* %9
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %10)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%15 = load i64, i64* %14
%16 = sub nsw i64 %13, %15
store i64 %16, i64* %4
%17 = load i64, i64* %4
ret i64 %17
}

LLVM IR (-O2):
%struct.timespec = type { i64 }
@CLOCK_THREAD_CPUTIME_ID = global i32 0
@.str = [10 x i8] c"end: %ld\0A\00"
define i64 @timer_end(i64 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = call i32 @memset(%struct.timespec* %2, i32 0, i32 8)
%5 = load i32, i32* @CLOCK_THREAD_CPUTIME_ID
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %2)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%8 = load i64, i64* %7
%9 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i64 %8)
%10 = load i64, i64* %7
%11 = sub nsw i64 %10, %0
ret i64 %11
}