#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 /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ fd_set;

/* Variables and functions */
int FD_ISSET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int /*<<< orphan*/ STDIN_FILENO;
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int input_pending(void) {
  struct timeval t = {0, 0};
  fd_set f;
  FD_ZERO(&f);
  FD_SET(STDIN_FILENO, &f);
  if (select(1, &f, NULL, NULL, &t) == -1)
    return 0;
  return FD_ISSET(STDIN_FILENO, &f);
}


x86 assembly (clang, -O0):
<input_pending>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x14(%rbp),%rdi
call   1050 <FD_ZERO@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
call   1070 <FD_SET@plt>
mov    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1060 <select@plt>
cmp    $0xffffffff,%eax
jne    11b1 <input_pending+0x61>
movl   $0x0,-0x4(%rbp)
jmp    11c6 <input_pending+0x76>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<input_pending>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    0x2e7a(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    $0x1,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
cmp    $0xffffffff,%eax
je     119d <input_pending+0x5d>
mov    (%r15),%edi
lea    0x4(%rsp),%rsi
call   1030 <FD_ISSET@plt>
mov    %eax,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
@STDIN_FILENO = global i32 0
define i32 @input_pending() {
%1 = alloca i32
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = bitcast %struct.timeval* %2 to i8*
%5 = call i32 @FD_ZERO(i32* %3)
%6 = load i32, i32* @STDIN_FILENO
%7 = call i32 @FD_SET(i32 %6, i32* %3)
%8 = call i32 @select(i32 1, i32* %3, i32* null, i32* null, %struct.timeval* %2)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 0, i32* %1
br label %14
11: ; preds = %0
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @FD_ISSET(i32 %12, i32* %3)
store i32 %13, i32* %1
br label %14
14: ; preds = %11, %10
%15 = load i32, i32* %1
ret i32 %15
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
@STDIN_FILENO = global i32 0
define i32 @input_pending() {
%1 = alloca i64
%2 = bitcast i64* %1 to %struct.timeval*
%3 = alloca i32
%4 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%5 = bitcast i32* %3 to i8*
%6 = call i32 @FD_ZERO(i32* %3)
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @FD_SET(i32 %7, i32* %3)
%9 = call i32 @select(i32 1, i32* %3, i32* null, i32* null, %struct.timeval* %2)
%10 = icmp eq i32 %9, -1
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @FD_ISSET(i32 %12, i32* %3)
br label %14
14: ; preds = %0, %11
%15 = phi i32 [ %13, %11 ], [ 0, %0 ]
ret i32 %15
}