#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 msdiff(struct timeval *tm, struct timeval *prevtm) {
  long long diff;
  int answer;
  diff = (long long)1000000 * (long long)(tm->tv_sec - prevtm->tv_sec);
  diff = diff - (long long)prevtm->tv_usec + (long long)tm->tv_usec;
  diff = diff / (long long)1000;
  answer = (int)diff;
  return answer;
}


x86 assembly (clang, -O0):
<msdiff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
imul   $0xf4240,%rax,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    -0x8(%rbp),%rcx
add    (%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<msdiff>:
mov    0x8(%rdi),%rax
sub    0x8(%rsi),%rax
imul   $0xf4240,%rax,%rax
sub    (%rsi),%rax
add    (%rdi),%rax
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
shr    $0x7,%rdx
add    %edx,%eax
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @msdiff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i64
%6 = alloca i32
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 = mul nsw i64 1000000, %13
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = load %struct.timeval*, %struct.timeval** %4
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = sub nsw i64 %15, %18
%20 = load %struct.timeval*, %struct.timeval** %3
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %20, i32 0, i32 0
%22 = load i64, i64* %21
%23 = add nsw i64 %19, %22
store i64 %23, i64* %5
%24 = load i64, i64* %5
%25 = sdiv i64 %24, 1000
store i64 %25, i64* %5
%26 = load i64, i64* %5
%27 = trunc i64 %26 to i32
store i32 %27, i32* %6
%28 = load i32, i32* %6
ret i32 %28
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @msdiff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sub nsw i64 %4, %6
%8 = mul nsw i64 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i64, i64* %9
%11 = sub i64 %8, %10
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%13 = load i64, i64* %12
%14 = add nsw i64 %11, %13
%15 = sdiv i64 %14, 1000
%16 = trunc i64 %15 to i32
ret i32 %16
}