#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 getchi();
int /*<<< orphan*/ mswait(int);
kbwait(unsigned int seconds) {
  static unsigned t;
  static int c;
  t = seconds * 10;
  while (!(c = getchi()) && (t--))
    mswait(100);
  return ((c & 0xff) == 27);
}


x86 assembly (clang, -O0):
<kbwait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
imul   $0xa,-0x4(%rbp),%eax
mov    %eax,0x2eff(%rip)
mov    $0x0,%al
call   1030 <getchi@plt>
mov    %eax,%ecx
mov    %ecx,0x2ef4(%rip)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x5(%rbp)
jne    116c <kbwait+0x4c>
mov    0x2edc(%rip),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,0x2ed1(%rip)
cmp    $0x0,%eax
setne  %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    117c <kbwait+0x5c>
jmp    118b <kbwait+0x6b>
mov    $0x64,%edi
call   1040 <mswait@plt>
jmp    1135 <kbwait+0x15>
mov    0x2ea7(%rip),%eax
and    $0xff,%eax
cmp    $0x1b,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kbwait>:
push   %rbx
add    %edi,%edi
lea    (%rdi,%rdi,4),%eax
mov    %eax,0x2f08(%rip)
xor    %eax,%eax
call   1030 <getchi@plt>
mov    %eax,%ebx
test   %eax,%eax
jne    1160 <kbwait+0x40>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
subl   $0x1,0x2eed(%rip)
jb     1160 <kbwait+0x40>
mov    $0x64,%edi
call   1040 <mswait@plt>
xor    %eax,%eax
call   1030 <getchi@plt>
test   %eax,%eax
je     1140 <kbwait+0x20>
mov    %eax,%ebx
xor    %eax,%eax
cmp    $0x1b,%bl
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
@kbwait.t = internal global i32 0
@kbwait.c = internal global i32 0
define i32 @kbwait(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = mul i32 %3, 10
store i32 %4, i32* @kbwait.t
br label %5
5: ; preds = %14, %1
%6 = call i32 (...) @getchi()
store i32 %6, i32* @kbwait.c
%7 = icmp ne i32 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = load i32, i32* @kbwait.t
%10 = add i32 %9, -1
store i32 %10, i32* @kbwait.t
%11 = icmp ne i32 %9, 0
br label %12
12: ; preds = %8, %5
%13 = phi i1 [ false, %5 ], [ %11, %8 ]
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = call i32 @mswait(i32 100)
br label %5
16: ; preds = %12
%17 = load i32, i32* @kbwait.c
%18 = and i32 %17, 255
%19 = icmp eq i32 %18, 27
%20 = zext i1 %19 to i32
ret i32 %20
}

LLVM IR (-O2):
@kbwait.t = internal unnamed_addr global i32 0
define i32 @kbwait(i32 %0) {
%2 = mul i32 %0, 10
store i32 %2, i32* @kbwait.t
%3 = tail call i32 (...) @getchi()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1, %9
%6 = load i32, i32* @kbwait.t
%7 = add i32 %6, -1
store i32 %7, i32* @kbwait.t
%8 = icmp eq i32 %6, 0
br i1 %8, label %13, label %9
9: ; preds = %5
%10 = tail call i32 @mswait(i32 100)
%11 = tail call i32 (...) @getchi()
%12 = icmp eq i32 %11, 0
br i1 %12, label %5, label %13
13: ; preds = %5, %9, %1
%14 = phi i32 [ %3, %1 ], [ %11, %9 ], [ 0, %5 ]
%15 = and i32 %14, 255
%16 = icmp eq i32 %15, 27
%17 = zext i1 %16 to i32
ret i32 %17
}