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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
double record_time_msec(struct timeval *begin) {
  struct timeval end;
  struct timeval diff;
  gettimeofday(&end, NULL);
  timersub(&end, begin, &diff);
  return (double)((&diff)->tv_sec * 1e3 + (double)(&diff)->tv_usec / 1e3);
}


x86 assembly (clang, -O0):
<record_time_msec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x8(%rbp),%rsi
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rdx
call   1040 <timersub@plt>
cvtsi2sdl -0x28(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xea3(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe97(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<record_time_msec>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbx
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <timersub@plt>
cvtsi2sdl 0x8(%rsp),%xmm0
cvtsi2sdq 0x10(%rsp),%xmm1
movsd  0xea2(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define double @record_time_msec(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = load %struct.timeval*, %struct.timeval** %2
%7 = call i32 @timersub(%struct.timeval* %3, %struct.timeval* %6, %struct.timeval* %4)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
%9 = load i32, i32* %8
%10 = sitofp i32 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+03
%15 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+03, double %14)
ret double %15
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define double @record_time_msec(%struct.timeval* %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* null)
%7 = call i32 @timersub(%struct.timeval* %2, %struct.timeval* %0, %struct.timeval* %3)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%9 = load i32, i32* %8
%10 = sitofp i32 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+03
%15 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+03, double %14)
ret double %15
}