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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
unsigned long DiffMillis(struct timeval *time1, struct timeval *time2) {
  double temp = 0;
  assert(time1 != NULL);
  assert(time2 != NULL);
  temp = time1->tv_sec - time2->tv_sec;
  temp *= 1000;
  temp += (time1->tv_usec - time2->tv_usec) / 1000;
  return temp;
}


x86 assembly (clang, -O0):
<DiffMillis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x10(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%ecx
sub    %ecx,%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe48(%rip),%xmm2
movaps %xmm0,%xmm1
subsd  %xmm2,%xmm1
cvttsd2si %xmm1,%rcx
cvttsd2si %xmm0,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
and    %rdx,%rcx
or     %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DiffMillis>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1030 <assert@plt>
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1030 <assert@plt>
movsd  (%rbx),%xmm0
subsd  (%r14),%xmm0
mulsd  0xeb9(%rip),%xmm0
mov    0x8(%rbx),%eax
sub    0x8(%r14),%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xe88(%rip),%xmm1
cvttsd2si %xmm1,%rax
and    %rdx,%rax
or     %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, i32 }
define i64 @DiffMillis(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca double
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
store double 0.000000e+00, double* %5
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = icmp ne %struct.timeval* %6, null
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load %struct.timeval*, %struct.timeval** %4
%11 = icmp ne %struct.timeval* %10, null
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 0
%16 = load double, double* %15
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load double, double* %18
%20 = fsub double %16, %19
store double %20, double* %5
%21 = load double, double* %5
%22 = fmul double %21, 1.000000e+03
store double %22, double* %5
%23 = load %struct.timeval*, %struct.timeval** %3
%24 = getelementptr inbounds %struct.timeval, %struct.timeval* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.timeval*, %struct.timeval** %4
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = sub nsw i32 %25, %28
%30 = sdiv i32 %29, 1000
%31 = sitofp i32 %30 to double
%32 = load double, double* %5
%33 = fadd double %32, %31
store double %33, double* %5
%34 = load double, double* %5
%35 = fptoui double %34 to i64
ret i64 %35
}

LLVM IR (-O2):
%struct.timeval = type { double, i32 }
define i64 @DiffMillis(%struct.timeval* %0, %struct.timeval* %1) {
%3 = icmp ne %struct.timeval* %0, null
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = icmp ne %struct.timeval* %1, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%10 = load double, double* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%12 = load double, double* %11
%13 = fsub double %10, %12
%14 = fmul double %13, 1.000000e+03
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%18 = load i32, i32* %17
%19 = sub nsw i32 %16, %18
%20 = sdiv i32 %19, 1000
%21 = sitofp i32 %20 to double
%22 = fadd double %14, %21
%23 = fptoui double %22 to i64
ret i64 %23
}