#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 tvsub(struct timeval *out, struct timeval *in) {
  if ((out->tv_usec -= in->tv_usec) < 0) {
    --out->tv_sec;
    out->tv_usec += 1000000;
  }
  out->tv_sec -= in->tv_sec;
}


x86 assembly (clang, -O0):
<tvsub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rax
sub    %rdx,%rax
mov    %rax,(%rcx)
cmp    $0x0,%rax
jge    114b <tvsub+0x4b>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvsub>:
mov    (%rdi),%rcx
mov    0x8(%rdi),%rax
sub    (%rsi),%rcx
mov    %rcx,(%rdi)
jns    1121 <tvsub+0x21>
add    $0xffffffffffffffff,%rax
mov    %rax,0x8(%rdi)
add    $0xf4240,%rcx
mov    %rcx,(%rdi)
sub    0x8(%rsi),%rax
mov    %rax,0x8(%rdi)
ret

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

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