// File: /workspace/github_c_makefile_star2_O1/hkshenSmart[P]ONVIF-discovery_cs/stdsoap2.c
// Function: fsend
static int
fsend(struct soap *soap, const char *s, size_t n)
{ register int nwritten, err;
#if defined(__cplusplus) && !defined(WITH_LEAN) && !defined(WITH_COMPAT)
  if (soap->os)
  { soap->os->write(s, (std::streamsize)n);
    if (soap->os->good())
      return SOAP_OK;
    soap->errnum = 0;
    return SOAP_EOF;
  }
#endif
  while (n)
  { if (soap_valid_socket(soap->socket))
    {
      if (soap->send_timeout)
      { for (;;)
        { register int r;
#ifdef WITH_OPENSSL
          if (soap->ssl)
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ALL, soap->send_timeout);
          else
#endif
#ifdef WITH_GNUTLS
          if (soap->session)
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ALL, soap->send_timeout);
          else
#endif
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout);
          if (r > 0)
            break;
          if (!r)
            return SOAP_EOF;
          err = soap->errnum;
          if (!err)
            return soap->error;
          if (err != SOAP_EINTR && err != SOAP_EAGAIN && err != SOAP_EWOULDBLOCK)
            return SOAP_EOF;
        }
      }
#ifdef WITH_OPENSSL
      if (soap->ssl)
        nwritten = SSL_write(soap->ssl, s, (int)n);
      else if (soap->bio)
        nwritten = BIO_write(soap->bio, s, (int)n);
      else
#endif
#ifdef WITH_GNUTLS
      if (soap->session)
        nwritten = gnutls_record_send(soap->session, s, n);
      else
#endif
#ifndef WITH_LEAN
      if ((soap->omode & SOAP_IO_UDP))
      { if (soap->peerlen)
          nwritten = sendto(soap->socket, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
        else
          nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
        /* retry and back-off algorithm */
        /* TODO: this is not very clear from specs so verify and limit conditions under which we should loop (e.g. ENOBUFS) */
        if (nwritten < 0)
        { int udp_repeat;
          int udp_delay;
          if ((soap->connect_flags & SO_BROADCAST))
            udp_repeat = 3; /* SOAP-over-UDP MULTICAST_UDP_REPEAT - 1 */
          else
            udp_repeat = 1; /* SOAP-over-UDP UNICAST_UDP_REPEAT - 1 */
          udp_delay = ((unsigned int)soap_random % 201) + 50; /* UDP_MIN_DELAY .. UDP_MAX_DELAY */
          do
          { tcp_select(soap, soap->socket, SOAP_TCP_SELECT_ERR, -1000 * udp_delay);
            if (soap->peerlen)
              nwritten = sendto(soap->socket, (char*)s, (SOAP_WINSOCKINT)n, soap->socket_flags, (struct sockaddr*)&soap->peer, (SOAP_WINSOCKINT)soap->peerlen);
            else
              nwritten = send(soap->socket, s, (SOAP_WINSOCKINT)n, soap->socket_flags);
            udp_delay <<= 1;
            if (udp_delay > 500) /* UDP_UPPER_DELAY */
              udp_delay = 500;
          }
          while (nwritten < 0 && --udp_repeat > 0);
        }
      }
      else
#endif
#if !defined(PALM) && !defined(AS400)
        nwritten = send(soap->socket, s, (int)n, soap->socket_flags);
#else
        nwritten = send(soap->socket, (void*)s, n, soap->socket_flags);
#endif
      if (nwritten <= 0)
      {
        register int r = 0;
        err = soap_socket_errno(soap->socket);
#ifdef WITH_OPENSSL
        if (soap->ssl && (r = SSL_get_error(soap->ssl, nwritten)) != SSL_ERROR_NONE && r != SSL_ERROR_WANT_READ && r != SSL_ERROR_WANT_WRITE)
        { soap->errnum = err;
          return SOAP_EOF;
        }
#endif
#ifdef WITH_GNUTLS
        if (soap->session)
        { if (nwritten == GNUTLS_E_INTERRUPTED)
            err = SOAP_EINTR;
          else if (nwritten == GNUTLS_E_AGAIN)
            err = SOAP_EAGAIN;
        }
#endif
        if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN)
        {
#if defined(WITH_OPENSSL)
          if (soap->ssl && r == SSL_ERROR_WANT_READ)
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
          else
#elif defined(WITH_GNUTLS)
          if (soap->session && !gnutls_record_get_direction(soap->session))
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_RCV | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
          else
#endif
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
          if (!r && soap->send_timeout)
            return SOAP_EOF;
          if (r < 0 && soap->errnum != SOAP_EINTR)
            return SOAP_EOF;
        }
        else if (err && err != SOAP_EINTR)
        { soap->errnum = err;
          return SOAP_EOF;
        }
        nwritten = 0; /* and call write() again */
      }
    }
    else
    {
#ifdef WITH_FASTCGI
      nwritten = fwrite((void*)s, 1, n, stdout);
      fflush(stdout);
#else
#ifdef UNDER_CE
      nwritten = fwrite(s, 1, n, soap->sendfd);
#else
#ifdef VXWORKS
#ifdef WMW_RPM_IO
      if (soap->rpmreqid)
        nwritten = (httpBlockPut(soap->rpmreqid, (char*)s, n) == 0) ? n : -1;
      else
#endif
        nwritten = fwrite(s, sizeof(char), n, fdopen(soap->sendfd, "w"));
#else
#ifdef WIN32
      nwritten = _write(soap->sendfd, s, (unsigned int)n);
#else
      nwritten = write(soap->sendfd, s, (unsigned int)n);
#endif
#endif
#endif
#endif
      if (nwritten <= 0)
      {
#ifndef WITH_FASTCGI
        err = soap_errno;
#else
        err = EOF;
#endif
        if (err && err != SOAP_EINTR && err != SOAP_EWOULDBLOCK && err != SOAP_EAGAIN)
        { soap->errnum = err;
          return SOAP_EOF;
        }
        nwritten = 0; /* and call write() again */
      }
    }
    n -= nwritten;
    s += nwritten;
  }
  return SOAP_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdx, %rdx
