#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);
scalar_t__ nanosleep(struct timespec *, struct timespec *);
int fsleep(double seconds) {
  struct timespec time, remaining;
  time.tv_sec = floor(seconds);
  time.tv_nsec = (seconds - floor(seconds)) * 1000000000.;
  if (nanosleep(&time, &remaining)) {
    return (double)remaining.tv_sec + (double)remaining.tv_nsec / 1000000000.;
  } else {
    return 0.0;
  }
}


x86 assembly (clang, -O0):
<fsleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x10(%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,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1030 <nanosleep@plt>
cmp    $0x0,%rax
je     11aa <fsleep+0x8a>
movsd  -0x30(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe6a(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    11b1 <fsleep+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fsleep>:
sub    $0x28,%rsp
movsd  %xmm0,(%rsp)
call   1040 <floor@plt>
movsd  %xmm0,0x18(%rsp)
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xebb(%rip),%xmm1
movsd  %xmm1,0x20(%rsp)
lea    0x18(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1030 <nanosleep@plt>
test   %rax,%rax
je     117c <fsleep+0x5c>
movsd  0x10(%rsp),%xmm0
divsd  0xe93(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%eax
add    $0x28,%rsp
ret
xor    %eax,%eax
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
define i32 @fsleep(double %0) {
%2 = alloca i32
%3 = alloca double
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
store double %0, double* %3
%6 = load double, double* %3
%7 = call double @llvm.floor.f64(double %6)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store double %7, double* %8
%9 = load double, double* %3
%10 = load double, double* %3
%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* %4, i32 0, i32 1
store double %13, double* %14
%15 = call i64 @nanosleep(%struct.timespec* %4, %struct.timespec* %5)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %25
17: ; preds = %1
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%19 = load double, double* %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%21 = load double, double* %20
%22 = fdiv double %21, 1.000000e+09
%23 = fadd double %19, %22
%24 = fptosi double %23 to i32
store i32 %24, i32* %2
br label %26
25: ; preds = %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %17
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
define i32 @fsleep(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
%11 = call i64 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%12 = icmp eq i64 %11, 0
br i1 %12, label %21, label %13
13: ; preds = %1
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%15 = load double, double* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%17 = load double, double* %16
%18 = fdiv double %17, 1.000000e+09
%19 = fadd double %15, %18
%20 = fptosi double %19 to i32
br label %21
21: ; preds = %1, %13
%22 = phi i32 [ %20, %13 ], [ 0, %1 ]
ret i32 %22
}