#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 */
int /*<<< orphan*/ timer_reset(struct timeval *);
void timer_sub(const struct timeval *timer_a, const struct timeval *timer_b,
               struct timeval *ret) {
  timer_reset(ret);
  ret->tv_usec = timer_a->tv_usec - timer_b->tv_usec;
  ret->tv_sec = timer_a->tv_sec - timer_b->tv_sec;
  if (ret->tv_usec < 0) {
    ret->tv_usec += 1000000;
    ret->tv_sec--;
  }
}


x86 assembly (clang, -O0):
<timer_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <timer_reset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%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)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1189 <timer_sub+0x79>
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timer_sub>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdx,%rdi
call   1030 <timer_reset@plt>
movdqu (%r15),%xmm0
movdqu (%r14),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,(%rbx)
movq   %xmm0,%rax
test   %rax,%rax
jns    114e <timer_sub+0x3e>
paddq  0xeb6(%rip),%xmm0
movdqu %xmm0,(%rbx)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @timer_sub(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* %2) {
%4 = tail call i32 @timer_reset(%struct.timeval* %2)
%5 = bitcast %struct.timeval* %0 to <2 x i64>*
%6 = load <2 x i64>, <2 x i64>* %5
%7 = bitcast %struct.timeval* %1 to <2 x i64>*
%8 = load <2 x i64>, <2 x i64>* %7
%9 = sub nsw <2 x i64> %6, %8
%10 = bitcast %struct.timeval* %2 to <2 x i64>*
store <2 x i64> %9, <2 x i64>* %10
%11 = extractelement <2 x i64> %9, i64 0
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = add nsw <2 x i64> %9, <i64 1000000, i64 -1>
%15 = bitcast %struct.timeval* %2 to <2 x i64>*
store <2 x i64> %14, <2 x i64>* %15
br label %16
16: ; preds = %13, %3
ret void
}