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

/* Variables and functions */
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int select(scalar_t__, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int raw_kbhit() {
  struct timeval wait;
  fd_set readfd, writefd, exceptfd;
  int ret;
  wait.tv_sec = 0;
  wait.tv_usec = 100;
  FD_ZERO(&readfd);
  FD_SET(0, &readfd);
  FD_ZERO(&writefd);
  FD_ZERO(&exceptfd);
  ret = select(0 + 1, &readfd, &writefd, &exceptfd, &wait);
  return (ret);
}


x86 assembly (clang, -O0):
<raw_kbhit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x64,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1050 <FD_SET@plt>
lea    -0x18(%rbp),%rdi
call   1030 <FD_ZERO@plt>
lea    -0x1c(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
lea    -0x1c(%rbp),%rcx
lea    -0x10(%rbp),%r8
call   1040 <select@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<raw_kbhit>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x18(%rsp)
movl   $0x64,0x10(%rsp)
lea    0xc(%rsp),%r15
mov    %r15,%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <FD_SET@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <FD_ZERO@plt>
lea    0x10(%rsp),%r8
mov    $0x1,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1040 <select@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @raw_kbhit() {
%1 = alloca %struct.timeval
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = bitcast %struct.timeval* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i32* %4 to i8*
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
store i32 100, i32* %10
%11 = call i32 @FD_ZERO(i32* %2)
%12 = call i32 @FD_SET(i32 0, i32* %2)
%13 = call i32 @FD_ZERO(i32* %3)
%14 = call i32 @FD_ZERO(i32* %4)
%15 = call i32 @select(i64 1, i32* %2, i32* %3, i32* %4, %struct.timeval* %1)
ret i32 %15
}