#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 */
void msec2tspec(int msec, struct timespec *ts) {
  if (msec) {
    ts->tv_sec = msec / 1000;
    ts->tv_nsec = (msec % 1000) * 1000000;
  } else {
    ts->tv_sec = 0;
    ts->tv_nsec = 0;
  }
}


x86 assembly (clang, -O0):
<msec2tspec>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1145 <msec2tspec+0x45>
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x4(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
imul   $0xf4240,%edx,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
jmp    115a <msec2tspec+0x5a>
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x10(%rbp),%rax
movl   $0x0,0x4(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<msec2tspec>:
test   %edi,%edi
je     112b <msec2tspec+0x2b>
movslq %edi,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
imul   $0x3e8,%eax,%ecx
sub    %ecx,%edi
imul   $0xf4240,%edi,%ecx
jmp    112f <msec2tspec+0x2f>
xor    %eax,%eax
xor    %ecx,%ecx
mov    %eax,(%rsi)
mov    %ecx,0x4(%rsi)
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @msec2tspec(i32 %0, %struct.timespec* %1) {
%3 = alloca i32
%4 = alloca %struct.timespec*
store i32 %0, i32* %3
store %struct.timespec* %1, %struct.timespec** %4
%5 = load i32, i32* %3
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %2
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 1000
%10 = load %struct.timespec*, %struct.timespec** %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = load i32, i32* %3
%13 = srem i32 %12, 1000
%14 = mul nsw i32 %13, 1000000
%15 = load %struct.timespec*, %struct.timespec** %4
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
store i32 %14, i32* %16
br label %22
17: ; preds = %2
%18 = load %struct.timespec*, %struct.timespec** %4
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 0
store i32 0, i32* %19
%20 = load %struct.timespec*, %struct.timespec** %4
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
store i32 0, i32* %21
br label %22
22: ; preds = %17, %7
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @msec2tspec(i32 %0, %struct.timespec* nocapture writeonly %1) {
%3 = icmp eq i32 %0, 0
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = sdiv i32 %0, 1000
%6 = srem i32 %0, 1000
%7 = mul nsw i32 %6, 1000000
br label %8
8: ; preds = %2, %4
%9 = phi i32 [ %5, %4 ], [ 0, %2 ]
%10 = phi i32 [ %7, %4 ], [ 0, %2 ]
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
store i32 %9, i32* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
store i32 %10, i32* %12
ret void
}