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

/* Variables and functions */
void tv_difference(struct timeval *tv_stop, struct timeval *tv_start,
                   struct timeval *tv_diff) {
  if (tv_stop->tv_usec < tv_start->tv_usec) {
    tv_diff->tv_usec = (tv_stop->tv_usec + 1000000) - tv_start->tv_usec;
    tv_diff->tv_sec = (tv_stop->tv_sec - 1 - tv_start->tv_sec);
  } else {
    tv_diff->tv_usec = tv_stop->tv_usec - tv_start->tv_usec;
    tv_diff->tv_sec = tv_stop->tv_sec - tv_start->tv_sec;
  }
}


x86 assembly (clang, -O0):
<tv_difference>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    115d <tv_difference+0x5d>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
sub    $0x1,%ecx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
jmp    1187 <tv_difference+0x87>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_difference>:
mov    (%rdi),%rax
mov    (%rsi),%r8
cmp    %r8,%rax
jge    111b <tv_difference+0x1b>
add    $0xf4240,%rax
mov    0x8(%rsi),%ecx
not    %ecx
add    0x8(%rdi),%ecx
jmp    1121 <tv_difference+0x21>
mov    0x8(%rdi),%ecx
sub    0x8(%rsi),%ecx
sub    %r8,%rax
mov    %rax,(%rdx)
mov    %ecx,0x8(%rdx)
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define void @tv_difference(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
%7 = load %struct.timeval*, %struct.timeval** %4
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load %struct.timeval*, %struct.timeval** %5
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp slt i64 %9, %12
br i1 %13, label %14, label %35
14: ; preds = %3
%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 = add nsw i64 %17, 1000000
%19 = load %struct.timeval*, %struct.timeval** %5
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = sub nsw i64 %18, %21
%23 = load %struct.timeval*, %struct.timeval** %6
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 0
store i64 %22, i64* %24
%25 = load %struct.timeval*, %struct.timeval** %4
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = sub nsw i32 %27, 1
%29 = load %struct.timeval*, %struct.timeval** %5
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %29, i32 0, i32 1
%31 = load i32, i32* %30
%32 = sub nsw i32 %28, %31
%33 = load %struct.timeval*, %struct.timeval** %6
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 1
store i32 %32, i32* %34
br label %54
35: ; preds = %3
%36 = load %struct.timeval*, %struct.timeval** %4
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = load %struct.timeval*, %struct.timeval** %5
%40 = getelementptr inbounds %struct.timeval, %struct.timeval* %39, i32 0, i32 0
%41 = load i64, i64* %40
%42 = sub nsw i64 %38, %41
%43 = load %struct.timeval*, %struct.timeval** %6
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 0
store i64 %42, i64* %44
%45 = load %struct.timeval*, %struct.timeval** %4
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.timeval*, %struct.timeval** %5
%49 = getelementptr inbounds %struct.timeval, %struct.timeval* %48, i32 0, i32 1
%50 = load i32, i32* %49
%51 = sub nsw i32 %47, %50
%52 = load %struct.timeval*, %struct.timeval** %6
%53 = getelementptr inbounds %struct.timeval, %struct.timeval* %52, i32 0, i32 1
store i32 %51, i32* %53
br label %54
54: ; preds = %35, %14
ret void
}

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