#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 */
scalar_t__ dbgu_mayget(unsigned char *);
int /*<<< orphan*/ dotn(int);
int get_ticks();
void safe_delay_msecs(int ms) {
  register int endtime;
  unsigned char b;
  endtime = get_ticks() + (ms << 5);
  do {
    int now;
    if (dbgu_mayget(&b)) {
      now = get_ticks();
      dotn(now);
      dotn(endtime);
      return;
    }
  } while ((endtime - get_ticks()) > 0);
}


x86 assembly (clang, -O0):
<safe_delay_msecs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1050 <get_ticks@plt>
mov    -0x4(%rbp),%ecx
shl    $0x5,%ecx
add    %ecx,%eax
mov    %eax,-0x8(%rbp)
lea    -0x9(%rbp),%rdi
call   1040 <dbgu_mayget@plt>
cmp    $0x0,%rax
je     117f <safe_delay_msecs+0x4f>
mov    $0x0,%al
call   1050 <get_ticks@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <dotn@plt>
mov    -0x8(%rbp),%edi
call   1030 <dotn@plt>
jmp    11a1 <safe_delay_msecs+0x71>
jmp    1184 <safe_delay_msecs+0x54>
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <get_ticks@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
cmp    $0x0,%eax
jg     114d <safe_delay_msecs+0x1d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safe_delay_msecs>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
xor    %eax,%eax
call   1050 <get_ticks@plt>
shl    $0x5,%ebp
add    %eax,%ebp
lea    0xf(%rsp),%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <dbgu_mayget@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <get_ticks@plt>
test   %rbx,%rbx
jne    116d <safe_delay_msecs+0x3d>
cmp    %eax,%ebp
jg     1150 <safe_delay_msecs+0x20>
jmp    117b <safe_delay_msecs+0x4b>
mov    %eax,%edi
call   1030 <dotn@plt>
mov    %ebp,%edi
call   1030 <dotn@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @safe_delay_msecs(i32 %0) {
%2 = alloca i8
%3 = tail call i32 (...) @get_ticks()
%4 = shl i32 %0, 5
%5 = add nsw i32 %3, %4
br label %6
6: ; preds = %13, %1
%7 = call i64 @dbgu_mayget(i8* %2)
%8 = icmp eq i64 %7, 0
%9 = call i32 (...) @get_ticks()
br i1 %8, label %13, label %10
10: ; preds = %6
%11 = call i32 @dotn(i32 %9)
%12 = call i32 @dotn(i32 %5)
br label %15
13: ; preds = %6
%14 = icmp sgt i32 %5, %9
br i1 %14, label %6, label %15
15: ; preds = %13, %10
ret void
}