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


x86 assembly (clang, -O0):
<sub_timeval>:
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    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    1158 <sub_timeval+0x58>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_timeval>:
mov    0x8(%rdi),%rdx
sub    0x8(%rsi),%rdx
mov    (%rdi),%rax
mov    %rdx,0x8(%rdi)
mov    (%rsi),%rcx
cmp    %rcx,%rax
jge    112b <sub_timeval+0x2b>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rdi)
add    $0xf4240,%rax
mov    %rax,(%rdi)
mov    (%rsi),%rcx
sub    %rcx,%rax
mov    %rax,(%rdi)
ret

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

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