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

/* Variables and functions */
long microseconds(struct timespec start, struct timespec end) {
  long secs_used, micros_used;
  secs_used = (end.tv_sec - start.tv_sec);
  micros_used =
      ((secs_used * 1000000) + (end.tv_nsec / 1000)) - (start.tv_nsec / 1000);
  return micros_used;
}


x86 assembly (clang, -O0):
<microseconds>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
imul   $0xf4240,-0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<microseconds>:
sub    %rdi,%rdx
imul   $0xf4240,%rdx,%rdx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
movslq %eax,%rcx
movslq %esi,%rax
imul   $0xffffffffef9db22d,%rax,%rax
mov    %rax,%rsi
shr    $0x3f,%rsi
sar    $0x26,%rax
add    %esi,%eax
cltq
add    %rdx,%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
define i64 @microseconds(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = alloca i64
%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 0
%16 = load i64, i64* %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%18 = load i64, i64* %17
%19 = sub nsw i64 %16, %18
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = mul nsw i64 %20, 1000000
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%23 = load i32, i32* %22
%24 = sdiv i32 %23, 1000
%25 = sext i32 %24 to i64
%26 = add nsw i64 %21, %25
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%28 = load i32, i32* %27
%29 = sdiv i32 %28, 1000
%30 = sext i32 %29 to i64
%31 = sub nsw i64 %26, %30
store i64 %31, i64* %8
%32 = load i64, i64* %8
ret i64 %32
}

LLVM IR (-O2):
define i64 @microseconds(i64 %0, i32 %1, i64 %2, i32 %3) {
%5 = sub nsw i64 %2, %0
%6 = mul nsw i64 %5, 1000000
%7 = sdiv i32 %3, 1000
%8 = sext i32 %7 to i64
%9 = sdiv i32 %1, -1000
%10 = sext i32 %9 to i64
%11 = add i64 %6, %10
%12 = add i64 %11, %8
ret i64 %12
}