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

/* Variables and functions */
void sub_timeval(struct timeval *x, const struct timeval *y) {
  x->tv_sec -= y->tv_sec;
  if (x->tv_usec < y->tv_usec) {
    --x->tv_sec;
    x->tv_usec = x->tv_usec + (1000000 - y->tv_usec);
  } else
    x->tv_usec -= y->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),%eax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
jge    1163 <sub_timeval+0x63>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rdx
mov    $0xf4240,%eax
sub    (%rdx),%eax
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1173 <sub_timeval+0x73>
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%ecx
sub    %edx,%ecx
mov    %ecx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<sub_timeval>:
mov    0x8(%rdi),%rdx
sub    0x8(%rsi),%rdx
mov    %rdx,0x8(%rdi)
mov    (%rdi),%eax
mov    (%rsi),%ecx
cmp    %ecx,%eax
jge    1121 <sub_timeval+0x21>
add    $0xffffffffffffffff,%rdx
mov    %rdx,0x8(%rdi)
add    $0xf4240,%eax
sub    %ecx,%eax
mov    %eax,(%rdi)
ret

LLVM IR (-O0):
%struct.timeval = type { i32, 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 i32, i32* %13
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = icmp slt i32 %14, %17
br i1 %18, label %19, label %34
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 i32, i32* %25
%27 = load %struct.timeval*, %struct.timeval** %4
%28 = getelementptr inbounds %struct.timeval, %struct.timeval* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = sub nsw i32 1000000, %29
%31 = add nsw i32 %26, %30
%32 = load %struct.timeval*, %struct.timeval** %3
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 0
store i32 %31, i32* %33
br label %42
34: ; preds = %2
%35 = load %struct.timeval*, %struct.timeval** %4
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = load %struct.timeval*, %struct.timeval** %3
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sub nsw i32 %40, %37
store i32 %41, i32* %39
br label %42
42: ; preds = %34, %19
ret void
}

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