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

/* Variables and functions */
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
void sleep_seconds(double s) {
  struct timespec ts;
  ts.tv_sec = (time_t)s;
  ts.tv_nsec = (long)((s - ts.tv_sec) * 1000000000L);
  if (ts.tv_nsec > 999999999L) {
    ts.tv_nsec = 999999999L;
  } else if (ts.tv_nsec < 0L) {
    ts.tv_nsec = 0L;
  }
  nanosleep(&ts, NULL);
}


x86 assembly (clang, -O0):
<sleep_seconds>:
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
cvttsd2si %xmm0,%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x3b9ac9ff,-0x10(%rbp)
3b
jle    1161 <sleep_seconds+0x51>
movq   $0x3b9ac9ff,-0x10(%rbp)
3b
jmp    1179 <sleep_seconds+0x69>
cmpq   $0x0,-0x10(%rbp)
jge    1174 <sleep_seconds+0x64>
movq   $0x0,-0x10(%rbp)
jmp    1179 <sleep_seconds+0x69>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep_seconds>:
sub    $0x18,%rsp
movsd  %xmm0,0x8(%rsp)
subsd  %xmm0,%xmm0
mulsd  0xeda(%rip),%xmm0
cvttsd2si %xmm0,%rcx
mov    %rcx,0x10(%rsp)
mov    $0x3b9ac9ff,%eax
cmp    $0x3b9ac9ff,%rcx
jg     1145 <sleep_seconds+0x35>
test   %rcx,%rcx
jns    114a <sleep_seconds+0x3a>
xor    %eax,%eax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
define void @sleep_seconds(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 = fptosi double %10 to i64
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %11, i64* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%14 = load i64, i64* %13
%15 = icmp sgt i64 %14, 999999999
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 999999999, i64* %17
br label %25
18: ; preds = %1
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%20 = load i64, i64* %19
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 0, i64* %23
br label %24
24: ; preds = %22, %18
br label %25
25: ; preds = %24, %16
%26 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
define void @sleep_seconds(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 = fptosi double %6 to i64
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %7, i64* %8
%9 = icmp sgt i64 %7, 999999999
br i1 %9, label %12, label %10
10: ; preds = %1
%11 = icmp slt i64 %7, 0
br i1 %11, label %12, label %14
12: ; preds = %10, %1
%13 = phi i64 [ 999999999, %1 ], [ 0, %10 ]
store i64 %13, i64* %8
br label %14
14: ; preds = %12, %10
%15 = call i32 @nanosleep(%struct.timespec* %2, i32* null)
ret void
}