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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, char *, long);
long printDiff(struct timespec *start, struct timespec *end, char *head) {
  unsigned long long val1 = start->tv_sec * 1000 * 1000 * 1000 + start->tv_nsec;
  unsigned long long val2 = end->tv_sec * 1000 * 1000 * 1000 + end->tv_nsec;
  long diff = val2 - val1;
  printf("[%s]time diff is %llu nanoseconds\n", head, diff);
  return diff;
}


x86 assembly (clang, -O0):
<printDiff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3e8,(%rax),%eax
imul   $0x3e8,%eax,%eax
imul   $0x3e8,%eax,%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3e8,(%rax),%eax
imul   $0x3e8,%eax,%eax
imul   $0x3e8,%eax,%eax
mov    -0x10(%rbp),%rcx
add    0x4(%rcx),%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xe7b(%rip),%rdi
call   1030 <printf@plt>
mov    -0x30(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDiff>:
push   %rbx
imul   $0x3b9aca00,(%rdi),%eax
movslq 0x4(%rdi),%rcx
cltq
add    %rcx,%rax
imul   $0x3b9aca00,(%rsi),%ecx
movslq 0x4(%rsi),%rsi
movslq %ecx,%rbx
add    %rsi,%rbx
sub    %rax,%rbx
lea    0xec6(%rip),%rdi
mov    %rdx,%rsi
mov    %rbx,%rdx
call   1030 <printf@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@.str = [35 x i8] c"[%s]time diff is %llu nanoseconds\0A\00"
define i64 @printDiff(%struct.timespec* %0, %struct.timespec* %1, i8* %2) {
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store %struct.timespec* %0, %struct.timespec** %4
store %struct.timespec* %1, %struct.timespec** %5
store i8* %2, i8** %6
%10 = load %struct.timespec*, %struct.timespec** %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 1000
%14 = mul nsw i32 %13, 1000
%15 = mul nsw i32 %14, 1000
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = add nsw i32 %15, %18
%20 = sext i32 %19 to i64
store i64 %20, i64* %7
%21 = load %struct.timespec*, %struct.timespec** %5
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 1000
%25 = mul nsw i32 %24, 1000
%26 = mul nsw i32 %25, 1000
%27 = load %struct.timespec*, %struct.timespec** %5
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %27, i32 0, i32 1
%29 = load i32, i32* %28
%30 = add nsw i32 %26, %29
%31 = sext i32 %30 to i64
store i64 %31, i64* %8
%32 = load i64, i64* %8
%33 = load i64, i64* %7
%34 = sub i64 %32, %33
store i64 %34, i64* %9
%35 = load i8*, i8** %6
%36 = load i64, i64* %9
%37 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %35, i64 %36)
%38 = load i64, i64* %9
ret i64 %38
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@.str = [35 x i8] c"[%s]time diff is %llu nanoseconds\0A\00"
define i64 @printDiff(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1, i8* %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = mul i32 %5, 1000000000
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = add nsw i32 %6, %8
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = mul i32 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%15 = load i32, i32* %14
%16 = add nsw i32 %13, %15
%17 = sext i32 %16 to i64
%18 = sub nsw i64 %17, %10
%19 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %2, i64 %18)
ret i64 %18
}