#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;
};
typedef int int64_t;
typedef int int32_t;

/* Variables and functions */
int64_t h2o_timeval_subtract(struct timeval *from, struct timeval *until) {
  int32_t delta_sec = (int32_t)until->tv_sec - (int32_t)from->tv_sec;
  int32_t delta_usec = (int32_t)until->tv_usec - (int32_t)from->tv_usec;
  int64_t delta = (int64_t)((int64_t)delta_sec * 1000 * 1000L) + delta_usec;
  return delta;
}


x86 assembly (clang, -O0):
<h2o_timeval_subtract>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %ecx,%eax
mov    %eax,-0x18(%rbp)
imul   $0x3e8,-0x14(%rbp),%eax
cltq
imul   $0x3e8,%rax,%rax
add    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<h2o_timeval_subtract>:
mov    0x8(%rsi),%rax
sub    0x8(%rdi),%rax
mov    (%rsi),%ecx
sub    (%rdi),%ecx
movabs $0x3e800000000,%rdx
imul   %rax,%rdx
shr    $0x20,%rdx
imul   $0x3e8,%edx,%eax
add    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @h2o_timeval_subtract(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%8 = load %struct.timeval*, %struct.timeval** %4
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = load %struct.timeval*, %struct.timeval** %3
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = sub nsw i32 %11, %15
store i32 %16, i32* %5
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = trunc i64 %23 to i32
%25 = sub nsw i32 %20, %24
store i32 %25, i32* %6
%26 = load i32, i32* %5
%27 = mul nsw i32 %26, 1000
%28 = sext i32 %27 to i64
%29 = mul nsw i64 %28, 1000
%30 = trunc i64 %29 to i32
%31 = load i32, i32* %6
%32 = add nsw i32 %30, %31
store i32 %32, i32* %7
%33 = load i32, i32* %7
ret i32 %33
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @h2o_timeval_subtract(%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 i64 %4, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = trunc i64 %9 to i32
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = sub i32 %10, %13
%15 = mul i64 %7, 4294967296000
%16 = lshr exact i64 %15, 32
%17 = trunc i64 %16 to i32
%18 = mul i32 %17, 1000
%19 = add nsw i32 %14, %18
ret i32 %19
}