// File: /workspace/github_c_makefile_star2_O2/hkshenSmart[P]ONVIF-discovery_cs/stdsoap2.c
// Function: tcp_select
static int
tcp_select(struct soap *soap, SOAP_SOCKET s, int flags, int timeout)
{ register int r;
  struct timeval tv;
  fd_set fd[3], *rfd, *sfd, *efd;
  soap->errnum = 0;
#ifndef WIN32
#if !defined(FD_SETSIZE) || defined(__QNX__) || defined(QNX)
  /* no FD_SETSIZE or select() is not MT safe on some QNX: always poll */
  if (1)
#else
  /* if fd max set size exceeded, use poll() */
  if ((int)s >= (int)FD_SETSIZE)
#endif
#ifdef HAVE_POLL
  { struct pollfd pollfd;
    int retries = 0;
    pollfd.fd = (int)s;
    pollfd.events = 0;
    if (flags & SOAP_TCP_SELECT_RCV)
      pollfd.events |= POLLIN;
    if (flags & SOAP_TCP_SELECT_SND)
      pollfd.events |= POLLOUT;
    if (flags & SOAP_TCP_SELECT_ERR)
      pollfd.events |= POLLERR;
    if (timeout < 0)
      timeout /= -1000; /* -usec -> ms */
    else if (timeout <= 1000000) /* avoid overflow */
      timeout *= 1000; /* sec -> ms */
    else
    { retries = timeout / 1000000;
      timeout = 1000000000;
    }
    do r = poll(&pollfd, 1, timeout);
    while (r == 0 && retries--);
    if (r > 0)
    { r = 0;
      if ((flags & SOAP_TCP_SELECT_RCV) && (pollfd.revents & POLLIN))
        r |= SOAP_TCP_SELECT_RCV;
      if ((flags & SOAP_TCP_SELECT_SND) && (pollfd.revents & POLLOUT))
        r |= SOAP_TCP_SELECT_SND;
      if ((flags & SOAP_TCP_SELECT_ERR) && (pollfd.revents & POLLERR))
        r |= SOAP_TCP_SELECT_ERR;
    }
    else if (r < 0)
      soap->errnum = soap_socket_errno(s);
    return r;
  }
#else
  { soap->error = SOAP_FD_EXCEEDED;
    return -1;
  }
#endif
#endif
  rfd = sfd = efd = NULL;
  if (flags & SOAP_TCP_SELECT_RCV)
  { rfd = &fd[0];
    FD_ZERO(rfd);
    FD_SET(s, rfd);
  }
  if (flags & SOAP_TCP_SELECT_SND)
  { sfd = &fd[1];
    FD_ZERO(sfd);
    FD_SET(s, sfd);
  }
  if (flags & SOAP_TCP_SELECT_ERR)
  { efd = &fd[2];
    FD_ZERO(efd);
    FD_SET(s, efd);
  }
  if (timeout >= 0)
  { tv.tv_sec = timeout;
    tv.tv_usec = 0;
  }
  else
  { tv.tv_sec = -timeout / 1000000;
    tv.tv_usec = -timeout % 1000000;
  }
  r = select((int)s + 1, rfd, sfd, efd, &tv);
  if (r > 0)
  { r = 0;
    if ((flags & SOAP_TCP_SELECT_RCV) && FD_ISSET(s, rfd))
      r |= SOAP_TCP_SELECT_RCV;
    if ((flags & SOAP_TCP_SELECT_SND) && FD_ISSET(s, sfd))
      r |= SOAP_TCP_SELECT_SND;
    if ((flags & SOAP_TCP_SELECT_ERR) && FD_ISSET(s, efd))
      r |= SOAP_TCP_SELECT_ERR;
  }
  else if (r < 0)
    soap->errnum = soap_socket_errno(s);
  return r;
}

