#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 */
double floor(double);
int nanosleep(struct timespec *, struct timespec *);
void sleeper(double sec) {
  struct timespec req;
  struct timespec rem;
  req.tv_sec = floor(sec);
  req.tv_nsec = (sec - floor(sec)) * 1000000000ULL;
  int r = -1;
  while (r) {
    r = nanosleep(&req, &rem);
    req = rem;
  }
}


x86 assembly (clang, -O0):
<sleeper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  0xe9c(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movl   $0xffffffff,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
je     11a3 <sleeper+0x83>
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <nanosleep@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1174 <sleeper+0x54>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleeper>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  %xmm0,0x10(%rsp)
call   1040 <floor@plt>
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xebc(%rip),%xmm1
movsd  %xmm0,(%rsp)
movsd  %xmm1,0x8(%rsp)
mov    %rsp,%r14
lea    0x18(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
movupd 0x18(%rsp),%xmm0
movapd %xmm0,(%rsp)
test   %eax,%eax
jne    1160 <sleeper+0x40>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
define void @sleeper(double %0) {
%2 = alloca double
%3 = alloca %struct.timespec
%4 = alloca %struct.timespec
%5 = alloca i32
store double %0, double* %2
%6 = load double, double* %2
%7 = call double @llvm.floor.f64(double %6)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store double %7, double* %8
%9 = load double, double* %2
%10 = load double, double* %2
%11 = call double @llvm.floor.f64(double %10)
%12 = fsub double %9, %11
%13 = fmul double %12, 1.000000e+09
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store double %13, double* %14
store i32 -1, i32* %5
br label %15
15: ; preds = %18, %1
%16 = load i32, i32* %5
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %4)
store i32 %19, i32* %5
%20 = bitcast %struct.timespec* %3 to i8*
%21 = bitcast %struct.timespec* %4 to i8*
br label %15
22: ; preds = %15
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
define void @sleeper(double %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast %struct.timespec* %3 to i8*
%6 = tail call double @llvm.floor.f64(double %0)
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store double %6, double* %7
%8 = fsub double %0, %6
%9 = fmul double %8, 1.000000e+09
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store double %9, double* %10
br label %11
11: ; preds = %1, %11
%12 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %11
14: ; preds = %11
ret void
}