#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;
  unsigned long tv_usec;
};

/* Variables and functions */
unsigned long caltv(struct timeval *pstv, struct timeval *petv) {
  struct timeval result;
  result.tv_sec = petv->tv_sec - pstv->tv_sec;
  result.tv_usec = petv->tv_usec - pstv->tv_usec;
  return result.tv_sec * 1000000 + result.tv_usec;
}


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

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

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

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