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


x86 assembly (clang, -O0):
<g_tcp_can_send>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
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)
lea    -0x10(%rbp),%rdi
call   1040 <FD_ZERO@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11c6 <g_tcp_can_send+0x86>
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1060 <FD_SET@plt>
mov    -0x8(%rbp),%edi
add    $0x1,%edi
xor    %ecx,%ecx
lea    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%r8
mov    %ecx,%esi
call   1050 <select@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    11c1 <g_tcp_can_send+0x81>
mov    -0x8(%rbp),%edi
call   1030 <g_tcp_socket_ok@plt>
mov    %eax,-0x4(%rbp)
jmp    11cd <g_tcp_can_send+0x8d>
jmp    11c6 <g_tcp_can_send+0x86>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<g_tcp_can_send>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
movslq %esi,%rax
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,0x8(%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,0xc(%rsp)
lea    0x4(%rsp),%rdi
call   1040 <FD_ZERO@plt>
test   %ebx,%ebx
jle    11cf <g_tcp_can_send+0x8f>
lea    0x4(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
call   1060 <FD_SET@plt>
lea    0x1(%rbx),%edi
xor    %ebp,%ebp
lea    0x8(%rsp),%r8
xor    %esi,%esi
mov    %r14,%rdx
xor    %ecx,%ecx
call   1050 <select@plt>
test   %eax,%eax
jle    11d1 <g_tcp_can_send+0x91>
mov    %ebx,%edi
call   1030 <g_tcp_socket_ok@plt>
mov    %eax,%ebp
jmp    11d1 <g_tcp_can_send+0x91>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
define i32 @g_tcp_can_send(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.timeval
%5 = bitcast i32* %3 to i8*
%6 = bitcast %struct.timeval* %4 to i8*
%7 = sdiv i32 %1, 1000
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
store i32 %7, i32* %8
%9 = mul nsw i32 %1, 1000
%10 = srem i32 %9, 1000000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
store i32 %10, i32* %11
%12 = call i32 @FD_ZERO(i32* %3)
%13 = icmp sgt i32 %0, 0
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = call i32 @FD_SET(i32 %0, i32* %3)
%16 = add nuw nsw i32 %0, 1
%17 = call i32 @select(i32 %16, i32 0, i32* %3, i32 0, %struct.timeval* %4)
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @g_tcp_socket_ok(i32 %0)
br label %21
21: ; preds = %2, %14, %19
%22 = phi i32 [ %20, %19 ], [ 0, %14 ], [ 0, %2 ]
ret i32 %22
}