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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int EINTR;
int clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/, struct timespec *,
                    struct timespec *);
double modf(double, double *);
void sleep_double(double time) {
  struct timespec t, x;
  double intpart, fractpart;
  int rc;
  fractpart = modf(time, &intpart);
  t.tv_sec = intpart;
  t.tv_nsec = fractpart * 1000000000;
  do {
    rc = clock_nanosleep(CLOCK_MONOTONIC, 0, &t, &x);
    t.tv_sec = x.tv_sec;
    t.tv_nsec = x.tv_nsec;
  } while (rc == EINTR);
}


x86 assembly (clang, -O0):
<sleep_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x30(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xeae(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1040 <clock_nanosleep@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x3c(%rbp),%eax
mov    0x2e43(%rip),%rcx
cmp    (%rcx),%eax
je     115c <sleep_double+0x3c>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep_double>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r14
mov    %r14,%rdi
call   1030 <modf@plt>
mulsd  0xec2(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2e9d(%rip),%r15
lea    0x10(%rsp),%r12
mov    0x2e81(%rip),%rbx
nopw   0x0(%rax,%rax,1)
mov    (%r15),%edi
xor    %esi,%esi
mov    %r14,%rdx
mov    %r12,%rcx
call   1040 <clock_nanosleep@plt>
movapd 0x10(%rsp),%xmm0
movapd %xmm0,(%rsp)
cmp    (%rbx),%eax
je     1160 <sleep_double+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
@CLOCK_MONOTONIC = global i32 0
@EINTR = global i32 0
define void @sleep_double(double %0) {
%2 = alloca double
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %2
%8 = load double, double* %2
%9 = call double @modf(double %8, double* %5)
store double %9, double* %6
%10 = load double, double* %5
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store double %10, double* %11
%12 = load double, double* %6
%13 = fmul double %12, 1.000000e+09
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store double %13, double* %14
br label %15
15: ; preds = %24, %1
%16 = load i32, i32* @CLOCK_MONOTONIC
%17 = call i32 @clock_nanosleep(i32 %16, i32 0, %struct.timespec* %3, %struct.timespec* %4)
store i32 %17, i32* %7
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%19 = load double, double* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store double %19, double* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%22 = load double, double* %21
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store double %22, double* %23
br label %24
24: ; preds = %15
%25 = load i32, i32* %7
%26 = load i32, i32* @EINTR
%27 = icmp eq i32 %25, %26
br i1 %27, label %15, label %28
28: ; preds = %24
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
@CLOCK_MONOTONIC = global i32 0
@EINTR = global i32 0
define void @sleep_double(double %0) {
%2 = alloca <2 x double>
%3 = bitcast <2 x double>* %2 to %struct.timespec*
%4 = alloca <2 x double>
%5 = bitcast <2 x double>* %4 to %struct.timespec*
%6 = bitcast <2 x double>* %2 to i8*
%7 = bitcast <2 x double>* %4 to i8*
%8 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 0
%9 = call double @modf(double %0, double* %8)
%10 = fmul double %9, 1.000000e+09
%11 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 1
store double %10, double* %11
br label %12
12: ; preds = %12, %1
%13 = load i32, i32* @CLOCK_MONOTONIC
%14 = call i32 @clock_nanosleep(i32 %13, i32 0, %struct.timespec* %3, %struct.timespec* %5)
%15 = load <2 x double>, <2 x double>* %4
store <2 x double> %15, <2 x double>* %2
%16 = load i32, i32* @EINTR
%17 = icmp eq i32 %14, %16
br i1 %17, label %12, label %18
18: ; preds = %12
ret void
}