// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x22263
movq -0x10(%rbp), %rax
cmpl $-0x1, 0xc134(%rax)
je 0x221d9
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x21f46
jmp 0x21ec0
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x54(%rax), %ecx
movl $0x6, %edx
callq 0x1e0d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x21eea
jmp 0x21f44
cmpl $0x0, -0x2c(%rbp)
jne 0x21efc
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
movq -0x10(%rbp), %rax
movl 0x1f27c(%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x21f21
movq -0x10(%rbp), %rax
movl 0x1f274(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x2226a
cmpl $0x4, -0x28(%rbp)
je 0x21f3f
cmpl $0xb, -0x28(%rbp)
je 0x21f3f
cmpl $0xb, -0x28(%rbp)
je 0x21f3f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
jmp 0x21ec0
jmp 0x21f46
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x220d1
movq -0x10(%rbp), %rax
cmpq $0x0, 0x27398(%rax)
je 0x21fa3
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %r8
addq $0x27384, %r8           # imm = 0x27384
movq -0x10(%rbp), %rax
movq 0x27398(%rax), %rax
movl %eax, %r9d
callq 0x31a0
movl %eax, -0x24(%rbp)
jmp 0x21fc4
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
callq 0x3120
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jge 0x220cf
movq -0x10(%rbp), %rax
movl 0x64(%rax), %eax
andl $0x6, %eax
cmpl $0x0, %eax
je 0x21fe6
movl $0x3, -0x30(%rbp)
jmp 0x21fed
movl $0x1, -0x30(%rbp)
callq 0x3360
movl $0xc9, %ecx
xorl %edx, %edx
divl %ecx
addl $0x32, %edx
movl %edx, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %esi
imull $0xfffffc18, -0x34(%rbp), %ecx # imm = 0xFFFFFC18
movl $0x4, %edx
callq 0x1e0d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x27398(%rax)
je 0x2206a
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %r8
addq $0x27384, %r8           # imm = 0x27384
movq -0x10(%rbp), %rax
movq 0x27398(%rax), %rax
movl %eax, %r9d
callq 0x31a0
movl %eax, -0x24(%rbp)
jmp 0x2208b
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
callq 0x3120
movl %eax, -0x24(%rbp)
movl -0x34(%rbp), %eax
shll %eax
movl %eax, -0x34(%rbp)
cmpl $0x1f4, -0x34(%rbp)     # imm = 0x1F4
jle 0x220a3
movl $0x1f4, -0x34(%rbp)     # imm = 0x1F4
jmp 0x220a5
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x39(%rbp)
jge 0x220c2
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, %eax
setg %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x22001
jmp 0x220cf
jmp 0x220f5
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movslq %eax, %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
callq 0x3120
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x221d7
movl $0x0, -0x38(%rbp)
callq 0x3050
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0xb, -0x28(%rbp)
je 0x22120
cmpl $0xb, -0x28(%rbp)
jne 0x221a9
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0xc134(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x2214b
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x22155
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
movl %eax, -0x4c(%rbp)
jmp 0x22155
movl -0x40(%rbp), %esi
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %ecx
movl $0x6, %edx
callq 0x1e0d0
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x22188
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x22188
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
cmpl $0x0, -0x38(%rbp)
jge 0x221a7
movq -0x10(%rbp), %rax
cmpl $0x4, 0x1f27c(%rax)
je 0x221a7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
jmp 0x221d0
cmpl $0x0, -0x28(%rbp)
je 0x221ce
cmpl $0x4, -0x28(%rbp)
je 0x221ce
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
jmp 0x221d0
movl $0x0, -0x24(%rbp)
jmp 0x2223e
movq -0x10(%rbp), %rax
movl 0xc148(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rax
movl %eax, %eax
movl %eax, %edx
callq 0x30d0
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jg 0x2223c
callq 0x3050
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x22235
cmpl $0x4, -0x28(%rbp)
je 0x22235
cmpl $0xb, -0x28(%rbp)
je 0x22235
cmpl $0xb, -0x28(%rbp)
je 0x22235
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1f27c(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x2226a
movl $0x0, -0x24(%rbp)
jmp 0x2223e
movslq -0x24(%rbp), %rcx
movq -0x20(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x18(%rbp)
jmp 0x21e94
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)