#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 long tv_usec;
  scalar_t__ tv_sec;
};
typedef long long int64_t;

/* Variables and functions */
int /*<<< orphan*/ monotime(struct timeval *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval const *,
                            struct timeval *);
int64_t monotime_since(const struct timeval *ref, struct timeval *out) {
  struct timeval tv;
  monotime(&tv);
  timersub(&tv, ref, &tv);
  if (out)
    *out = tv;
  return (int64_t)tv.tv_sec * 1000000LL + tv.tv_usec;
}


x86 assembly (clang, -O0):
<monotime_since>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1030 <monotime@plt>
mov    -0x8(%rbp),%rsi
lea    -0x20(%rbp),%rdx
mov    %rdx,%rdi
call   1040 <timersub@plt>
cmpq   $0x0,-0x10(%rbp)
je     1167 <monotime_since+0x47>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    %rcx,0x8(%rax)
imul   $0xf4240,-0x18(%rbp),%rax
add    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monotime_since>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <monotime@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1040 <timersub@plt>
test   %r15,%r15
je     1155 <monotime_since+0x35>
movups (%rsp),%xmm0
movups %xmm0,(%r15)
imul   $0xf4240,0x8(%rsp),%rax
add    (%rsp),%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i64 @monotime_since(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = call i32 @monotime(%struct.timeval* %5)
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = call i32 @timersub(%struct.timeval* %5, %struct.timeval* %7, %struct.timeval* %5)
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = icmp ne %struct.timeval* %9, null
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load %struct.timeval*, %struct.timeval** %4
%13 = bitcast %struct.timeval* %12 to i8*
%14 = bitcast %struct.timeval* %5 to i8*
br label %15
15: ; preds = %11, %2
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%17 = load i64, i64* %16
%18 = mul nsw i64 %17, 1000000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%20 = load i64, i64* %19
%21 = add nsw i64 %18, %20
ret i64 %21
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i64 @monotime_since(%struct.timeval* %0, %struct.timeval* writeonly %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @monotime(%struct.timeval* %3)
%6 = call i32 @timersub(%struct.timeval* %3, %struct.timeval* %0, %struct.timeval* %3)
%7 = icmp eq %struct.timeval* %1, null
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = bitcast %struct.timeval* %1 to i8*
br label %10
10: ; preds = %8, %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%12 = load i64, i64* %11
%13 = mul nsw i64 %12, 1000000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%15 = load i64, i64* %14
%16 = add nsw i64 %13, %15
ret i64 %16
}