#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 */
scalar_t__ EOF;
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ getchar();
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int check_select_stdin(void) {
  fd_set rdfs;
  struct timeval timeout;
  int ret;
  FD_ZERO(&rdfs);
  FD_SET(0, &rdfs);
  timeout.tv_sec = 0;
  timeout.tv_usec = 0;
  ret = select(1, &rdfs, NULL, NULL, &timeout);
  if (ret < 0)
    return 0;
  if (ret > 0 && getchar() == EOF)
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<check_select_stdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x8(%rbp),%rdi
call   1040 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x8(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x1,%edi
lea    -0x8(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    119e <check_select_stdin+0x5e>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <check_select_stdin+0x92>
cmpl   $0x0,-0x1c(%rbp)
jle    11cb <check_select_stdin+0x8b>
mov    $0x0,%al
call   1030 <getchar@plt>
mov    0x2e32(%rip),%rcx
cmp    (%rcx),%rax
jne    11cb <check_select_stdin+0x8b>
movl   $0x0,-0x4(%rbp)
jmp    11d2 <check_select_stdin+0x92>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_select_stdin>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <FD_ZERO@plt>
xor    %r14d,%r14d
xor    %edi,%edi
mov    %rbx,%rsi
call   1060 <FD_SET@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r8
mov    $0x1,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %eax,%eax
js     11a1 <check_select_stdin+0x61>
je     119b <check_select_stdin+0x5b>
xor    %r14d,%r14d
xor    %eax,%eax
call   1030 <getchar@plt>
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%rax
je     11a1 <check_select_stdin+0x61>
mov    $0x1,%r14d
mov    %r14d,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@EOF = global i64 0
define i32 @check_select_stdin() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = call i32 @FD_ZERO(i32* %2)
%6 = call i32 @FD_SET(i32 0, i32* %2)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
store i64 0, i64* %7
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
store i64 0, i64* %8
%9 = call i32 @select(i32 1, i32* %2, i32* null, i32* null, %struct.timeval* %3)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 0, i32* %1
br label %22
13: ; preds = %0
%14 = load i32, i32* %4
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i64 (...) @getchar()
%18 = load i64, i64* @EOF
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %16
store i32 0, i32* %1
br label %22
21: ; preds = %16, %13
store i32 1, i32* %1
br label %22
22: ; preds = %21, %20, %12
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@EOF = global i64 0
define i32 @check_select_stdin() {
%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 = call i32 @FD_SET(i32 0, i32* %1)
%7 = bitcast %struct.timeval* %2 to i8*
%8 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
%9 = icmp slt i32 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %0
%11 = icmp eq i32 %8, 0
br i1 %11, label %16, label %12
12: ; preds = %10
%13 = call i64 (...) @getchar()
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %17, label %16
16: ; preds = %12, %10
br label %17
17: ; preds = %12, %0, %16
%18 = phi i32 [ 1, %16 ], [ 0, %0 ], [ 0, %12 ]
ret i32 %18
}