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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/);
float latency(void (*request)()) {
  struct timeval begin, end;
  float time_spent;
  gettimeofday(&begin, 0);
  request();
  gettimeofday(&end, 0);
  time_spent = (end.tv_sec - begin.tv_sec) * 1000.0f +
               (end.tv_usec - begin.tv_usec) / 1000.0f;
  return time_spent;
}


x86 assembly (clang, -O0):
<latency>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    $0x0,%al
call   *-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movss  -0x18(%rbp),%xmm0
subss  -0x10(%rbp),%xmm0
movss  -0x14(%rbp),%xmm1
subss  -0xc(%rbp),%xmm1
movss  0xead(%rip),%xmm2
divss  %xmm2,%xmm1
movss  0xea1(%rip),%xmm2
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<latency>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xor    %eax,%eax
call   *%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movss  (%rsp),%xmm0
movss  0x4(%rsp),%xmm1
subss  0x8(%rsp),%xmm0
subss  0xc(%rsp),%xmm1
movss  0xeaf(%rip),%xmm2
divss  %xmm2,%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { float, float }
define float @latency(void (...)* %0) {
%2 = alloca void (...)*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
%5 = alloca float
store void (...)* %0, void (...)** %2
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%7 = load void (...)*, void (...)** %2
%8 = call i32 @gettimeofday(%struct.timeval* %4, i32 0)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%10 = load float, float* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load float, float* %11
%13 = fsub float %10, %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%15 = load float, float* %14
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load float, float* %16
%18 = fsub float %15, %17
%19 = fdiv float %18, 1.000000e+03
%20 = call float @llvm.fmuladd.f32(float %13, float 1.000000e+03, float %19)
store float %20, float* %5
%21 = load float, float* %5
ret float %21
}

LLVM IR (-O2):
%struct.timeval = type { float, float }
define float @latency(void (...)* nocapture %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timeval* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32 0)
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32 0)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load float, float* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load float, float* %10
%12 = fsub float %9, %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%14 = load float, float* %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%16 = load float, float* %15
%17 = fsub float %14, %16
%18 = fdiv float %17, 1.000000e+03
%19 = call float @llvm.fmuladd.f32(float %12, float 1.000000e+03, float %18)
ret float %19
}