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

/* Variables and functions */
int timeval_subtract(struct timeval *result, struct timeval *t2,
                     struct timeval *t1) {
  unsigned int resolution = 1000000;
  long diff = t2->tv_usec + resolution * t2->tv_sec -
              (t1->tv_usec + resolution * t1->tv_sec);
  result->tv_sec = diff / resolution;
  result->tv_usec = diff % resolution;
  return diff < 0;
}


x86 assembly (clang, -O0):
<timeval_subtract>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xf4240,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x1c(%rbp),%ecx
mov    -0x10(%rbp),%rdx
imul   0x8(%rdx),%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    -0x18(%rbp),%rcx
mov    (%rcx),%rcx
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rsi
imul   0x8(%rsi),%edx
mov    %edx,%edx
add    %rdx,%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cqto
idiv   %rcx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x28(%rbp),%rax
mov    -0x1c(%rbp),%ecx
cqto
idiv   %rcx
mov    -0x8(%rbp),%rax
mov    %rdx,(%rax)
cmpq   $0x0,-0x28(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_subtract>:
imul   $0xf4240,0x8(%rsi),%ecx
imul   $0xf4240,0x8(%rdx),%eax
add    (%rsi),%rcx
add    (%rdx),%rax
sub    %rax,%rcx
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
mov    %edx,0x8(%rdi)
imul   $0xf4240,%rdx,%rax
mov    %rcx,%rdx
sub    %rax,%rdx
mov    %rdx,(%rdi)
shr    $0x3f,%rcx
mov    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i32 }
define i32 @timeval_subtract(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca i32
%8 = alloca i64
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
store i32 1000000, i32* %7
%9 = load %struct.timeval*, %struct.timeval** %5
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i32, i32* %7
%13 = load %struct.timeval*, %struct.timeval** %5
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = mul i32 %12, %15
%17 = zext i32 %16 to i64
%18 = add nsw i64 %11, %17
%19 = load %struct.timeval*, %struct.timeval** %6
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = load i32, i32* %7
%23 = load %struct.timeval*, %struct.timeval** %6
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = mul i32 %22, %25
%27 = zext i32 %26 to i64
%28 = add nsw i64 %21, %27
%29 = sub nsw i64 %18, %28
store i64 %29, i64* %8
%30 = load i64, i64* %8
%31 = load i32, i32* %7
%32 = zext i32 %31 to i64
%33 = sdiv i64 %30, %32
%34 = trunc i64 %33 to i32
%35 = load %struct.timeval*, %struct.timeval** %4
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 1
store i32 %34, i32* %36
%37 = load i64, i64* %8
%38 = load i32, i32* %7
%39 = zext i32 %38 to i64
%40 = srem i64 %37, %39
%41 = load %struct.timeval*, %struct.timeval** %4
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %41, i32 0, i32 0
store i64 %40, i64* %42
%43 = load i64, i64* %8
%44 = icmp slt i64 %43, 0
%45 = zext i1 %44 to i32
ret i32 %45
}

LLVM IR (-O2):
%struct.timeval = type { i64, i32 }
define i32 @timeval_subtract(%struct.timeval* nocapture writeonly %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i32, i32* %6
%8 = mul i32 %7, 1000000
%9 = zext i32 %8 to i64
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = load i32, i32* %12
%14 = mul i32 %13, 1000000
%15 = zext i32 %14 to i64
%16 = add i64 %5, %9
%17 = add i64 %11, %15
%18 = sub i64 %16, %17
%19 = sdiv i64 %18, 1000000
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %20, i32* %21
%22 = srem i64 %18, 1000000
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i64 %22, i64* %23
%24 = lshr i64 %18, 63
%25 = trunc i64 %24 to i32
ret i32 %25
}