#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 KheTestTimeOfDayEnd(struct timeval *tv) {
  struct timeval end_tv;
  gettimeofday(&end_tv, NULL);
  return (float)(end_tv.tv_sec - tv->tv_sec) +
         (float)(end_tv.tv_usec - tv->tv_usec) / 1000000.0;
}


x86 assembly (clang, -O0):
<KheTestTimeOfDayEnd>:
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    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%rax
cvtsi2ss %rax,%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2ss %rax,%xmm1
cvtss2sd %xmm1,%xmm1
movsd  0xea6(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<KheTestTimeOfDayEnd>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rax
sub    0x8(%rbx),%rax
cvtsi2ss %rax,%xmm0
mov    (%rsp),%rax
sub    (%rbx),%rax
cvtsi2ss %rax,%xmm1
cvtss2sd %xmm1,%xmm1
divsd  0xeb8(%rip),%xmm1
cvtss2sd %xmm0,%xmm0
addsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsd2ss %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define float @KheTestTimeOfDayEnd(%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 1
%6 = load i64, i64* %5
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%9 = load i64, i64* %8
%10 = sub nsw i64 %6, %9
%11 = sitofp i64 %10 to float
%12 = fpext float %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load %struct.timeval*, %struct.timeval** %2
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = sub nsw i64 %14, %17
%19 = sitofp i64 %18 to float
%20 = fpext float %19 to double
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %12, %21
%23 = fptrunc double %22 to float
ret float %23
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define float @KheTestTimeOfDayEnd(%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 1
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%8 = load i64, i64* %7
%9 = sub nsw i64 %6, %8
%10 = sitofp i64 %9 to float
%11 = fpext float %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%15 = load i64, i64* %14
%16 = sub nsw i64 %13, %15
%17 = sitofp i64 %16 to float
%18 = fpext float %17 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %19, %11
%21 = fptrunc double %20 to float
ret float %21
}