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

/* Variables and functions */
long long timeval_subtract(struct timeval *end, struct timeval *start) {
  long long msec_end = end->tv_sec * 1000 * 1000 + end->tv_usec;
  long long msec_start = start->tv_sec * 1000 * 1000 + start->tv_usec;
  return msec_end - msec_start;
}


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

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

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

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