#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 {
  unsigned int tv_sec;
  unsigned int tv_nsec;
};

/* Variables and functions */
scalar_t__ EINTR;
scalar_t__ errno;
int nanosleep(struct timespec *, struct timespec *);
void wusleep(unsigned int usec) {
  struct timespec tm;
  if (usec > 600000000)
    return;
  tm.tv_sec = usec / 1000000;
  tm.tv_nsec = (usec % 1000000) * 1000;
  while (nanosleep(&tm, &tm) == -1 && errno == EINTR)
    ;
}


x86 assembly (clang, -O0):
<wusleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0x23c34600,-0x4(%rbp)
jbe    112d <wusleep+0x1d>
jmp    119c <wusleep+0x8c>
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%eax
mov    $0xf4240,%ecx
xor    %edx,%edx
div    %ecx
imul   $0x3e8,%edx,%eax
mov    %eax,-0xc(%rbp)
lea    -0x10(%rbp),%rsi
mov    %rsi,%rdi
call   1030 <nanosleep@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
mov    %al,-0x11(%rbp)
jne    1187 <wusleep+0x77>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1197 <wusleep+0x87>
jmp    119c <wusleep+0x8c>
jmp    1151 <wusleep+0x41>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wusleep>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
cmp    $0x23c34600,%edi
ja     1178 <wusleep+0x68>
mov    %edi,%eax
imul   $0x431bde83,%rax,%rax
shr    $0x32,%rax
mov    %eax,0x8(%rsp)
imul   $0xf4240,%eax,%eax
sub    %eax,%edi
imul   $0x3e8,%edi,%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rbx
mov    0x2e90(%rip),%r14
mov    0x2e81(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %rbx,%rsi
call   1030 <nanosleep@plt>
cmp    $0xffffffff,%eax
jne    1178 <wusleep+0x68>
mov    (%r15),%rax
cmp    %rax,(%r14)
je     1160 <wusleep+0x50>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @wusleep(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.timespec
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = icmp ugt i32 %4, 600000000
br i1 %5, label %6, label %7
6: ; preds = %1
br label %25
7: ; preds = %1
%8 = load i32, i32* %2
%9 = udiv i32 %8, 1000000
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* %2
%12 = urem i32 %11, 1000000
%13 = mul i32 %12, 1000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
store i32 %13, i32* %14
br label %15
15: ; preds = %24, %7
%16 = call i32 @nanosleep(%struct.timespec* %3, %struct.timespec* %3)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @EINTR
%21 = icmp eq i64 %19, %20
br label %22
22: ; preds = %18, %15
%23 = phi i1 [ false, %15 ], [ %21, %18 ]
br i1 %23, label %24, label %25
24: ; preds = %22
br label %15
25: ; preds = %6, %22
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@errno = global i64 0
@EINTR = global i64 0
define void @wusleep(i32 %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = icmp ugt i32 %0, 600000000
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = udiv i32 %0, 1000000
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 %6, i32* %7
%8 = urem i32 %0, 1000000
%9 = mul nuw nsw i32 %8, 1000
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i32 %9, i32* %10
br label %11
11: ; preds = %11, %5
%12 = call i32 @nanosleep(%struct.timespec* %2, %struct.timespec* %2)
%13 = icmp eq i32 %12, -1
%14 = load i64, i64* @errno
%15 = load i64, i64* @EINTR
%16 = icmp eq i64 %14, %15
%17 = select i1 %13, i1 %16, i1 false
br i1 %17, label %11, label %18
18: ; preds = %11, %1
ret void
}