#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 timeval_minus(struct timeval *d, const struct timeval *s1,
                   const struct timeval *s2) {
  if (s1->tv_usec >= s2->tv_usec) {
    d->tv_usec = s1->tv_usec - s2->tv_usec;
    d->tv_sec = s1->tv_sec - s2->tv_sec;
  } else {
    d->tv_usec = s1->tv_usec + 1000000 - s2->tv_usec;
    d->tv_sec = s1->tv_sec - s2->tv_sec - 1;
  }
}


x86 assembly (clang, -O0):
<timeval_minus>:
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
jl     1156 <timeval_minus+0x56>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    118e <timeval_minus+0x8e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
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)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_minus>:
mov    (%rsi),%rax
mov    (%rdx),%r8
cmp    %r8,%rax
jge    111e <timeval_minus+0x1e>
add    $0xf4240,%rax
mov    0x8(%rdx),%rcx
not    %rcx
add    0x8(%rsi),%rcx
jmp    1126 <timeval_minus+0x26>
mov    0x8(%rsi),%rcx
sub    0x8(%rdx),%rcx
sub    %r8,%rax
mov    %rax,(%rdi)
mov    %rcx,0x8(%rdi)
ret

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

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