#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 subtract_times(struct timeval *etime, struct timeval *sttime) {
  etime->tv_sec -= sttime->tv_sec;
  etime->tv_usec -= sttime->tv_usec;
  while (etime->tv_usec < 0) {
    etime->tv_usec += 1000000;
    etime->tv_sec--;
  }
}


x86 assembly (clang, -O0):
<subtract_times>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    116b <subtract_times+0x6b>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
jmp    1137 <subtract_times+0x37>
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtract_times>:
mov    (%rdi),%r8
mov    0x8(%rdi),%rcx
sub    0x8(%rsi),%rcx
mov    %rcx,0x8(%rdi)
mov    (%rsi),%rsi
mov    %r8,%rdx
sub    %rsi,%rdx
mov    %rdx,(%rdi)
js     111e <subtract_times+0x1e>
ret
cmp    $0xfffffffffff0bdc1,%rdx
mov    $0xfffffffffff0bdc0,%rax
cmovge %rdx,%rax
add    %rsi,%rax
xor    %r9d,%r9d
sub    %r8,%rax
setne  %r9b
sub    %r9,%rax
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mul    %rdx
shr    $0x12,%rdx
add    %r9,%rdx
imul   $0xf4240,%rdx,%rax
add    %r8,%rax
sub    %rsi,%rax
add    $0xf4240,%rax
not    %rdx
add    %rdx,%rcx
mov    %rax,(%rdi)
mov    %rcx,0x8(%rdi)
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define void @subtract_times(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sub nsw i64 %6, %4
store i64 %7, i64* %5
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%11 = load i64, i64* %10
%12 = sub i64 %11, %9
store i64 %12, i64* %10
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %29
14: ; preds = %2
%15 = call i64 @llvm.smax.i64(i64 %12, i64 -1000000)
%16 = add i64 %9, %15
%17 = sub i64 %16, %11
%18 = icmp ne i64 %17, 0
%19 = zext i1 %18 to i64
%20 = sub i64 %17, %19
%21 = udiv i64 %20, 1000000
%22 = add nuw nsw i64 %21, %19
%23 = mul i64 %22, 1000000
%24 = add i64 %11, %23
%25 = add i64 %24, 1000000
%26 = sub i64 %25, %9
%27 = xor i64 %22, -1
%28 = add i64 %7, %27
store i64 %26, i64* %10
store i64 %28, i64* %5
br label %29
29: ; preds = %14, %2
ret void
}