#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 */
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ fileno(int /*<<< orphan*/);
int select(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stdin;
int waitkeyin(void) {
  fd_set rset;
  int nSelect;
  FD_ZERO(&rset);
  FD_SET(fileno(stdin), &rset);
  nSelect = select(fileno(stdin) + 1, &rset, NULL, NULL, NULL);
  if (nSelect == -1)
    return 0;
  return nSelect > 0;
}


x86 assembly (clang, -O0):
<waitkeyin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %rax,%rdi
lea    -0x8(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %rax,%rdi
add    $0x1,%rdi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
mov    %r8,%rcx
call   1050 <select@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11ad <waitkeyin+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11bc <waitkeyin+0x7c>
cmpl   $0x0,-0xc(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitkeyin>:
push   %r14
push   %rbx
push   %rax
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e90(%rip),%rbx
mov    (%rbx),%edi
call   1030 <fileno@plt>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
mov    (%rbx),%edi
call   1030 <fileno@plt>
lea    0x1(%rax),%rdi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1050 <select@plt>
xor    %ecx,%ecx
test   %eax,%eax
setg   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @waitkeyin() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @FD_ZERO(i32* %2)
%5 = load i32, i32* @stdin
%6 = call i64 @fileno(i32 %5)
%7 = call i32 @FD_SET(i64 %6, i32* %2)
%8 = load i32, i32* @stdin
%9 = call i64 @fileno(i32 %8)
%10 = add nsw i64 %9, 1
%11 = call i32 @select(i64 %10, i32* %2, i32* null, i32* null, i32* null)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %15
14: ; preds = %0
store i32 0, i32* %1
br label %19
15: ; preds = %0
%16 = load i32, i32* %3
%17 = icmp sgt i32 %16, 0
%18 = zext i1 %17 to i32
store i32 %18, i32* %1
br label %19
19: ; preds = %15, %14
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @waitkeyin() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @FD_ZERO(i32* %1)
%4 = load i32, i32* @stdin
%5 = call i64 @fileno(i32 %4)
%6 = call i32 @FD_SET(i64 %5, i32* %1)
%7 = load i32, i32* @stdin
%8 = call i64 @fileno(i32 %7)
%9 = add nsw i64 %8, 1
%10 = call i32 @select(i64 %9, i32* %1, i32* null, i32* null, i32* null)
%11 = icmp sgt i32 %10, 0
%12 = zext i1 %11 to i32
ret i32 %12
}