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


x86 assembly (clang, -O0):
<irmo_timeval_sub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
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    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jl     1156 <irmo_timeval_sub+0x56>
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    1183 <irmo_timeval_sub+0x83>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
mov    $0xf4240,%ecx
sub    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

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

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

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