#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*/ CLOCK_MONOTONIC;
scalar_t__ EINTR;
int /*<<< orphan*/ TIMER_ABSTIME;
scalar_t__ clock_nanosleep(int /*<<< orphan*/, int /*<<< orphan*/,
                           struct timespec *, int /*<<< orphan*/ *);
int modfl(long double, long double *);
scalar_t__ os_time();
void os_sleep(long double t) {
  struct timespec tp;
  long double integral;
  t += os_time();
  tp.tv_nsec = (long)(modfl(t, &integral) * 1e9);
  tp.tv_sec = (time_t)integral;
  while (clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &tp, NULL) == EINTR)
    ;
}


x86 assembly (clang, -O0):
<os_sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
xor    %eax,%eax
call   1040 <os_time@plt>
mov    %rax,-0x40(%rbp)
fildll -0x40(%rbp)
fldt   -0x10(%rbp)
faddp  %st,%st(1)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
mov    %rsp,%rax
fstpt  (%rax)
lea    -0x30(%rbp),%rdi
call   1030 <modfl@plt>
cvtsi2sd %eax,%xmm0
movsd  0xe8f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x20(%rbp)
fldt   -0x30(%rbp)
fnstcw -0x42(%rbp)
movzwl -0x42(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x44(%rbp)
fldcw  -0x44(%rbp)
fistpll -0x38(%rbp)
fldcw  -0x42(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <clock_nanosleep@plt>
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%rax
jne    11d6 <os_sleep+0xa6>
jmp    11a2 <os_sleep+0x72>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<os_sleep>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
fldt   0x90(%rsp)
fstpt  0x34(%rsp)
xor    %eax,%eax
call   1040 <os_time@plt>
mov    %rax,0x20(%rsp)
fildll 0x20(%rsp)
fldt   0x34(%rsp)
faddp  %st,%st(1)
fstpt  (%rsp)
lea    0x50(%rsp),%rdi
call   1030 <modfl@plt>
cvtsi2sd %eax,%xmm0
mulsd  0xe8b(%rip),%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,0x40(%rsp)
fldt   0x50(%rsp)
fnstcw 0x1c(%rsp)
movzwl 0x1c(%rsp),%eax
or     $0xc00,%eax
mov    %ax,0x1e(%rsp)
fldcw  0x1e(%rsp)
fistpll 0x28(%rsp)
fldcw  0x1c(%rsp)
mov    0x28(%rsp),%rax
mov    %rax,0x48(%rsp)
mov    0x2e2d(%rip),%r14
mov    0x2e2e(%rip),%r15
lea    0x40(%rsp),%r12
mov    0x2e0a(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%edi
mov    (%r15),%esi
mov    %r12,%rdx
xor    %ecx,%ecx
call   1050 <clock_nanosleep@plt>
cmp    (%rbx),%rax
je     11d0 <os_sleep+0xa0>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
@EINTR = global i64 0
define void @os_sleep(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca %struct.timespec
%4 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %2
%5 = call i64 (...) @os_time()
%6 = sitofp i64 %5 to x86_fp80
%7 = load x86_fp80, x86_fp80* %2
%8 = fadd x86_fp80 %7, %6
store x86_fp80 %8, x86_fp80* %2
%9 = load x86_fp80, x86_fp80* %2
%10 = call i32 @modfl(x86_fp80 %9, x86_fp80* %4)
%11 = sitofp i32 %10 to double
%12 = fmul double %11, 1.000000e+09
%13 = fptosi double %12 to i64
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i64 %13, i64* %14
%15 = load x86_fp80, x86_fp80* %4
%16 = fptosi x86_fp80 %15 to i64
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i64 %16, i64* %17
br label %18
18: ; preds = %24, %1
%19 = load i32, i32* @CLOCK_MONOTONIC
%20 = load i32, i32* @TIMER_ABSTIME
%21 = call i64 @clock_nanosleep(i32 %19, i32 %20, %struct.timespec* %3, i32* null)
%22 = load i64, i64* @EINTR
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %18
br label %18
25: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@TIMER_ABSTIME = global i32 0
@EINTR = global i64 0
define void @os_sleep(x86_fp80 %0) {
%2 = alloca %struct.timespec
%3 = alloca x86_fp80
%4 = bitcast %struct.timespec* %2 to i8*
%5 = bitcast x86_fp80* %3 to i8*
%6 = tail call i64 (...) @os_time()
%7 = sitofp i64 %6 to x86_fp80
%8 = fadd x86_fp80 %7, %0
%9 = call i32 @modfl(x86_fp80 %8, x86_fp80* %3)
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 1.000000e+09
%12 = fptosi double %11 to i64
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %12, i64* %13
%14 = load x86_fp80, x86_fp80* %3
%15 = fptosi x86_fp80 %14 to i64
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %15, i64* %16
br label %17
17: ; preds = %17, %1
%18 = load i32, i32* @CLOCK_MONOTONIC
%19 = load i32, i32* @TIMER_ABSTIME
%20 = call i64 @clock_nanosleep(i32 %18, i32 %19, %struct.timespec* %2, i32* null)
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %17, label %23
23: ; preds = %17
ret void
}