#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);
void zcoroutine_sleep_millisecond(int milliseconds) {
  int left = milliseconds;
  if (left < 1) {
    return;
  }
  long end = _zmillisecond() + left + 1;
  while (left > 0) {
    poll(0, 0, left);
    left = end - _zmillisecond();
  }
}


x86 assembly (clang, -O0):
<zcoroutine_sleep_millisecond>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    1140 <zcoroutine_sleep_millisecond+0x20>
jmp    118d <zcoroutine_sleep_millisecond+0x6d>
mov    $0x0,%al
call   1030 <_zmillisecond@plt>
movslq -0x8(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    118d <zcoroutine_sleep_millisecond+0x6d>
mov    -0x8(%rbp),%edx
xor    %esi,%esi
mov    %esi,%edi
call   1040 <poll@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <_zmillisecond@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
jmp    1156 <zcoroutine_sleep_millisecond+0x36>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zcoroutine_sleep_millisecond>:
push   %r14
push   %rbx
push   %rax
test   %edi,%edi
jle    115b <zcoroutine_sleep_millisecond+0x3b>
mov    %edi,%ebx
xor    %eax,%eax
call   1030 <_zmillisecond@plt>
mov    %ebx,%ecx
lea    (%rcx,%rax,1),%r14
add    $0x1,%r14
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <poll@plt>
xor    %eax,%eax
call   1030 <_zmillisecond@plt>
mov    %r14d,%ebx
sub    %eax,%ebx
test   %ebx,%ebx
jg     1140 <zcoroutine_sleep_millisecond+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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