#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 {
  long long tv_sec;
  long long 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 cmpp_sock_writable(int fd, long long millisecond) {
  int ret;
  fd_set wset;
  struct timeval timeout;
  timeout.tv_sec = millisecond / 1000;
  timeout.tv_usec = (millisecond % 1000) * 1000;
  FD_ZERO(&wset);
  FD_SET(fd, &wset);
  ret = select(fd + 1, NULL, &wset, NULL, &timeout);
  return ret;
}


x86 assembly (clang, -O0):
<cmpp_sock_writable>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
imul   $0x3e8,%rdx,%rax
mov    %rax,-0x20(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <FD_ZERO@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <FD_SET@plt>
mov    -0x4(%rbp),%edi
add    $0x1,%edi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x18(%rbp),%rdx
lea    -0x28(%rbp),%r8
mov    %rcx,%rsi
call   1040 <select@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmpp_sock_writable>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebx
movabs $0x20c49ba5e353f7cf,%rcx
9b c4 20
mov    %rsi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
mov    %rdx,0x8(%rsp)
imul   $0x3e8,%rdx,%rax
sub    %rax,%rsi
imul   $0x3e8,%rsi,%rax
mov    %rax,0x10(%rsp)
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1030 <FD_ZERO@plt>
mov    %ebx,%edi
mov    %r14,%rsi
call   1050 <FD_SET@plt>
add    $0x1,%ebx
lea    0x8(%rsp),%r8
mov    %ebx,%edi
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1040 <select@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define i32 @cmpp_sock_writable(i32 %0, i64 %1) {
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.timeval
store i32 %0, i32* %3
store i64 %1, i64* %4
%8 = load i64, i64* %4
%9 = sdiv i64 %8, 1000
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
store i64 %9, i64* %10
%11 = load i64, i64* %4
%12 = srem i64 %11, 1000
%13 = mul nsw i64 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
store i64 %13, i64* %14
%15 = call i32 @FD_ZERO(i32* %6)
%16 = load i32, i32* %3
%17 = call i32 @FD_SET(i32 %16, i32* %6)
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = call i32 @select(i32 %19, i32* null, i32* %6, i32* null, %struct.timeval* %7)
store i32 %20, i32* %5
%21 = load i32, i32* %5
ret i32 %21
}

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