#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;
  void *tv_nsec;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
void *floor(double);
struct timespec ms_to_time(double ms) {
  struct timespec ts = {0};
  ts.tv_sec = floor(ms / 1000.0);
  ts.tv_nsec = floor((ms - ts.tv_sec * 1000) * 1000.0 * 1000.0);
  return ts;
}


x86 assembly (clang, -O0):
<ms_to_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rdi,%rax
mov    %rax,-0x10(%rbp)
movsd  %xmm0,-0x8(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
movsd  -0x8(%rbp),%xmm0
movsd  0xeaf(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    -0x18(%rbp),%rdi
mov    %eax,(%rdi)
movsd  -0x8(%rbp),%xmm0
imul   $0x3e8,(%rdi),%eax
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe79(%rip),%xmm1
mulsd  %xmm1,%xmm0
call   1040 <floor@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,0x8(%rdi)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ms_to_time>:
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,0x8(%rsp)
mov    %rdi,%rbx
xorps  %xmm1,%xmm1
movups %xmm1,(%rdi)
movq   $0x0,0x10(%rdi)
divsd  0xecc(%rip),%xmm0
call   1030 <floor@plt>
imul   $0x3e8,%eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
mov    %eax,(%rbx)
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  0xea6(%rip),%xmm0
mulsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <floor@plt>
mov    %rax,0x8(%rbx)
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i8*, i32 }
define void @ms_to_time(%struct.timespec* noalias sret(%struct.timespec) align 8 %0, double %1) {
%3 = alloca double
store double %1, double* %3
%4 = bitcast %struct.timespec* %0 to i8*
%5 = load double, double* %3
%6 = fdiv double %5, 1.000000e+03
%7 = call i8* @floor(double %6)
%8 = ptrtoint i8* %7 to i32
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
store i32 %8, i32* %9
%10 = load double, double* %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
%12 = load i32, i32* %11
%13 = mul nsw i32 %12, 1000
%14 = sitofp i32 %13 to double
%15 = fsub double %10, %14
%16 = fmul double %15, 1.000000e+03
%17 = fmul double %16, 1.000000e+03
%18 = call i8* @floor(double %17)
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
store i8* %18, i8** %19
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i8*, i32 }
define void @ms_to_time(%struct.timespec* noalias nocapture writeonly sret(%struct.timespec) align 8 %0, double %1) {
%3 = bitcast %struct.timespec* %0 to i8*
tail call void @llvm.memset.p0i8.i64(i8* align 8 dereferenceable(24) %3, i8 0, i64 24, i1 false)
%4 = fdiv double %1, 1.000000e+03
%5 = tail call i8* @floor(double %4)
%6 = ptrtoint i8* %5 to i64
%7 = trunc i64 %6 to i32
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i32 %7, i32* %8
%9 = mul nsw i32 %7, 1000
%10 = sitofp i32 %9 to double
%11 = fsub double %1, %10
%12 = fmul double %11, 1.000000e+03
%13 = fmul double %12, 1.000000e+03
%14 = tail call i8* @floor(double %13)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i8* %14, i8** %15
ret void
}