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

/* Variables and functions */
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 can_recv(int sck, int millis) {
  struct timeval time;
  fd_set rfds;
  int select_rv;
  FD_ZERO(&rfds);
  FD_SET(sck, &rfds);
  time.tv_sec = millis / 1000;
  time.tv_usec = (millis * 1000) % 1000000;
  select_rv = select(sck + 1, &rfds, 0, 0, &time);
  if (select_rv > 0) {
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<can_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x1c(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x8(%rbp),%edi
lea    -0x1c(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x18(%rbp)
imul   $0x3e8,-0xc(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
mov    -0x8(%rbp),%edi
add    $0x1,%edi
lea    -0x1c(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
mov    %ecx,%edx
call   1040 <select@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jle    11a3 <can_recv+0x73>
movl   $0x1,-0x4(%rbp)
jmp    11aa <can_recv+0x7a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<can_recv>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebp
mov    %edi,%ebx
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
movslq %ebp,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rsp)
imul   $0x3e8,%eax,%eax
cltq
imul   $0x431bde83,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rcx
add    %edx,%ecx
imul   $0xf4240,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
add    $0x1,%ebx
mov    %rsp,%r8
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <select@plt>
xor    %ecx,%ecx
test   %eax,%eax
setg   %cl
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i32 @can_recv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.timeval
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
%9 = call i32 @FD_ZERO(i32* %7)
%10 = load i32, i32* %4
%11 = call i32 @FD_SET(i32 %10, i32* %7)
%12 = load i32, i32* %5
%13 = sdiv i32 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
store i32 %13, i32* %14
%15 = load i32, i32* %5
%16 = mul nsw i32 %15, 1000
%17 = srem i32 %16, 1000000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* %4
%20 = add nsw i32 %19, 1
%21 = call i32 @select(i32 %20, i32* %7, i32 0, i32 0, %struct.timeval* %6)
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp sgt i32 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %2
store i32 1, i32* %3
br label %26
25: ; preds = %2
store i32 0, i32* %3
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %3
ret i32 %27
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @can_recv(i32 %0, i32 %1) {
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = bitcast %struct.timeval* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 @FD_ZERO(i32* %4)
%8 = call i32 @FD_SET(i32 %0, i32* %4)
%9 = sdiv i32 %1, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
store i32 %9, i32* %10
%11 = mul nsw i32 %1, 1000
%12 = srem i32 %11, 1000000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = add nsw i32 %0, 1
%15 = call i32 @select(i32 %14, i32* %4, i32 0, i32 0, %struct.timeval* %3)
%16 = icmp sgt i32 %15, 0
%17 = zext i1 %16 to i32
ret i32 %17
}