#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 ERR;
int /*<<< orphan*/ FALSE;
int /*<<< orphan*/ TRUE;
int getch();
int /*<<< orphan*/ nodelay(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdscr;
int /*<<< orphan*/ ungetch(int);
int con_kbhit(void) {
  int i, g;
  nodelay(stdscr, TRUE);
  i = ((g = getch()) == ERR ? 0 : 1);
  if (i)
    ungetch(g);
  nodelay(stdscr, FALSE);
  return i;
}


x86 assembly (clang, -O0):
<con_kbhit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
call   1030 <nodelay@plt>
mov    $0x0,%al
call   1050 <getch@plt>
mov    %eax,%edx
mov    %edx,-0x8(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     1185 <con_kbhit+0x55>
mov    -0x8(%rbp),%edi
call   1040 <ungetch@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    0x2e33(%rip),%rax
mov    (%rax),%esi
call   1030 <nodelay@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<con_kbhit>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2ea2(%rip),%r14
mov    (%r14),%edi
mov    0x2e90(%rip),%rax
mov    (%rax),%esi
call   1030 <nodelay@plt>
xor    %eax,%eax
call   1050 <getch@plt>
mov    %eax,%ebx
mov    0x2e89(%rip),%rax
mov    (%rax),%r15d
cmp    %r15d,%ebx
je     116e <con_kbhit+0x3e>
mov    %ebx,%edi
call   1040 <ungetch@plt>
xor    %ebp,%ebp
cmp    %r15d,%ebx
setne  %bpl
mov    (%r14),%edi
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
call   1030 <nodelay@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdscr = global i32 0
@TRUE = global i32 0
@ERR = global i32 0
@FALSE = global i32 0
define i32 @con_kbhit() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @stdscr
%4 = load i32, i32* @TRUE
%5 = call i32 @nodelay(i32 %3, i32 %4)
%6 = call i32 (...) @getch()
store i32 %6, i32* %2
%7 = load i32, i32* @ERR
%8 = icmp eq i32 %6, %7
%9 = zext i1 %8 to i64
%10 = select i1 %8, i32 0, i32 1
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = load i32, i32* %2
%15 = call i32 @ungetch(i32 %14)
br label %16
16: ; preds = %13, %0
%17 = load i32, i32* @stdscr
%18 = load i32, i32* @FALSE
%19 = call i32 @nodelay(i32 %17, i32 %18)
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@stdscr = global i32 0
@TRUE = global i32 0
@ERR = global i32 0
@FALSE = global i32 0
define i32 @con_kbhit() {
%1 = load i32, i32* @stdscr
%2 = load i32, i32* @TRUE
%3 = tail call i32 @nodelay(i32 %1, i32 %2)
%4 = tail call i32 (...) @getch()
%5 = load i32, i32* @ERR
%6 = icmp ne i32 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @ungetch(i32 %4)
br label %9
9: ; preds = %7, %0
%10 = zext i1 %6 to i32
%11 = load i32, i32* @stdscr
%12 = load i32, i32* @FALSE
%13 = tail call i32 @nodelay(i32 %11, i32 %12)
ret i32 %10
}