#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;
  scalar_t__ tv_sec;
};

/* Variables and functions */
void tvdiff(const struct timeval *t1, const struct timeval *t2,
            struct timeval *r) {
  long u;
  r->tv_sec = t1->tv_sec - t2->tv_sec;
  u = t1->tv_usec - t2->tv_usec;
  if (u < 0) {
    u += 1000000;
    --r->tv_sec;
  }
  r->tv_usec = u;
}


x86 assembly (clang, -O0):
<tvdiff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1163 <tvdiff+0x63>
mov    -0x20(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvdiff>:
mov    0x8(%rdi),%rcx
sub    0x8(%rsi),%rcx
mov    %rcx,0x8(%rdx)
mov    (%rdi),%rax
sub    (%rsi),%rax
js     1118 <tvdiff+0x18>
mov    %rax,(%rdx)
ret
add    $0xf4240,%rax
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rdx)
mov    %rax,(%rdx)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @tvdiff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture writeonly %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
%8 = sub nsw i64 %5, %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 %8, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = sub nsw i64 %11, %13
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %3
%17 = add nsw i64 %14, 1000000
%18 = add nsw i64 %8, -1
store i64 %18, i64* %9
br label %19
19: ; preds = %16, %3
%20 = phi i64 [ %17, %16 ], [ %14, %3 ]
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i64 %20, i64* %21
ret void
}