#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 */
int /*<<< orphan*/ fb_Delay(int);
scalar_t__ fb_hConsoleInputBufferChanged();
void fb_ConsoleSleep(int msecs) {
  if (msecs == -1) {
    while (!fb_hConsoleInputBufferChanged())
      fb_Delay(50);
    return;
  }
  if (msecs >= 100) {
    while (msecs > 50) {
      if (fb_hConsoleInputBufferChanged())
        return;
      fb_Delay(50);
      msecs -= 50;
    }
  }
  if (msecs >= 0)
    fb_Delay(msecs);
}


x86 assembly (clang, -O0):
<fb_ConsoleSleep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    116b <fb_ConsoleSleep+0x4b>
jmp    113a <fb_ConsoleSleep+0x1a>
mov    $0x0,%al
call   1040 <fb_hConsoleInputBufferChanged@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1157 <fb_ConsoleSleep+0x37>
jmp    1166 <fb_ConsoleSleep+0x46>
mov    $0x32,%edi
call   1030 <fb_Delay@plt>
jmp    113a <fb_ConsoleSleep+0x1a>
jmp    11c9 <fb_ConsoleSleep+0xa9>
cmpl   $0x64,-0x4(%rbp)
jl     11b7 <fb_ConsoleSleep+0x97>
jmp    117a <fb_ConsoleSleep+0x5a>
cmpl   $0x32,-0x4(%rbp)
jle    11b2 <fb_ConsoleSleep+0x92>
mov    $0x0,%al
call   1040 <fb_hConsoleInputBufferChanged@plt>
cmp    $0x0,%rax
je     119a <fb_ConsoleSleep+0x7a>
jmp    11c9 <fb_ConsoleSleep+0xa9>
mov    $0x32,%edi
call   1030 <fb_Delay@plt>
mov    -0x4(%rbp),%eax
sub    $0x32,%eax
mov    %eax,-0x4(%rbp)
jmp    117a <fb_ConsoleSleep+0x5a>
jmp    11b7 <fb_ConsoleSleep+0x97>
cmpl   $0x0,-0x4(%rbp)
jl     11c9 <fb_ConsoleSleep+0xa9>
mov    -0x4(%rbp),%edi
call   1030 <fb_Delay@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fb_ConsoleSleep>:
push   %rbx
cmp    $0xffffffff,%edi
je     116a <fb_ConsoleSleep+0x4a>
mov    %edi,%ebx
cmp    $0x64,%edi
jl     1178 <fb_ConsoleSleep+0x58>
nopl   (%rax)
xor    %eax,%eax
call   1040 <fb_hConsoleInputBufferChanged@plt>
test   %rax,%rax
jne    1184 <fb_ConsoleSleep+0x64>
mov    $0x32,%edi
call   1030 <fb_Delay@plt>
lea    -0x32(%rbx),%edi
cmp    $0x64,%ebx
mov    %edi,%ebx
jg     1130 <fb_ConsoleSleep+0x10>
test   %edi,%edi
jns    117e <fb_ConsoleSleep+0x5e>
jmp    1184 <fb_ConsoleSleep+0x64>
cs nopw 0x0(%rax,%rax,1)
mov    $0x32,%edi
call   1030 <fb_Delay@plt>
xor    %eax,%eax
call   1040 <fb_hConsoleInputBufferChanged@plt>
test   %rax,%rax
je     1160 <fb_ConsoleSleep+0x40>
jmp    1184 <fb_ConsoleSleep+0x64>
mov    %ebx,%edi
test   %edi,%edi
js     1184 <fb_ConsoleSleep+0x64>
pop    %rbx
jmp    1030 <fb_Delay@plt>
pop    %rbx
ret

LLVM IR (-O0):
define void @fb_ConsoleSleep(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %13
5: ; preds = %1
br label %6
6: ; preds = %10, %5
%7 = call i64 (...) @fb_hConsoleInputBufferChanged()
%8 = icmp ne i64 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %12
10: ; preds = %6
%11 = call i32 @fb_Delay(i32 50)
br label %6
12: ; preds = %6
br label %35
13: ; preds = %1
%14 = load i32, i32* %2
%15 = icmp sge i32 %14, 100
br i1 %15, label %16, label %29
16: ; preds = %13
br label %17
17: ; preds = %24, %16
%18 = load i32, i32* %2
%19 = icmp sgt i32 %18, 50
br i1 %19, label %20, label %28
20: ; preds = %17
%21 = call i64 (...) @fb_hConsoleInputBufferChanged()
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %20
br label %35
24: ; preds = %20
%25 = call i32 @fb_Delay(i32 50)
%26 = load i32, i32* %2
%27 = sub nsw i32 %26, 50
store i32 %27, i32* %2
br label %17
28: ; preds = %17
br label %29
29: ; preds = %28, %13
%30 = load i32, i32* %2
%31 = icmp sge i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %29
%33 = load i32, i32* %2
%34 = call i32 @fb_Delay(i32 %33)
br label %35
35: ; preds = %12, %23, %32, %29
ret void
}

LLVM IR (-O2):
define void @fb_ConsoleSleep(i32 %0) {
%2 = icmp eq i32 %0, -1
br i1 %2, label %3, label %10
3: ; preds = %1
%4 = tail call i64 (...) @fb_hConsoleInputBufferChanged()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %25
6: ; preds = %3, %6
%7 = tail call i32 @fb_Delay(i32 50)
%8 = tail call i64 (...) @fb_hConsoleInputBufferChanged()
%9 = icmp eq i64 %8, 0
br i1 %9, label %6, label %25
10: ; preds = %1
%11 = icmp sgt i32 %0, 99
br i1 %11, label %12, label %20
12: ; preds = %10, %16
%13 = phi i32 [ %18, %16 ], [ %0, %10 ]
%14 = tail call i64 (...) @fb_hConsoleInputBufferChanged()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %12
%17 = tail call i32 @fb_Delay(i32 50)
%18 = add nsw i32 %13, -50
%19 = icmp sgt i32 %13, 100
br i1 %19, label %12, label %20
20: ; preds = %16, %10
%21 = phi i32 [ %0, %10 ], [ %18, %16 ]
%22 = icmp sgt i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = tail call i32 @fb_Delay(i32 %21)
br label %25
25: ; preds = %12, %6, %3, %23, %20
ret void
}