#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 */

/* Variables and functions */
long _zmillisecond();
int /*<<< orphan*/ poll(int /*<<< orphan*/, int /*<<< orphan*/, int);
unsigned int sleep(unsigned int seconds) {
  int left = seconds * 1000;
  if (left < 1) {
    return 0;
  }
  long end = _zmillisecond() + left + 1;
  poll(0, 0, (int)left);
  left = end - _zmillisecond();
  if (left < 10) {
    return 0;
  }
  return (left / 1000);
}


x86 assembly (clang, -O0):
<sleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
imul   $0x3e8,-0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    114b <sleep+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    11ad <sleep+0x8d>
mov    $0x0,%al
call   1030 <_zmillisecond@plt>
movslq -0xc(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%edx
xor    %esi,%esi
mov    %esi,%edi
call   1040 <poll@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <_zmillisecond@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    119f <sleep+0x7f>
movl   $0x0,-0x4(%rbp)
jmp    11ad <sleep+0x8d>
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sleep>:
push   %rbp
push   %r14
push   %rbx
imul   $0x3e8,%edi,%ebp
xor    %r14d,%r14d
test   %ebp,%ebp
jle    1171 <sleep+0x51>
xor    %eax,%eax
call   1030 <_zmillisecond@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <poll@plt>
xor    %eax,%eax
call   1030 <_zmillisecond@plt>
or     $0x1,%ebp
add    %ebp,%ebx
sub    %eax,%ebx
cmp    $0xa,%ebx
jl     1171 <sleep+0x51>
movslq %ebx,%rax
imul   $0x10624dd3,%rax,%r14
mov    %r14,%rax
shr    $0x3f,%rax
sar    $0x26,%r14
add    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @sleep(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i64
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = mul i32 %6, 1000
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 0, i32* %2
br label %29
11: ; preds = %1
%12 = call i64 (...) @_zmillisecond()
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = add nsw i64 %12, %14
%16 = add nsw i64 %15, 1
store i64 %16, i64* %5
%17 = load i32, i32* %4
%18 = call i32 @poll(i32 0, i32 0, i32 %17)
%19 = load i64, i64* %5
%20 = call i64 (...) @_zmillisecond()
%21 = sub nsw i64 %19, %20
%22 = trunc i64 %21 to i32
store i32 %22, i32* %4
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 10
br i1 %24, label %25, label %26
25: ; preds = %11
store i32 0, i32* %2
br label %29
26: ; preds = %11
%27 = load i32, i32* %4
%28 = sdiv i32 %27, 1000
store i32 %28, i32* %2
br label %29
29: ; preds = %26, %25, %10
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @sleep(i32 %0) {
%2 = mul i32 %0, 1000
%3 = icmp slt i32 %2, 1
br i1 %3, label %16, label %4
4: ; preds = %1
%5 = tail call i64 (...) @_zmillisecond()
%6 = tail call i32 @poll(i32 0, i32 0, i32 %2)
%7 = tail call i64 (...) @_zmillisecond()
%8 = or i32 %2, 1
%9 = zext i32 %8 to i64
%10 = add i64 %5, %9
%11 = sub i64 %10, %7
%12 = trunc i64 %11 to i32
%13 = icmp slt i32 %12, 10
%14 = sdiv i32 %12, 1000
%15 = select i1 %13, i32 0, i32 %14
br label %16
16: ; preds = %1, %4
%17 = phi i32 [ %15, %4 ], [ 0, %1 ]
ret i32 %17
}