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

/* Variables and functions */
scalar_t__ FD_ISSET(int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_SET(int const, int /*<<< orphan*/ *);
int /*<<< orphan*/ FD_ZERO(int /*<<< orphan*/ *);
scalar_t__ select(int const, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                  int /*<<< orphan*/ *, struct timeval *);
int is_af_unix_keeper(const int fd) {
  struct timeval tval = {2, 0};
  fd_set read_fds;
  FD_ZERO(&read_fds);
  FD_SET(fd, &read_fds);
  return select(fd + 1, &read_fds, NULL, NULL, &tval) >= 0 &&
         FD_ISSET(fd, &read_fds);
}


x86 assembly (clang, -O0):
<is_af_unix_keeper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    0xeae(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x14(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x10(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x15(%rbp)
jl     11ad <is_af_unix_keeper+0x6d>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_af_unix_keeper>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
movq   $0x2,0x8(%rsp)
lea    0x4(%rsp),%r15
mov    %r15,%rdi
call   1040 <FD_ZERO@plt>
mov    %r14d,%edi
mov    %r15,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%r14),%edi
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
mov    %r15,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %rax,%rax
js     119e <is_af_unix_keeper+0x5e>
lea    0x4(%rsp),%rsi
mov    %r14d,%edi
call   1030 <FD_ISSET@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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