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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
uint64_t usec_diff(struct timeval start_time) {
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (uint64_t)((tv.tv_usec + tv.tv_sec * 1e6) -
                    (start_time.tv_usec + start_time.tv_sec * 1e6));
}


x86 assembly (clang, -O0):
<usec_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cvtsi2sdq -0x18(%rbp),%xmm1
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  0xec1(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdq -0x8(%rbp),%xmm2
cvtsi2sdl -0x10(%rbp),%xmm1
movsd  0xea6(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<usec_diff>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
cvtsi2sdl 0x8(%rsp),%xmm1
movsd  0xec4(%rip),%xmm2
mulsd  %xmm2,%xmm1
cvtsi2sd %rbx,%xmm3
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @usec_diff(i32 %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %3 to { i32, i64 }*
%6 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %5, i32 0, i32 0
store i32 %0, i32* %6
%7 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %5, i32 0, i32 1
store i64 %1, i64* %7
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%13 = load i32, i32* %12
%14 = sitofp i32 %13 to double
%15 = call double @llvm.fmuladd.f64(double %14, double 1.000000e+06, double %11)
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = sitofp i32 %20 to double
%22 = call double @llvm.fmuladd.f64(double %21, double 1.000000e+06, double %18)
%23 = fsub double %15, %22
%24 = fptosi double %23 to i32
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @usec_diff(i32 %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%7 = load i64, i64* %6
%8 = sitofp i64 %7 to double
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sitofp i32 %10 to double
%12 = tail call double @llvm.fmuladd.f64(double %11, double 1.000000e+06, double %8)
%13 = sitofp i64 %1 to double
%14 = sitofp i32 %0 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double 1.000000e+06, double %13)
%16 = fsub double %12, %15
%17 = fptosi double %16 to i32
ret i32 %17
}