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

/* Variables and functions */
void TimeSubtract(struct timeval *result, struct timeval *x,
                  struct timeval *y) {
  if (x->tv_usec < y->tv_usec) {
    result->tv_sec = x->tv_sec - y->tv_sec - 1;
    result->tv_usec = y->tv_usec - x->tv_usec;
  } else {
    result->tv_sec = x->tv_sec - y->tv_sec;
    result->tv_usec = x->tv_usec - y->tv_usec;
  }
  return;
}


x86 assembly (clang, -O0):
<TimeSubtract>:
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    -0x18(%rbp),%rcx
cmp    (%rcx),%rax
jge    115a <TimeSubtract+0x5a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
jmp    1187 <TimeSubtract+0x87>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<TimeSubtract>:
mov    (%rsi),%r8
mov    0x8(%rsi),%rax
mov    (%rdx),%rsi
mov    0x8(%rdx),%rdx
mov    %r8,%rcx
sub    %rsi,%rcx
jge    1124 <TimeSubtract+0x24>
not    %rdx
add    %rdx,%rax
sub    %r8,%rsi
mov    %rsi,%rcx
jmp    1127 <TimeSubtract+0x27>
sub    %rdx,%rax
mov    %rax,0x8(%rdi)
mov    %rcx,(%rdi)
ret

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

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