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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
long timer_end(struct timeval start_time) {
  struct timeval end_time;
  gettimeofday(&end_time, NULL);
  long elapsed = (end_time.tv_sec - start_time.tv_sec) * 1e6 +
                 end_time.tv_usec - start_time.tv_usec;
  return elapsed;
}


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

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

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i64 @timer_end(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 0
%7 = load i32, i32* %6
%8 = sub nsw i32 %7, %0
%9 = sitofp i32 %8 to double
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = tail call double @llvm.fmuladd.f64(double %9, double 1.000000e+06, double %12)
%14 = sitofp i64 %1 to double
%15 = fsub double %13, %14
%16 = fptosi double %15 to i64
ret i64 %16
}