#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;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
float getElapsedTime(struct timeval tval_start) {
  struct timeval tval_end, tval_diff;
  gettimeofday(&tval_end, NULL);
  tval_diff.tv_sec = tval_end.tv_sec - tval_start.tv_sec;
  tval_diff.tv_usec = tval_end.tv_usec - tval_start.tv_usec;
  if (tval_diff.tv_usec < 0) {
    --tval_diff.tv_sec;
    tval_diff.tv_usec += 1000000;
  }
  return (float)tval_diff.tv_sec + (float)tval_diff.tv_usec / 1000000;
}


x86 assembly (clang, -O0):
<getElapsedTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jge    116a <getElapsedTime+0x5a>
mov    -0x28(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x30(%rbp)
cvtsi2ssq -0x28(%rbp),%xmm0
cvtsi2ssq -0x30(%rbp),%xmm1
movss  0xe82(%rip),%xmm2
divss  %xmm2,%xmm1
addss  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getElapsedTime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
mov    0x10(%rsp),%rcx
sub    %rbx,%rcx
sub    %r14,%rax
lea    0xf4240(%rax),%rdx
mov    %rax,%rsi
sar    $0x3f,%rsi
add    %rcx,%rsi
test   %rax,%rax
cmovns %rax,%rdx
cvtsi2ss %rsi,%xmm1
cvtsi2ss %rdx,%xmm0
divss  0xe9d(%rip),%xmm0
addss  %xmm1,%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define float @getElapsedTime(i64 %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = bitcast %struct.timeval* %3 to { i64, i64 }*
%7 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %6, i32 0, i32 0
store i64 %0, i64* %7
%8 = getelementptr inbounds { i64, i64 }, { i64, 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 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%13 = load i64, i64* %12
%14 = sub nsw i64 %11, %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 %14, i64* %15
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%19 = load i64, i64* %18
%20 = sub nsw i64 %17, %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 %20, i64* %21
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%23 = load i64, i64* %22
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %32
25: ; preds = %2
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%27 = load i64, i64* %26
%28 = add nsw i64 %27, -1
store i64 %28, i64* %26
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%30 = load i64, i64* %29
%31 = add nsw i64 %30, 1000000
store i64 %31, i64* %29
br label %32
32: ; preds = %25, %2
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%34 = load i64, i64* %33
%35 = sitofp i64 %34 to float
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to float
%39 = fdiv float %38, 1.000000e+06
%40 = fadd float %35, %39
ret float %40
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define float @getElapsedTime(i64 %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 = sub i64 %7, %1
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = sub nsw i64 %10, %0
%12 = icmp slt i64 %11, 0
%13 = add nsw i64 %11, 1000000
%14 = ashr i64 %11, 63
%15 = add nsw i64 %8, %14
%16 = select i1 %12, i64 %13, i64 %11
%17 = sitofp i64 %15 to float
%18 = sitofp i64 %16 to float
%19 = fdiv float %18, 1.000000e+06
%20 = fadd float %19, %17
ret float %20
}