#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 w_timeval_sub(const struct timeval a, const struct timeval b,
                   struct timeval *result) {
  result->tv_sec = a.tv_sec - b.tv_sec;
  result->tv_usec = a.tv_usec - b.tv_usec;
  if (result->tv_usec < 0) {
    result->tv_sec--;
    result->tv_usec += 1000000;
  }
}


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

x86 assembly (clang, -O2):
<w_timeval_sub>:
sub    %rcx,%rsi
mov    %rsi,0x8(%r8)
sub    %rdx,%rdi
mov    %rdi,(%r8)
js     1110 <w_timeval_sub+0x10>
ret
add    $0xffffffffffffffff,%rsi
mov    %rsi,0x8(%r8)
add    $0xf4240,%rdi
mov    %rdi,(%r8)
ret

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

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