#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 /*<<< orphan*/ fileno(int /*<<< orphan*/);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int /*<<< orphan*/ stdin;
int stdin_is_ready() {
  fd_set fdset;
  struct timeval timeout;
  FD_ZERO(&fdset);
  FD_SET(fileno(stdin), &fdset);
  timeout.tv_sec = 0;
  timeout.tv_usec = 1;
  return select(1, &fdset, NULL, NULL, &timeout) == 1 ? 1 : 0;
}


x86 assembly (clang, -O0):
<stdin_is_ready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x4(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e90(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
lea    -0x4(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x1,%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x1,%edx
cmove  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdin_is_ready>:
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
call   1030 <fileno@plt>
mov    %eax,%edi
mov    %rbx,%rsi
call   1060 <FD_SET@plt>
movq   $0x0,0x18(%rsp)
movl   $0x1,0x10(%rsp)
lea    0x10(%rsp),%r8
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
xor    %ecx,%ecx
cmp    $0x1,%eax
sete   %cl
mov    %ecx,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
@stdin = global i32 0
define i32 @stdin_is_ready() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = call i32 @FD_ZERO(i32* %1)
%4 = load i32, i32* @stdin
%5 = call i32 @fileno(i32 %4)
%6 = call i32 @FD_SET(i32 %5, i32* %1)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
store i32 1, i32* %8
%9 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%10 = icmp eq i32 %9, 1
%11 = zext i1 %10 to i64
%12 = select i1 %10, i32 1, i32 0
ret i32 %12
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
@stdin = global i32 0
define i32 @stdin_is_ready() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @FD_ZERO(i32* %1)
%6 = load i32, i32* @stdin
%7 = call i32 @fileno(i32 %6)
%8 = call i32 @FD_SET(i32 %7, i32* %1)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
store i32 1, i32* %10
%11 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
ret i32 %13
}