#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__ FD_ISSET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
int select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
           int /*<<< orphan*/ *, struct timeval *);
int isready(int fd) {
  int rc;
  fd_set fds;
  struct timeval tv;
  FD_ZERO(&fds);
  FD_SET(fd, &fds);
  tv.tv_sec = tv.tv_usec = 0;
  rc = select(fd + 1, &fds, NULL, NULL, &tv);
  if (rc < 0)
    return -1;
  return FD_ISSET(fd, &fds) ? 1 : 0;
}


x86 assembly (clang, -O0):
<isready>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11a3 <isready+0x63>
movl   $0xffffffff,-0x4(%rbp)
jmp    11c3 <isready+0x83>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1030 <FD_ISSET@plt>
mov    %rax,%rdx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%rdx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isready>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1040 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%rbx),%edi
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%r8
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %eax,%eax
js     1199 <isready+0x59>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1030 <FD_ISSET@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
setne  %al
jmp    119e <isready+0x5e>
mov    $0xffffffff,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

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