#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 */
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ nanosleep(struct timespec *, struct timespec *);
void fsleep(double seconds) {
  struct timespec ts;
  ts.tv_sec = seconds;
  ts.tv_nsec = (seconds - ts.tv_sec) * 1000000000.0;
  errno = 0;
  while (nanosleep(&ts, &ts) && errno == EINTR)
    ;
}


x86 assembly (clang, -O0):
<fsleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xec7(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e97(%rip),%rax
movq   $0x0,(%rax)
lea    -0x18(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <nanosleep@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x19(%rbp)
je     1188 <fsleep+0x78>
mov    0x2e6b(%rip),%rax
mov    (%rax),%rax
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    1198 <fsleep+0x88>
jmp    119d <fsleep+0x8d>
jmp    1150 <fsleep+0x40>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsleep>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm0,(%rsp)
subsd  %xmm0,%xmm0
mulsd  0xed6(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2ea9(%rip),%r14
movq   $0x0,(%r14)
mov    %rsp,%rbx
mov    0x2e90(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
test   %rax,%rax
je     1168 <fsleep+0x58>
mov    (%r15),%rax
cmp    %rax,(%r14)
je     1150 <fsleep+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
@errno = global i64 0
@EINTR = global i64 0
define void @fsleep(double %0) {
%2 = alloca double
%3 = alloca %struct.timespec
store double %0, double* %2
%4 = load double, double* %2
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store double %4, double* %5
%6 = load double, double* %2
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%8 = load double, double* %7
%9 = fsub double %6, %8
%10 = fmul double %9, 1.000000e+09
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store double %10, double* %11
store i64 0, i64* @errno
br label %12
12: ; preds = %21, %1
%13 = call i64 @nanosleep(%struct.timespec* %3, %struct.timespec* %3)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %12
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br label %19
19: ; preds = %15, %12
%20 = phi i1 [ false, %12 ], [ %18, %15 ]
br i1 %20, label %21, label %22
21: ; preds = %19
br label %12
22: ; preds = %19
ret void
}

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