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

/* Variables and functions */
void TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result) {
  long l;
  if ((l = a->tv_usec - b->tv_usec) >= 0) {
    result->tv_usec = l;
    result->tv_sec = a->tv_sec - b->tv_sec;
  } else {
    result->tv_usec = 1000000 + l;
    result->tv_sec = a->tv_sec - b->tv_sec - 1;
  }
}


x86 assembly (clang, -O0):
<TIMEVAL_SUB>:
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
sub    (%rcx),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jl     1154 <TIMEVAL_SUB+0x54>
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
jmp    1182 <TIMEVAL_SUB+0x82>
mov    -0x20(%rbp),%rcx
add    $0xf4240,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<TIMEVAL_SUB>:
mov    (%rdi),%rax
sub    (%rsi),%rax
js     1112 <TIMEVAL_SUB+0x12>
mov    0x8(%rdi),%rcx
sub    0x8(%rsi),%rcx
jmp    1123 <TIMEVAL_SUB+0x23>
add    $0xf4240,%rax
mov    0x8(%rsi),%rcx
not    %rcx
add    0x8(%rdi),%rcx
mov    %rax,(%rdx)
mov    %rcx,0x8(%rdx)
ret

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

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