#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 /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int checkStdin(void) {
  fd_set rfds;
  struct timeval tv;
  int retval;
  FD_ZERO(&rfds);
  FD_SET(0, &rfds);
  tv.tv_sec = 0;
  tv.tv_usec = 0;
  retval = select(1, &rfds, NULL, NULL, &tv);
  if (retval == -1) {
    perror("checkStdin() experienced error.");
    exit(EXIT_FAILURE);
  }
  return retval;
}


x86 assembly (clang, -O0):
<checkStdin>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x4(%rbp),%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
lea    -0x4(%rbp),%rsi
call   1070 <FD_SET@plt>
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x1,%edi
lea    -0x4(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1040 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11bc <checkStdin+0x6c>
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkStdin>:
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <FD_ZERO@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1070 <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   1040 <select@plt>
cmp    $0xffffffff,%eax
je     1195 <checkStdin+0x45>
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe64(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
@.str = [32 x i8] c"checkStdin() experienced error.\00"
@EXIT_FAILURE = global i32 0
define i32 @checkStdin() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = call i32 @FD_ZERO(i32* %1)
%5 = call i32 @FD_SET(i32 0, i32* %1)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
store i64 0, i64* %7
%8 = call i32 @select(i32 1, i32* %1, i32* null, i32* null, %struct.timeval* %2)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %0
%16 = load i32, i32* %3
ret i32 %16
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
@.str = [32 x i8] c"checkStdin() experienced error.\00"
@EXIT_FAILURE = global i32 0
define i32 @checkStdin() {
%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 eq i32 %8, -1
br i1 %9, label %10, label %14
10: ; preds = %0
%11 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %0
ret i32 %8
}