#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 timeval {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int select(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
void mysleep(double time) {
  int rc;
  struct timeval tv;
  tv.tv_sec = (int)time;
  tv.tv_usec = (int)(time * 1000000) % 1000000;
  for (;;) {
    rc = select(0, NULL, NULL, NULL, &tv);
    if ((rc == -1) && (errno == EINTR))
      continue;
    if (rc == 0)
      return;
  }
}


x86 assembly (clang, -O0):
<mysleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
cvttsd2si -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  0xed3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
xor    %edi,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rsi
mov    %rcx,%rdx
call   1030 <select@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1182 <mysleep+0x72>
mov    0x2e76(%rip),%rax
mov    (%rax),%rax
mov    0x2e64(%rip),%rcx
cmp    (%rcx),%rax
jne    1182 <mysleep+0x72>
jmp    1141 <mysleep+0x31>
cmpl   $0x0,-0xc(%rbp)
jne    1192 <mysleep+0x82>
add    $0x20,%rsp
pop    %rbp
ret
jmp    1141 <mysleep+0x31>

x86 assembly (clang, -O2):
<mysleep>:
push   %rbx
sub    $0x10,%rsp
cvttsd2si %xmm0,%eax
mulsd  0xedf(%rip),%xmm0
mov    %eax,0x8(%rsp)
cvttsd2si %xmm0,%eax
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rbx
xor    %edi,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
mov    %rbx,%r8
call   1030 <select@plt>
test   %eax,%eax
jne    1150 <mysleep+0x40>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @mysleep(double %0) {
%2 = alloca double
%3 = alloca i32
%4 = alloca %struct.timeval
store double %0, double* %2
%5 = load double, double* %2
%6 = fptosi double %5 to i32
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 0
store i32 %6, i32* %7
%8 = load double, double* %2
%9 = fmul double %8, 1.000000e+06
%10 = fptosi double %9 to i32
%11 = srem i32 %10, 1000000
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i32 0, i32 1
store i32 %11, i32* %12
br label %13
13: ; preds = %26, %21, %1
%14 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %4)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %17
br label %13
22: ; preds = %17, %13
%23 = load i32, i32* %3
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %22
ret void
26: ; preds = %22
br label %13
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @mysleep(double %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = fptosi double %0 to i32
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 %4, i32* %5
%6 = fmul double %0, 1.000000e+06
%7 = fptosi double %6 to i32
%8 = srem i32 %7, 1000000
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i32 %8, i32* %9
br label %10
10: ; preds = %10, %1
%11 = call i32 @select(i32 0, i32* null, i32* null, i32* null, %struct.timeval* %2)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %10
13: ; preds = %10
ret void
}