je 0x1741f
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0x27384(%rdi), %rax
movq %rax, 0x10(%rsp)
cmpl $-0x1, 0xc134(%r14)
je 0x1726e
cmpl $0x0, 0x54(%r14)
je 0x17245
movl 0xc134(%r14), %esi
movl 0x54(%r14), %ecx
movq %r14, %rdi
movl $0x6, %edx
callq 0x14afd
movl $0x4, %ecx
testl %eax, %eax
jg 0x17238
movl $0x1, %ecx
je 0x1722f
movl 0x1f27c(%r14), %eax
cmpl $0xb, %eax
je 0x17236
cmpl $0x4, %eax
je 0x17236
testl %eax, %eax
jne 0x1722f
movl 0x1f274(%r14), %ebp
jmp 0x17238
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17238
xorl %ecx, %ecx
testl %ecx, %ecx
je 0x171e9
cmpl $0x4, %ecx
jne 0x17421
testb $0x4, 0xc(%r14)
movl %ebp, 0xc(%rsp)
jne 0x172b1
movl 0xc134(%r14), %edi
movslq %ebx, %rdx
movl 0x60(%r14), %ecx
movq %r15, %rsi
callq 0x3120
movq %rax, %r13
jmp 0x17396
movl 0xc148(%r14), %edi
movl %ebx, %edx
movq %r15, %rsi
callq 0x30e0
movq %rax, %r13
testl %r13d, %r13d
jg 0x17410
callq 0x3050
movl (%rax), %eax
cmpl $0xb, %eax
ja 0x17432
xorl %r13d, %r13d
movl $0x811, %ecx            # imm = 0x811
btl %eax, %ecx
jb 0x17410
jmp 0x17432
movq 0x27398(%r14), %r9
movl 0xc134(%r14), %edi
testq %r9, %r9
je 0x172da
movl 0x60(%r14), %ecx
movq %r15, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %r8
callq 0x3190
jmp 0x172e9
movl 0x60(%r14), %ecx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3120
movq %rax, %r13
testl %r13d, %r13d
jns 0x17396
xorl %eax, %eax
testb $0x6, 0x64(%r14)
setne %al
leal 0x2(,%rax,2), %r12d
callq 0x3340
movl %eax, %ecx
imulq $0x28c1979, %rcx, %rcx  # imm = 0x28C1979
shrq $0x21, %rcx
imull $0xc9, %ecx, %ecx
negl %ecx
leal (%rax,%rcx), %ebp
addl $0x32, %ebp
movl 0xc134(%r14), %esi
imull $0xfffffc18, %ebp, %ecx # imm = 0xFFFFFC18
movq %r14, %rdi
movl $0x4, %edx
callq 0x14afd
movq 0x27398(%r14), %r9
movl 0xc134(%r14), %edi
testq %r9, %r9
je 0x1736a
movl 0x60(%r14), %ecx
movq %r15, %rsi
movq %rbx, %rdx
movq 0x10(%rsp), %r8
callq 0x3190
jmp 0x17379
movl 0x60(%r14), %ecx
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3120
movq %rax, %r13
testl %r13d, %r13d
jns 0x17396
addl %ebp, %ebp
movl $0x1f4, %eax            # imm = 0x1F4
cmpl %eax, %ebp
cmovgel %eax, %ebp
decl %r12d
cmpl $0x1, %r12d
jg 0x17327
testl %r13d, %r13d
jle 0x173a1
movl 0xc(%rsp), %ebp
jmp 0x17410
callq 0x3050
movl (%rax), %eax
cmpl $0xb, %eax
movl 0xc(%rsp), %ebp
jne 0x173e7
movl 0xc134(%r14), %esi
movl 0x54(%r14), %ecx
testl %ecx, %ecx
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
cmovel %eax, %ecx
movq %r14, %rdi
movl $0x6, %edx
callq 0x14afd
testl %eax, %eax
je 0x173fe
testl %eax, %eax
jns 0x173f7
cmpl $0x4, 0x1f27c(%r14)
je 0x173f7
jmp 0x17405
testl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
je 0x173f7
movl %eax, 0x1f27c(%r14)
jmp 0x17405
movb $0x1, %al
xorl %r13d, %r13d
jmp 0x1740c
cmpl $0x0, 0x54(%r14)
je 0x173d7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %eax, %eax
testb %al, %al
je 0x17421
movslq %r13d, %rax
addq %rax, %r15
subq %rax, %rbx
jne 0x171d4
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x1f27c(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x17421