#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 timespec {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
unsigned int timespec_sub_ms(struct timespec *a, struct timespec *b) {
  return (a->tv_sec * 1000 + a->tv_nsec / (1000 * 1000) -
          (b->tv_sec * 1000 + b->tv_nsec / (1000 * 1000)));
}


x86 assembly (clang, -O0):
<timespec_sub_ms>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3e8,(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3e8,(%rax),%ecx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    $0xf4240,%esi
cltd
idiv   %esi
mov    %eax,%edx
mov    -0x14(%rbp),%eax
add    %edx,%ecx
sub    %ecx,%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_sub_ms>:
mov    (%rdi),%eax
movslq 0x4(%rdi),%rcx
imul   $0x431bde83,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
movslq 0x4(%rsi),%rdx
imul   $0xffffffffbce4217d,%rdx,%rdx
mov    %rdx,%rdi
shr    $0x3f,%rdi
sar    $0x32,%rdx
add    %edi,%edx
add    %ecx,%edx
sub    (%rsi),%eax
imul   $0x3e8,%eax,%eax
add    %edx,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @timespec_sub_ms(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
%5 = load %struct.timespec*, %struct.timespec** %3
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%7 = load i32, i32* %6
%8 = mul nsw i32 %7, 1000
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%11 = load i32, i32* %10
%12 = sdiv i32 %11, 1000000
%13 = add nsw i32 %8, %12
%14 = load %struct.timespec*, %struct.timespec** %4
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1000
%18 = load %struct.timespec*, %struct.timespec** %4
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 1
%20 = load i32, i32* %19
%21 = sdiv i32 %20, 1000000
%22 = add nsw i32 %17, %21
%23 = sub nsw i32 %13, %22
ret i32 %23
}

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