#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_send(int sck, int millis) {
  struct timeval time;
  fd_set wfds;
  int select_rv;
  FD_ZERO(&wfds);
  FD_SET(sck, &wfds);
  time.tv_sec = millis / 1000;
  time.tv_usec = (millis * 1000) % 1000000;
  select_rv = select(sck + 1, 0, &wfds, 0, &time);
  return (select_rv > 0) ? 1 : 0;
}


x86 assembly (clang, -O0):
<can_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x14(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x14(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x8(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
imul   $0x3e8,-0x8(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %edx,-0xc(%rbp)
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %ecx,%ecx
lea    -0x14(%rbp),%rdx
lea    -0x10(%rbp),%r8
mov    %ecx,%esi
call   1040 <select@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edx
xor    %eax,%eax
mov    $0x1,%ecx
cmp    $0x0,%edx
cmovg  %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<can_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %edi,%ebp
lea    0xc(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
movslq %ebx,%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,%ebp
mov    %rsp,%r8
mov    %ebp,%edi
xor    %esi,%esi
mov    %r14,%rdx
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_send(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.timeval
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%8 = call i32 @FD_ZERO(i32* %6)
%9 = load i32, i32* %3
%10 = call i32 @FD_SET(i32 %9, i32* %6)
%11 = load i32, i32* %4
%12 = sdiv i32 %11, 1000
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store i32 %12, i32* %13
%14 = load i32, i32* %4
%15 = mul nsw i32 %14, 1000
%16 = srem i32 %15, 1000000
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = call i32 @select(i32 %19, i32 0, i32* %6, i32 0, %struct.timeval* %5)
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp sgt i32 %21, 0
%23 = zext i1 %22 to i64
%24 = select i1 %22, i32 1, i32 0
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @can_send(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 0, i32* %4, i32 0, %struct.timeval* %3)
%16 = icmp sgt i32 %15, 0
%17 = zext i1 %16 to i32
ret i32 %17
}