#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_usec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double getTimeElapsed(struct timeval *begTime) {
  struct timeval curTime;
  gettimeofday(&curTime, NULL);
  return (double)((curTime.tv_usec - (*begTime).tv_usec) / 1000000. +
                  curTime.tv_sec - (*begTime).tv_sec);
}


x86 assembly (clang, -O0):
<getTimeElapsed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
movsd  0xec2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm1
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
subsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTimeElapsed>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%eax
sub    (%rbx),%eax
cvtsi2sd %eax,%xmm1
divsd  0xecd(%rip),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rbx),%xmm1
subsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define double @getTimeElapsed(%struct.timeval* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%6 = load i32, i32* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = sub nsw i32 %6, %8
%10 = sitofp i32 %9 to double
%11 = fdiv double %10, 1.000000e+06
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fadd double %11, %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = fsub double %15, %18
ret double %19
}