#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 /*<<< orphan*/ select(int, int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          int /*<<< orphan*/ *, struct timeval *);
int canRead(int sockFd) {
  struct timeval timeout;
  timeout.tv_sec = 0;
  timeout.tv_usec = 0;
  fd_set set;
  FD_ZERO(&set);
  FD_SET(sockFd, &set);
  int maxFd = sockFd + 1;
  select(maxFd, &set, NULL, NULL, &timeout);
  if (FD_ISSET(sockFd, &set)) {
    return 1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<canRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
lea    -0x1c(%rbp),%rdi
call   1040 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%r8
mov    %rcx,%rdx
call   1050 <select@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1030 <FD_ISSET@plt>
cmp    $0x0,%rax
je     11b2 <canRead+0x72>
movl   $0x1,-0x4(%rbp)
jmp    11b9 <canRead+0x79>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<canRead>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
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
lea    0x10(%rsp),%r8
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1050 <select@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1030 <FD_ISSET@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define i32 @canRead(i32 %0) {
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timeval* %2 to i8*
%7 = call i32 @FD_ZERO(i32* %3)
%8 = call i32 @FD_SET(i32 %0, i32* %3)
%9 = add nsw i32 %0, 1
%10 = call i32 @select(i32 %9, i32* %3, i32* null, i32* null, %struct.timeval* %2)
%11 = call i64 @FD_ISSET(i32 %0, i32* %3)
%12 = icmp ne i64 %11, 0
%13 = zext i1 %12 to i32
ret i32 %13
}