// Assembly:
andl $0x0, 0x1f27c(%rdi)
cmpl $0x400, %esi            # imm = 0x400
jl 0x137f2
movl $0x2e, 0x1f274(%rdi)
pushq $-0x1
popq %rcx
jmp 0x139ab
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %ecx, %r8d
movl %edx, %ebp
movl %esi, %ebx
movq %rdi, 0x8(%rsp)
pushq $0x40
popq %rdi
pushq $0x1
popq %r10
testb $0x1, %bpl
jne 0x13820
xorl %esi, %esi
jmp 0x13852
xorl %eax, %eax
cmpq $0x10, %rax
je 0x13833
andq $0x0, 0x20(%rsp,%rax,8)
incq %rax
jmp 0x13822
movl %ebx, %eax
cltd
idivl %edi
movslq %eax, %rdx
shll $0x6, %eax
movl %ebx, %ecx
subl %eax, %ecx
movq %r10, %rax
shlq %cl, %rax
orq %rax, 0x20(%rsp,%rdx,8)
leaq 0x20(%rsp), %rsi
testb $0x2, %bpl
jne 0x1385d
xorl %r9d, %r9d
jmp 0x13898
leaq 0xa0(%rsp), %r9
xorl %eax, %eax
cmpq $0x10, %rax
je 0x1387b
andq $0x0, 0xa0(%rsp,%rax,8)
incq %rax
jmp 0x13867
movl %ebx, %eax
cltd
idivl %edi
movslq %eax, %rdx
shll $0x6, %eax
movl %ebx, %ecx
subl %eax, %ecx
movq %r10, %rax
shlq %cl, %rax
orq %rax, 0xa0(%rsp,%rdx,8)
testb $0x4, %bpl
jne 0x138a3
xorl %r11d, %r11d
jmp 0x138db
leaq 0x120(%rsp), %r11
xorl %eax, %eax
cmpq $0x10, %rax
je 0x138c1
andq $0x0, 0x120(%rsp,%rax,8)
incq %rax
jmp 0x138ad
movl %ebx, %eax
cltd
idivl %edi
movslq %eax, %rdx
shll $0x6, %eax
movl %ebx, %ecx
subl %eax, %ecx
shlq %cl, %r10
orq %r10, 0x120(%rsp,%rdx,8)
testl %r8d, %r8d
js 0x138e4
xorl %edx, %edx
jmp 0x138f6
negl %r8d
movl $0xf4240, %ecx          # imm = 0xF4240
movl %r8d, %eax
xorl %edx, %edx
divl %ecx
movl %eax, %r8d
movl %r8d, %eax
leaq 0x10(%rsp), %r8
movq %rax, (%r8)
movq %rdx, 0x8(%r8)
leal 0x1(%rbx), %edi
movq %rsi, %r14
movq %r9, %r13
movq %r9, %rdx
movq %r11, %r12
movq %r11, %rcx
callq 0x3230
testl %eax, %eax
jle 0x1397c
xorl %ecx, %ecx
testb $0x1, %bpl
pushq $0x40
popq %rdi
je 0x1393f
movl %ebx, %eax
cltd
idivl %edi
cltq
movq (%r14,%rax,8), %rax
xorl %ecx, %ecx
btq %rdx, %rax
setb %cl
testb $0x2, %bpl
je 0x1395d
movl %ebx, %eax
cltd
idivl %edi
cltq
movq (%r13,%rax,8), %rax
leal 0x2(%rcx), %esi
btq %rdx, %rax
cmovael %ecx, %esi
movl %esi, %ecx
testb $0x4, %bpl
je 0x1399a
movl %ebx, %eax
cltd
idivl %edi
cltq
movq (%r12,%rax,8), %rax
leal 0x4(%rcx), %esi
btq %rdx, %rax
cmovael %ecx, %esi
movl %esi, %ecx
jmp 0x1399a
movl %eax, %r15d
xorl %ecx, %ecx
testl %eax, %eax
jns 0x1399a
callq 0x3050
movl (%rax), %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x1f27c(%rcx)
movl %r15d, %ecx
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
movl %ecx, %eax
retq