#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*/ printf(char *, double);
int /*<<< orphan*/ timeval_normalize(struct timeval *);
void print_tv_diff(struct timeval *tv1, struct timeval *tv2) {
  struct timeval diff;
  diff.tv_sec = tv1->tv_sec - tv2->tv_sec;
  diff.tv_usec = tv1->tv_usec - tv2->tv_usec;
  timeval_normalize(&diff);
  double diff_ms;
  diff_ms =
      (double)1000 * (double)diff.tv_sec + (double)diff.tv_usec / (double)1000;
  printf("Diff = %fms\n", diff_ms);
}


x86 assembly (clang, -O0):
<print_tv_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x20(%rbp)
lea    -0x20(%rbp),%rdi
call   1040 <timeval_normalize@plt>
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe8d(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe81(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe70(%rip),%rdi
call   1030 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_tv_diff>:
sub    $0x18,%rsp
movdqu (%rdi),%xmm0
movdqu (%rsi),%xmm1
psubq  %xmm1,%xmm0
movdqa %xmm0,(%rsp)
mov    %rsp,%rdi
call   1040 <timeval_normalize@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%rsp),%xmm1
movsd  0xea8(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"Diff = %fms\0A\00"
define void @print_tv_diff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
%6 = alloca double
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%9 = load i64, i64* %8
%10 = load %struct.timeval*, %struct.timeval** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %9, %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 %13, i64* %14
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 0
%20 = load i64, i64* %19
%21 = sub nsw i64 %17, %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i64 %21, i64* %22
%23 = call i32 @timeval_normalize(%struct.timeval* %5)
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%25 = load i64, i64* %24
%26 = sitofp i64 %25 to double
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%28 = load i64, i64* %27
%29 = sitofp i64 %28 to double
%30 = fdiv double %29, 1.000000e+03
%31 = call double @llvm.fmuladd.f64(double 1.000000e+03, double %26, double %30)
store double %31, double* %6
%32 = load double, double* %6
%33 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %32)
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [13 x i8] c"Diff = %fms\0A\00"
define void @print_tv_diff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = alloca <2 x i64>
%4 = bitcast <2 x i64>* %3 to %struct.timeval*
%5 = bitcast <2 x i64>* %3 to i8*
%6 = getelementptr inbounds <2 x i64>, <2 x i64>* %3, i64 0, i64 1
%7 = bitcast %struct.timeval* %0 to <2 x i64>*
%8 = load <2 x i64>, <2 x i64>* %7
%9 = bitcast %struct.timeval* %1 to <2 x i64>*
%10 = load <2 x i64>, <2 x i64>* %9
%11 = sub nsw <2 x i64> %8, %10
%12 = getelementptr inbounds <2 x i64>, <2 x i64>* %3, i64 0, i64 0
store <2 x i64> %11, <2 x i64>* %3
%13 = call i32 @timeval_normalize(%struct.timeval* %4)
%14 = load i64, i64* %6
%15 = sitofp i64 %14 to double
%16 = load i64, i64* %12
%17 = sitofp i64 %16 to double
%18 = fdiv double %17, 1.000000e+03
%19 = call double @llvm.fmuladd.f64(double %15, double 1.000000e+03, double %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %19)
ret void
}