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

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


x86 assembly (clang, -O0):
<timeval_subtract>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
imul   $0xf4240,0x8(%rcx),%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x10(%rbp),%rdx
imul   $0xf4240,0x8(%rdx),%edx
movslq %edx,%rdx
add    %rdx,%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

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

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

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