#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_difference(struct timeval *start, struct timeval *end,
                        struct timeval **res) {
  if (end->tv_usec - start->tv_usec < 0) {
    (*res)->tv_sec = end->tv_sec - start->tv_sec - 1;
    (*res)->tv_usec = end->tv_usec - start->tv_usec + 1.0e6;
  } else {
    (*res)->tv_sec = end->tv_sec - start->tv_sec;
    (*res)->tv_usec = end->tv_usec - start->tv_usec;
  }
}


x86 assembly (clang, -O0):
<timeval_difference>:
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    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cmp    $0x0,%rax
jge    117a <timeval_difference+0x7a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe9e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
jmp    11ad <timeval_difference+0xad>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x8(%rbp),%rax
sub    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_difference>:
mov    (%rsi),%rax
mov    0x8(%rsi),%rsi
mov    (%rdi),%r8
mov    0x8(%rdi),%rdi
mov    %rax,%rcx
sub    %r8,%rcx
jge    113c <timeval_difference+0x3c>
not    %rdi
add    %rdi,%rsi
mov    (%rdx),%rdx
mov    %rsi,0x8(%rdx)
sub    %r8,%rax
cvtsi2sd %rax,%xmm0
addsd  0xecd(%rip),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,(%rdx)
ret
sub    %rdi,%rsi
mov    (%rdx),%rdx
mov    %rsi,0x8(%rdx)
mov    %rcx,(%rdx)
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define void @timeval_difference(%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** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sub nsw i64 %9, %12
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %40
15: ; preds = %3
%16 = load %struct.timeval*, %struct.timeval** %5
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load %struct.timeval*, %struct.timeval** %4
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = sub nsw i64 %18, %21
%23 = sub nsw i64 %22, 1
%24 = load %struct.timeval**, %struct.timeval*** %6
%25 = load %struct.timeval*, %struct.timeval** %24
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
store i64 %23, i64* %26
%27 = load %struct.timeval*, %struct.timeval** %5
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load i64, i64* %28
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = sub nsw i64 %29, %32
%34 = sitofp i64 %33 to double
%35 = fadd double %34, 1.000000e+06
%36 = fptosi double %35 to i64
%37 = load %struct.timeval**, %struct.timeval*** %6
%38 = load %struct.timeval*, %struct.timeval** %37
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %38, i32 0, i32 0
store i64 %36, i64* %39
br label %61
40: ; preds = %3
%41 = load %struct.timeval*, %struct.timeval** %5
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %41, i32 0, i32 1
%43 = load i64, i64* %42
%44 = load %struct.timeval*, %struct.timeval** %4
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 1
%46 = load i64, i64* %45
%47 = sub nsw i64 %43, %46
%48 = load %struct.timeval**, %struct.timeval*** %6
%49 = load %struct.timeval*, %struct.timeval** %48
%50 = getelementptr inbounds %struct.timeval, %struct.timeval* %49, i32 0, i32 1
store i64 %47, i64* %50
%51 = load %struct.timeval*, %struct.timeval** %5
%52 = getelementptr inbounds %struct.timeval, %struct.timeval* %51, i32 0, i32 0
%53 = load i64, i64* %52
%54 = load %struct.timeval*, %struct.timeval** %4
%55 = getelementptr inbounds %struct.timeval, %struct.timeval* %54, i32 0, i32 0
%56 = load i64, i64* %55
%57 = sub nsw i64 %53, %56
%58 = load %struct.timeval**, %struct.timeval*** %6
%59 = load %struct.timeval*, %struct.timeval** %58
%60 = getelementptr inbounds %struct.timeval, %struct.timeval* %59, i32 0, i32 0
store i64 %57, i64* %60
br label %61
61: ; preds = %40, %15
ret void
}

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