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

/* Variables and functions */
long tvdelta(struct timeval *t1, struct timeval *t2) {
  long delta, usec;
  delta = 1000000 * (t1->tv_sec - t2->tv_sec);
  usec = t1->tv_usec;
  if (t1->tv_usec < t2->tv_usec) {
    usec += 1000000;
    delta -= 1000000;
  }
  delta += (usec - t2->tv_usec);
  return delta;
}


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

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

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i64 @tvdelta(%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 = load %struct.timeval*, %struct.timeval** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = sub nsw i32 %9, %12
%14 = mul nsw i32 1000000, %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 1
%18 = load i64, i64* %17
store i64 %18, i64* %6
%19 = load %struct.timeval*, %struct.timeval** %3
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = load %struct.timeval*, %struct.timeval** %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = icmp slt i64 %21, %24
br i1 %25, label %26, label %31
26: ; preds = %2
%27 = load i64, i64* %6
%28 = add nsw i64 %27, 1000000
store i64 %28, i64* %6
%29 = load i64, i64* %5
%30 = sub nsw i64 %29, 1000000
store i64 %30, i64* %5
br label %31
31: ; preds = %26, %2
%32 = load i64, i64* %6
%33 = load %struct.timeval*, %struct.timeval** %4
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 1
%35 = load i64, i64* %34
%36 = sub nsw i64 %32, %35
%37 = load i64, i64* %5
%38 = add nsw i64 %37, %36
store i64 %38, i64* %5
%39 = load i64, i64* %5
ret i64 %39
}

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