#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 FD_ISSET(int /*<<< orphan*/, 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 input_available() {
  struct timeval tv;
  tv.tv_sec = 0;
  tv.tv_usec = 500;
  fd_set fds;
  FD_ZERO(&fds);
  FD_SET(STDIN_FILENO, &fds);
  select(STDIN_FILENO + 1, &fds, NULL, NULL, &tv);
  return FD_ISSET(0, &fds);
}


x86 assembly (clang, -O0):
<input_available>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movq   $0x0,-0x8(%rbp)
movl   $0x1f4,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%rdi
lea    -0x14(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    0x2e66(%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>
xor    %edi,%edi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_available>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movl   $0x1f4,0x8(%rsp)
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e74(%rip),%r14
mov    (%r14),%rdi
mov    %rbx,%rsi
call   1060 <FD_SET@plt>
mov    (%r14),%rdi
add    $0x1,%rdi
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1030 <FD_ISSET@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@STDIN_FILENO = global i64 0
define i32 @input_available() {
%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 i32 500, i32* %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 = call i32 @FD_ISSET(i32 0, i32* %2)
ret i32 %11
}

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