#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 */
void timeval_subtract(struct timeval *result, struct timeval *t2,
                      struct timeval *t1) {
  long int diff = (t2->tv_usec + 1000000 * t2->tv_sec) -
                  (t1->tv_usec + 1000000 * t1->tv_sec);
  result->tv_sec = diff / 1000000;
  result->tv_usec = diff % 1000000;
}


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

x86 assembly (clang, -O2):
<timeval_subtract>:
movslq 0x8(%rsi),%rax
imul   $0xf4240,%rax,%rcx
movslq 0x8(%rdx),%rax
imul   $0xf4240,%rax,%rax
add    (%rsi),%rcx
add    (%rdx),%rax
sub    %rax,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
mov    %edx,0x8(%rdi)
imul   $0xf4240,%rdx,%rax
sub    %rax,%rcx
mov    %rcx,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define void @timeval_subtract(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca i64
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
%8 = load %struct.timeval*, %struct.timeval** %5
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = load %struct.timeval*, %struct.timeval** %5
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = mul nsw i32 1000000, %13
%15 = sext i32 %14 to i64
%16 = add nsw i64 %10, %15
%17 = load %struct.timeval*, %struct.timeval** %6
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = load %struct.timeval*, %struct.timeval** %6
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = mul nsw i32 1000000, %22
%24 = sext i32 %23 to i64
%25 = add nsw i64 %19, %24
%26 = sub nsw i64 %16, %25
store i64 %26, i64* %7
%27 = load i64, i64* %7
%28 = sdiv i64 %27, 1000000
%29 = trunc i64 %28 to i32
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 1
store i32 %29, i32* %31
%32 = load i64, i64* %7
%33 = srem i64 %32, 1000000
%34 = load %struct.timeval*, %struct.timeval** %4
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 0
store i64 %33, i64* %35
ret void
}

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