#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 */
typedef scalar_t__ uint64_t;
struct timeval {
  int tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
uint64_t timeval_diff_us(struct timeval *stop, struct timeval *start) {
  uint64_t durr_us = 0;
  if (stop && start) {
    durr_us = (stop->tv_sec - start->tv_sec) * 1000000 + stop->tv_usec -
              start->tv_usec;
  }
  return durr_us;
}


x86 assembly (clang, -O0):
<timeval_diff_us>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1152 <timeval_diff_us+0x52>
cmpq   $0x0,-0x10(%rbp)
je     1152 <timeval_diff_us+0x52>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
imul   $0xf4240,%eax,%eax
cltq
mov    -0x8(%rbp),%rcx
add    0x8(%rcx),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_diff_us>:
xor    %eax,%eax
test   %rdi,%rdi
je     1127 <timeval_diff_us+0x27>
test   %rsi,%rsi
je     1127 <timeval_diff_us+0x27>
movslq (%rdi),%rax
movslq (%rsi),%rcx
sub    %rcx,%rax
imul   $0xf4240,%rax,%rcx
mov    0x8(%rdi),%rax
sub    0x8(%rsi),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i64 @timeval_diff_us(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
store i64 0, i64* %5
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = icmp ne %struct.timeval* %6, null
br i1 %7, label %8, label %29
8: ; preds = %2
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = icmp ne %struct.timeval* %9, null
br i1 %10, label %11, label %29
11: ; preds = %8
%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 = sub nsw i32 %14, %17
%19 = mul nsw i32 %18, 1000000
%20 = sext i32 %19 to i64
%21 = load %struct.timeval*, %struct.timeval** %3
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%23 = load i64, i64* %22
%24 = add nsw i64 %20, %23
%25 = load %struct.timeval*, %struct.timeval** %4
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = sub nsw i64 %24, %27
store i64 %28, i64* %5
br label %29
29: ; preds = %11, %8, %2
%30 = load i64, i64* %5
ret i64 %30
}

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