#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 */
struct timeval {
  scalar_t__ tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int FD_ISSET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(scalar_t__, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ STDIN_FILENO;
int /*<<< orphan*/ select(scalar_t__, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          struct timeval *);
int kbhit(void) {
  struct timeval tv;
  fd_set fds;
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  FD_ZERO(&fds);
  FD_SET(STDIN_FILENO, &fds);
  select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
  return FD_ISSET(STDIN_FILENO, &fds);
}


x86 assembly (clang, -O0):
<kbhit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%rdi
add    $0x1,%rdi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<kbhit>:
push   %r14
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e7d(%rip),%r14
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1060 <FD_SET@plt>
mov    (%r14),%rdi
add    $0x1,%rdi
lea    0x10(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@STDIN_FILENO = global i64 0
define i32 @kbhit() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
store i64 0, i64* %3
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
store i64 0, i64* %4
%5 = call i32 @FD_ZERO(i32* %2)
%6 = load i64, i64* @STDIN_FILENO
%7 = call i32 @FD_SET(i64 %6, i32* %2)
%8 = load i64, i64* @STDIN_FILENO
%9 = add nsw i64 %8, 1
%10 = call i32 @select(i64 %9, i32* %2, i32* null, i32* null, %struct.timeval* %1)
%11 = load i64, i64* @STDIN_FILENO
%12 = call i32 @FD_ISSET(i64 %11, i32* %2)
ret i32 %12
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@STDIN_FILENO = global i64 0
define i32 @kbhit() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.timeval* %1 to i8*
%6 = call i32 @FD_ZERO(i32* %2)
%7 = load i64, i64* @STDIN_FILENO
%8 = call i32 @FD_SET(i64 %7, i32* %2)
%9 = load i64, i64* @STDIN_FILENO
%10 = add nsw i64 %9, 1
%11 = call i32 @select(i64 %10, i32* %2, i32* null, i32* null, %struct.timeval* %1)
%12 = load i64, i64* @STDIN_FILENO
%13 = call i32 @FD_ISSET(i64 %12, i32* %2)
ret i32 %13
}