#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 */
typedef long time_t;
struct timespec {
  long tv_sec;
  long tv_nsec;
};

/* Variables and functions */
void tsConvertToMs(struct timespec time, time_t *millis, time_t *millis_fract) {
  if (time.tv_sec != 0) {
    *millis = time.tv_sec * 1000L;
  } else {
    *millis = 0;
  }
  if (time.tv_nsec != 0) {
    *millis += time.tv_nsec / 1000000L;
    *millis_fract = time.tv_nsec % 1000000L;
  }
}


x86 assembly (clang, -O0):
<tsConvertToMs>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1133 <tsConvertToMs+0x33>
imul   $0x3e8,-0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    113e <tsConvertToMs+0x3e>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x8(%rbp)
je     1179 <tsConvertToMs+0x79>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    -0x20(%rbp),%rax
mov    %rdx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<tsConvertToMs>:
imul   $0x3e8,%rdi,%rdi
mov    %rdi,(%rdx)
test   %rsi,%rsi
je     1143 <tsConvertToMs+0x43>
mov    %rdx,%r8
movabs $0x431bde82d7b634db,%rdx
de 1b 43
mov    %rsi,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rax,%rdx
add    %rdx,%rdi
mov    %rdi,(%r8)
imul   $0xf4240,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,(%rcx)
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define void @tsConvertToMs(i64 %0, i64 %1, i64* %2, i64* %3) {
%5 = alloca %struct.timespec
%6 = alloca i64*
%7 = alloca i64*
%8 = bitcast %struct.timespec* %5 to { i64, i64 }*
%9 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
store i64* %2, i64** %6
store i64* %3, i64** %7
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %4
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%16 = load i64, i64* %15
%17 = mul nsw i64 %16, 1000
%18 = load i64*, i64** %6
store i64 %17, i64* %18
br label %21
19: ; preds = %4
%20 = load i64*, i64** %6
store i64 0, i64* %20
br label %21
21: ; preds = %19, %14
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%23 = load i64, i64* %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %36
25: ; preds = %21
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%27 = load i64, i64* %26
%28 = sdiv i64 %27, 1000000
%29 = load i64*, i64** %6
%30 = load i64, i64* %29
%31 = add nsw i64 %30, %28
store i64 %31, i64* %29
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%33 = load i64, i64* %32
%34 = srem i64 %33, 1000000
%35 = load i64*, i64** %7
store i64 %34, i64* %35
br label %36
36: ; preds = %25, %21
ret void
}

LLVM IR (-O2):
define void @tsConvertToMs(i64 %0, i64 %1, i64* nocapture %2, i64* nocapture writeonly %3) {
%5 = mul i64 %0, 1000
store i64 %5, i64* %2
%6 = icmp eq i64 %1, 0
br i1 %6, label %11, label %7
7: ; preds = %4
%8 = sdiv i64 %1, 1000000
%9 = add nsw i64 %8, %5
store i64 %9, i64* %2
%10 = srem i64 %1, 1000000
store i64 %10, i64* %3
br label %11
11: ; preds = %7, %4
ret void
}