// File: /workspace/github_c_makefile_star2_O0/loversmile[P]sugarcrm/sugar_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))
    { 
#ifndef WITH_LEAN
      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
            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;
        }
      }
#endif
#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
#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 = (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)
      {
#if defined(WITH_OPENSSL) || !defined(WITH_LEAN)
        register int r = 0;
#endif
        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
        if (err == SOAP_EWOULDBLOCK || err == SOAP_EAGAIN)
        {
#ifndef WITH_LEAN
#ifdef 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
            r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
#else
          r = tcp_select(soap, soap->socket, SOAP_TCP_SELECT_SND | SOAP_TCP_SELECT_ERR, soap->send_timeout ? soap->send_timeout : -10000);
#endif
	  if (!r && soap->send_timeout)
            return SOAP_EOF;
	  if (r < 0 && soap->errnum != SOAP_EINTR)
            return SOAP_EOF;
#endif
        }
        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 0x58be2
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x60d4(%rax)
je 0x58b58
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x588c6
jmp 0x58840
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60d4(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x54(%rax), %ecx
movl $0x6, %edx
callq 0x59760
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x5886a
jmp 0x588c4
cmpl $0x0, -0x2c(%rbp)
jne 0x5887c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
movq -0x10(%rbp), %rax
movl 0x1921c(%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x588a1
movq -0x10(%rbp), %rax
movl 0x19214(%rax), %eax
movl %eax, -0x4(%rbp)
jmp 0x58be9
cmpl $0x4, -0x28(%rbp)
je 0x588bf
cmpl $0xb, -0x28(%rbp)
je 0x588bf
cmpl $0xb, -0x28(%rbp)
je 0x588bf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
jmp 0x58840
jmp 0x588c6
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x58a50
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1b338(%rax)
je 0x58923
movq -0x10(%rbp), %rax
movl 0x60d4(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %r8
addq $0x1b324, %r8           # imm = 0x1B324
movq -0x10(%rbp), %rax
movq 0x1b338(%rax), %rax
movl %eax, %r9d
callq 0x31a0
movl %eax, -0x24(%rbp)
jmp 0x58944
movq -0x10(%rbp), %rax
movl 0x60d4(%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 0x58a4e
movq -0x10(%rbp), %rax
movl 0x64(%rax), %eax
andl $0x6, %eax
cmpl $0x0, %eax
je 0x58966
movl $0x3, -0x30(%rbp)
jmp 0x5896d
movl $0x1, -0x30(%rbp)
callq 0x3400
movl $0xc9, %ecx
cltd
idivl %ecx
addl $0x32, %edx
movl %edx, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60d4(%rax), %esi
imull $0xfffffc18, -0x34(%rbp), %ecx # imm = 0xFFFFFC18
movl $0x4, %edx
callq 0x59760
movq -0x10(%rbp), %rax
cmpq $0x0, 0x1b338(%rax)
je 0x589e9
movq -0x10(%rbp), %rax
movl 0x60d4(%rax), %edi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x10(%rbp), %r8
addq $0x1b324, %r8           # imm = 0x1B324
movq -0x10(%rbp), %rax
movq 0x1b338(%rax), %rax
movl %eax, %r9d
callq 0x31a0
movl %eax, -0x24(%rbp)
jmp 0x58a0a
movq -0x10(%rbp), %rax
movl 0x60d4(%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 0x58a22
movl $0x1f4, -0x34(%rbp)     # imm = 0x1F4
jmp 0x58a24
xorl %eax, %eax
cmpl $0x0, -0x24(%rbp)
movb %al, -0x39(%rbp)
jge 0x58a41
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 0x58980
jmp 0x58a4e
jmp 0x58a74
movq -0x10(%rbp), %rax
movl 0x60d4(%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 0x58b56
movl $0x0, -0x38(%rbp)
callq 0x3060
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0xb, -0x28(%rbp)
je 0x58a9f
cmpl $0xb, -0x28(%rbp)
jne 0x58b28
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x60d4(%rax), %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x58aca
movq -0x10(%rbp), %rax
movl 0x54(%rax), %eax
movl %eax, -0x4c(%rbp)
jmp 0x58ad4
movl $0xffffd8f0, %eax       # imm = 0xFFFFD8F0
movl %eax, -0x4c(%rbp)
jmp 0x58ad4
movl -0x40(%rbp), %esi
movq -0x48(%rbp), %rdi
movl -0x4c(%rbp), %ecx
movl $0x6, %edx
callq 0x59760
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
jne 0x58b07
movq -0x10(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x58b07
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
cmpl $0x0, -0x38(%rbp)
jge 0x58b26
movq -0x10(%rbp), %rax
cmpl $0x4, 0x1921c(%rax)
je 0x58b26
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
jmp 0x58b4f
cmpl $0x0, -0x28(%rbp)
je 0x58b4d
cmpl $0x4, -0x28(%rbp)
je 0x58b4d
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1921c(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
jmp 0x58b4f
movl $0x0, -0x24(%rbp)
jmp 0x58bbd
movq -0x10(%rbp), %rax
movl 0x60e8(%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 0x58bbb
callq 0x3060
movl (%rax), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x58bb4
cmpl $0x4, -0x28(%rbp)
je 0x58bb4
cmpl $0xb, -0x28(%rbp)
je 0x58bb4
cmpl $0xb, -0x28(%rbp)
je 0x58bb4
movl -0x28(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1921c(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x58be9
movl $0x0, -0x24(%rbp)
jmp 0x58bbd
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 0x58814
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)