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

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, struct timespec *);
long long flu_msleep(long long milliseconds) {
  struct timespec treq;
  treq.tv_sec = milliseconds / 1000;
  treq.tv_nsec = (milliseconds * 1000000) % 1000000000;
  struct timespec trem;
  trem.tv_sec = 0;
  trem.tv_nsec = 0;
  nanosleep(&treq, &trem);
  return trem.tv_sec * 1000 + trem.tv_nsec / 1000000;
}


x86 assembly (clang, -O0):
<flu_msleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x18(%rbp)
imul   $0xf4240,-0x8(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <nanosleep@plt>
imul   $0x3e8,-0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
add    %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flu_msleep>:
sub    $0x28,%rsp
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
mov    %rdx,0x18(%rsp)
imul   $0xf4240,%rdi,%rcx
movabs $0x112e0be826d694b3,%rdx
0b 2e 11
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
imul   $0x3b9aca00,%rdx,%rax
sub    %rax,%rcx
mov    %rcx,0x20(%rsp)
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
lea    0x18(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <nanosleep@plt>
imul   $0x3e8,(%rsp),%rcx
movabs $0x431bde82d7b634db,%rax
de 1b 43
imulq  0x8(%rsp)
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rdx
add    %rdx,%rax
add    %rcx,%rax
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define i64 @flu_msleep(i64 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = sdiv i64 %0, 1000
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %5, i64* %6
%7 = mul nsw i64 %0, 1000000
%8 = srem i64 %7, 1000000000
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %8, i64* %9
%10 = bitcast %struct.timespec* %3 to i8*
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%13 = bitcast %struct.timespec* %3 to i8*
%14 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%15 = load i64, i64* %11
%16 = mul nsw i64 %15, 1000
%17 = load i64, i64* %12
%18 = sdiv i64 %17, 1000000
%19 = add nsw i64 %18, %16
ret i64 %19
}