#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 */
double getMiliTimeDiff(struct timeval t_start, struct timeval t_end) {
  double dif = 0;
  double dif2 = 0;
  dif = (t_end.tv_sec - t_start.tv_sec) * 1000;
  if (t_end.tv_usec < t_start.tv_usec) {
    dif -= 1000;
    t_end.tv_usec += 1000000;
  }
  dif2 = (t_end.tv_usec - t_start.tv_usec) / 1000.0;
  dif += dif2;
  return dif;
}


x86 assembly (clang, -O0):
<getMiliTimeDiff>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %edx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%eax
sub    -0x10(%rbp),%eax
imul   $0x3e8,%eax,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1169 <getMiliTimeDiff+0x69>
movsd  -0x28(%rbp),%xmm0
movsd  0xeae(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe82(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<getMiliTimeDiff>:
sub    %edi,%edx
imul   $0x3e8,%edx,%eax
cvtsi2sd %eax,%xmm1
lea    0xf4240(%rcx),%rax
cmp    %rsi,%rcx
cmovge %rcx,%rax
jge    1124 <getMiliTimeDiff+0x24>
addsd  0xedc(%rip),%xmm1
sub    %rsi,%rax
cvtsi2sd %rax,%xmm0
divsd  0xed4(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define double @getMiliTimeDiff(i32 %0, i64 %1, i32 %2, i64 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca double
%8 = alloca double
%9 = bitcast %struct.timeval* %5 to { i32, i64 }*
%10 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %9, i32 0, i32 0
store i32 %0, i32* %10
%11 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %9, i32 0, i32 1
store i64 %1, i64* %11
%12 = bitcast %struct.timeval* %6 to { i32, i64 }*
%13 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 0
store i32 %2, i32* %13
%14 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %12, i32 0, i32 1
store i64 %3, i64* %14
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%18 = load i32, i32* %17
%19 = sub nsw i32 %16, %18
%20 = mul nsw i32 %19, 1000
%21 = sitofp i32 %20 to double
store double %21, double* %7
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%23 = load i64, i64* %22
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%25 = load i64, i64* %24
%26 = icmp slt i64 %23, %25
br i1 %26, label %27, label %33
27: ; preds = %4
%28 = load double, double* %7
%29 = fsub double %28, 1.000000e+03
store double %29, double* %7
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%31 = load i64, i64* %30
%32 = add nsw i64 %31, 1000000
store i64 %32, i64* %30
br label %33
33: ; preds = %27, %4
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%35 = load i64, i64* %34
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%37 = load i64, i64* %36
%38 = sub nsw i64 %35, %37
%39 = sitofp i64 %38 to double
%40 = fdiv double %39, 1.000000e+03
store double %40, double* %8
%41 = load double, double* %8
%42 = load double, double* %7
%43 = fadd double %42, %41
store double %43, double* %7
%44 = load double, double* %7
ret double %44
}

LLVM IR (-O2):
define double @getMiliTimeDiff(i32 %0, i64 %1, i32 %2, i64 %3) {
%5 = sub nsw i32 %2, %0
%6 = mul nsw i32 %5, 1000
%7 = sitofp i32 %6 to double
%8 = icmp slt i64 %3, %1
%9 = fadd double %7, -1.000000e+03
%10 = add nsw i64 %3, 1000000
%11 = select i1 %8, i64 %10, i64 %3
%12 = select i1 %8, double %9, double %7
%13 = sub nsw i64 %11, %1
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+03
%16 = fadd double %12, %15
ret double %16
}