#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_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int nanosleep(struct timespec *, struct timespec *);
int sleepu(double usec) {
  struct timespec req, rem;
  int r;
  req.tv_sec = 0;
  req.tv_nsec = usec * 1000;
  while ((r = nanosleep(&req, &rem)) == -1 && errno == EINTR)
    req = rem;
  return r;
}


x86 assembly (clang, -O0):
<sleepu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movsd  0xed3(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <nanosleep@plt>
mov    %eax,%ecx
mov    %ecx,-0x2c(%rbp)
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x2d(%rbp)
jne    1171 <sleepu+0x61>
mov    0x2e82(%rip),%rax
mov    (%rax),%rax
mov    0x2e70(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2d(%rbp)
mov    -0x2d(%rbp),%al
test   $0x1,%al
jne    1181 <sleepu+0x71>
jmp    1196 <sleepu+0x86>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
jmp    1137 <sleepu+0x27>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleepu>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
movq   $0x0,0x8(%rsp)
mulsd  0xed4(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    %rsp,%rdi
lea    0x18(%rsp),%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    1194 <sleepu+0x84>
mov    0x2e96(%rip),%r15
mov    0x2e87(%rip),%r12
mov    (%r12),%rcx
cmp    %rcx,(%r15)
jne    1194 <sleepu+0x84>
mov    %rsp,%r14
lea    0x18(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movupd 0x18(%rsp),%xmm0
movapd %xmm0,(%rsp)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    1194 <sleepu+0x84>
mov    (%r12),%rcx
cmp    %rcx,(%r15)
je     1170 <sleepu+0x60>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@errno = global i64 0
@EINTR = global i64 0
define i32 @sleepu(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 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %6
%7 = fmul double %0, 1.000000e+03
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store double %7, double* %8
%9 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%10 = icmp eq i32 %9, -1
%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 %15, label %22
15: ; preds = %1, %15
%16 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %3)
%17 = icmp eq i32 %16, -1
%18 = load i64, i64* @errno
%19 = load i64, i64* @EINTR
%20 = icmp eq i64 %18, %19
%21 = select i1 %17, i1 %20, i1 false
br i1 %21, label %15, label %22
22: ; preds = %15, %1
%23 = phi i32 [ %9, %1 ], [ %16, %15 ]
ret i32 %23
}