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

/* Variables and functions */
int /*<<< orphan*/ dod_exit(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
double floor(int);
int nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void systime_sleep(double s) {
  struct timespec spec;
  double i = floor(s);
  spec.tv_sec = (time_t)i;
  s -= i;
  i = floor(1e+9 * s + .5);
  if (i >= 1e+9) {
    i -= 1.0;
    ++spec.tv_sec;
  }
  spec.tv_nsec = (long)i;
  int result = nanosleep(&spec, NULL);
  if (result != 0)
    dod_exit("nanosleep():%s", strerror(errno));
}


x86 assembly (clang, -O0):
<systime_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%edi
call   1060 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
cvttsd2si -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
movsd  -0x20(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe76(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11dd <systime_sleep+0x9d>
movsd  -0x20(%rbp),%xmm0
movsd  0xe48(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cvttsd2si -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <nanosleep@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     121d <systime_sleep+0xdd>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe00(%rip),%rdi
call   1030 <dod_exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<systime_sleep>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm0,0x8(%rsp)
cvttsd2si %xmm0,%edi
call   1060 <floor@plt>
cvttsd2si %xmm0,%rbx
mov    %rbx,0x18(%rsp)
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xe90(%rip),%xmm1
addsd  0xe90(%rip),%xmm1
cvttsd2si %xmm1,%edi
call   1060 <floor@plt>
ucomisd 0xe77(%rip),%xmm0
jb     119c <systime_sleep+0x5c>
addsd  0xe7d(%rip),%xmm0
add    $0x1,%rbx
mov    %rbx,0x18(%rsp)
cvttsd2si %xmm0,%rax
mov    %rax,0x10(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1040 <nanosleep@plt>
test   %eax,%eax
je     11d2 <systime_sleep+0x92>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe4d(%rip),%rdi
mov    %eax,%esi
call   1030 <dod_exit@plt>
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@.str = [15 x i8] c"nanosleep():%s\00"
@errno = global i32 0
define void @systime_sleep(double %0) {
%2 = alloca double
%3 = alloca %struct.timespec
%4 = alloca double
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = fptosi double %6 to i32
%8 = call double @floor(i32 %7)
store double %8, double* %4
%9 = load double, double* %4
%10 = fptosi double %9 to i64
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %10, i64* %11
%12 = load double, double* %4
%13 = load double, double* %2
%14 = fsub double %13, %12
store double %14, double* %2
%15 = load double, double* %2
%16 = call double @llvm.fmuladd.f64(double 1.000000e+09, double %15, double 5.000000e-01)
%17 = fptosi double %16 to i32
%18 = call double @floor(i32 %17)
store double %18, double* %4
%19 = load double, double* %4
%20 = fcmp oge double %19, 1.000000e+09
br i1 %20, label %21, label %27
21: ; preds = %1
%22 = load double, double* %4
%23 = fsub double %22, 1.000000e+00
store double %23, double* %4
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%25 = load i64, i64* %24
%26 = add nsw i64 %25, 1
store i64 %26, i64* %24
br label %27
27: ; preds = %21, %1
%28 = load double, double* %4
%29 = fptosi double %28 to i64
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i64 %29, i64* %30
%31 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* @errno
%36 = call i32 @strerror(i32 %35)
%37 = call i32 @dod_exit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %34, %27
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@.str = [15 x i8] c"nanosleep():%s\00"
@errno = global i32 0
define void @systime_sleep(double %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = fptosi double %0 to i32
%5 = tail call double @floor(i32 %4)
%6 = fptosi double %5 to i64
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %6, i64* %7
%8 = fsub double %0, %5
%9 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e+09, double 5.000000e-01)
%10 = fptosi double %9 to i32
%11 = tail call double @floor(i32 %10)
%12 = fcmp ult double %11, 1.000000e+09
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = fadd double %11, -1.000000e+00
%15 = add nsw i64 %6, 1
store i64 %15, i64* %7
br label %16
16: ; preds = %13, %1
%17 = phi double [ %14, %13 ], [ %11, %1 ]
%18 = fptosi double %17 to i64
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %18, i64* %19
%20 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i32, i32* @errno
%24 = call i32 @strerror(i32 %23)
%25 = call i32 @dod_exit(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %22, %16
ret void
}