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

/* Variables and functions */
long int elapsed_us(struct timeval *t2, struct timeval *t1) {
  long int usec1 = (t1->tv_usec + 1000000 * t1->tv_sec);
  long int usec2 = (t2->tv_usec + 1000000 * t2->tv_sec);
  return usec2 - usec1;
}


x86 assembly (clang, -O0):
<elapsed_us>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
imul   $0xf4240,0x4(%rcx),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
imul   $0xf4240,0x4(%rcx),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_us>:
movslq (%rsi),%rax
movslq 0x4(%rsi),%rcx
imul   $0xf4240,%rcx,%rcx
add    %rax,%rcx
movslq (%rdi),%rdx
movslq 0x4(%rdi),%rax
imul   $0xf4240,%rax,%rax
add    %rdx,%rax
sub    %rcx,%rax
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i64 @elapsed_us(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%6 = load i32, i32* %5
%7 = mul nsw i32 %6, 1000000
%8 = add nsw i32 %7, %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000000
%15 = add nsw i32 %14, %11
%16 = sext i32 %15 to i64
%17 = sub nsw i64 %16, %9
ret i64 %17
}