// File: /workspace/github_c_makefile_star2_O1/loversmile[P]sugarcrm/sugar_stdsoap2.c
// Function: soap_end_send
SOAP_FMAC2
soap_end_send(struct soap *soap)
{ 
#ifndef WITH_LEANER
  if (soap->dime.list)
  { /* SOAP body referenced attachments must appear first */
    soap->dime.last->next = soap->dime.first;
    soap->dime.first = soap->dime.list->next;
    soap->dime.list->next = NULL;
    soap->dime.last = soap->dime.list;
  }
  if (soap_putdime(soap) || soap_putmime(soap))
    return soap->error;
  soap->mime.list = NULL;
  soap->mime.first = NULL;
  soap->mime.last = NULL;
  soap->dime.list = NULL;
  soap->dime.first = NULL;
  soap->dime.last = NULL;
#endif
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send\n"));
  if (soap->mode & SOAP_IO) /* need to flush the remaining data in buffer */
  { if (soap_flush(soap))
#ifdef WITH_ZLIB
    { if (soap->mode & SOAP_ENC_ZLIB && soap->zlib_state == SOAP_ZLIB_DEFLATE)
      { soap->zlib_state = SOAP_ZLIB_NONE;
        deflateEnd(soap->d_stream);
      }
      return soap->error;
    }
#else
      return soap->error;
#endif
#ifdef WITH_ZLIB
    if (soap->mode & SOAP_ENC_ZLIB)
    { int r;
      soap->d_stream->avail_in = 0;
      do
      { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflating remainder\n"));
        r = deflate(soap->d_stream, Z_FINISH);
        if (soap->d_stream->avail_out != SOAP_BUFLEN)
        { if (soap_flush_raw(soap, soap->z_buf, SOAP_BUFLEN - soap->d_stream->avail_out))
          { soap->zlib_state = SOAP_ZLIB_NONE;
            deflateEnd(soap->d_stream);
            return soap->error;
          }
          soap->d_stream->next_out = (Byte*)soap->z_buf;
          soap->d_stream->avail_out = SOAP_BUFLEN;
        }
      } while (r == Z_OK);
      DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflated total %lu->%lu bytes\n", soap->d_stream->total_in, soap->d_stream->total_out));
      soap->z_ratio_out = (float)soap->d_stream->total_out / (float)soap->d_stream->total_in;
      soap->mode &= ~SOAP_ENC_ZLIB;
      soap->zlib_state = SOAP_ZLIB_NONE;
      if (deflateEnd(soap->d_stream) != Z_OK || r != Z_STREAM_END)
      { DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Unable to end deflate: %s\n", soap->d_stream->msg?soap->d_stream->msg:SOAP_STR_EOS));
        return soap->error = SOAP_ZLIB_ERROR;
      }
#ifdef WITH_GZIP
      if (soap->zlib_out != SOAP_ZLIB_DEFLATE)
      { soap->z_buf[0] = soap->z_crc & 0xFF;
        soap->z_buf[1] = (soap->z_crc >> 8) & 0xFF;
        soap->z_buf[2] = (soap->z_crc >> 16) & 0xFF;
        soap->z_buf[3] = (soap->z_crc >> 24) & 0xFF;
        soap->z_buf[4] = soap->d_stream->total_in & 0xFF;
        soap->z_buf[5] = (soap->d_stream->total_in >> 8) & 0xFF;
        soap->z_buf[6] = (soap->d_stream->total_in >> 16) & 0xFF;
        soap->z_buf[7] = (soap->d_stream->total_in >> 24) & 0xFF;
        if (soap_flush_raw(soap, soap->z_buf, 8))
          return soap->error;
        DBGLOG(TEST, SOAP_MESSAGE(fdebug, "gzip crc32=%lu\n", (unsigned long)soap->z_crc));
      }
#endif
    }
#endif
    if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
    { char *p;
#ifndef WITH_NOHTTP
      if (!(soap->mode & SOAP_ENC_XML))
      { soap->mode--;
        DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Sending buffered message of length %u\n", (unsigned int)soap->blist->size));
        if (soap->status >= SOAP_POST)
          soap->error = soap->fpost(soap, soap->endpoint, soap->host, soap->port, soap->path, soap->action, soap->blist->size);
        else if (soap->status != SOAP_STOP)
          soap->error = soap->fresponse(soap, soap->status, soap->blist->size);
        if (soap->error || soap_flush(soap))
          return soap->error;
        soap->mode++;
      }
#endif
      for (p = soap_first_block(soap, NULL); p; p = soap_next_block(soap, NULL))
      { DBGMSG(SENT, p, soap_block_size(soap, NULL));
        if ((soap->error = soap->fsend(soap, p, soap_block_size(soap, NULL))))
        { soap_end_block(soap, NULL);
          return soap->error;
        }
      }
      soap_end_block(soap, NULL);
    }
#ifndef WITH_LEANER
    else if ((soap->mode & SOAP_IO) == SOAP_IO_CHUNK)
    { DBGMSG(SENT, "\r\n0\r\n\r\n", 7);
      if ((soap->error = soap->fsend(soap, "\r\n0\r\n\r\n", 7)))
        return soap->error;
    }
#endif
  }
#ifdef WITH_TCPFIN
#ifdef WITH_OPENSSL
  if (!soap->ssl && soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP))
    soap->fshutdownsocket(soap, soap->socket, 1); /* Send TCP FIN */
#else
  if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP))
    soap->fshutdownsocket(soap, soap->socket, 1); /* Send TCP FIN */
#endif
#endif
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n"));
  soap->omode &= ~SOAP_XML_SEC;
  soap->count = 0;
  soap->part = SOAP_END;
  return SOAP_OK;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x19270(%rdi), %rax
testq %rax, %rax
je 0x40184
movq 0x19278(%rbx), %rcx
movq 0x19280(%rbx), %rdx
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, 0x19278(%rbx)
movq $0x0, (%rax)
movq %rax, 0x19280(%rbx)
movq %rbx, %rdi
callq 0x403c7
testl %eax, %eax
jne 0x4019c
movq %rbx, %rdi
callq 0x40642
testl %eax, %eax
je 0x401aa
movl 0x19214(%rbx), %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x19270(%rbx), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
movq %rcx, 0x192a8(%rbx)
movups %xmm0, 0x19298(%rbx)
testb $0x3, 0x4(%rbx)
je 0x403a8
movq 0x60f0(%rbx), %rdx
testq %rdx, %rdx
je 0x401ff
movq $0x0, 0x60f0(%rbx)
leaq 0x6138(%rbx), %rsi
movq %rbx, %rdi
callq 0x37839
testl %eax, %eax
jne 0x4019c
movl 0x4(%rbx), %eax
movl %eax, %ecx
andl $0x3, %ecx
cmpl $0x3, %ecx
je 0x4026c
cmpl $0x2, %ecx
jne 0x403a8
testb $0x40, %al
jne 0x402fa
decl %eax
movl %eax, 0x4(%rbx)
movl 0x19210(%rbx), %esi
cmpl $0x7d0, %esi            # imm = 0x7D0
jl 0x40294
leaq 0x185a8(%rbx), %rsi
leaq 0x18da8(%rbx), %rdx
movl 0x191c8(%rbx), %ecx
leaq 0x189a8(%rbx), %r8
movq 0x191a8(%rbx), %r9
movq 0x90(%rbx), %rax
movq 0x10(%rax), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
callq *0x5f68(%rbx)
jmp 0x402b0
leaq 0x122aa(%rip), %rsi     # 0x5251d
movl $0x7, %edx
movq %rbx, %rdi
callq *0x6000(%rbx)
movl %eax, 0x19214(%rbx)
testl %eax, %eax
jne 0x401a2
jmp 0x403a8
cmpl $0x3e8, %esi            # imm = 0x3E8
je 0x402b6
movq 0x90(%rbx), %rax
movq 0x10(%rax), %rdx
movq %rbx, %rdi
callq *0x5fa0(%rbx)
movl %eax, 0x19214(%rbx)
cmpl $0x0, 0x19214(%rbx)
je 0x402cd
movl 0x19214(%rbx), %eax
xorl %r14d, %r14d
jmp 0x4039f
movq 0x60f0(%rbx), %rdx
testq %rdx, %rdx
je 0x402f7
movq $0x0, 0x60f0(%rbx)
leaq 0x6138(%rbx), %rsi
movq %rbx, %rdi
callq 0x37839
testl %eax, %eax
jne 0x402bf
incl 0x4(%rbx)
movq 0x90(%rbx), %rax
movq 0x8(%rax), %rcx
xorl %esi, %esi
testq %rcx, %rcx
je 0x40378
movq %rsi, %rdx
movq %rcx, %rsi
movq (%rcx), %rcx
movq %rdx, (%rsi)
testq %rcx, %rcx
jne 0x4030c
movq %rsi, 0x8(%rax)
addq $0x10, %rsi
jmp 0x40378
movq 0x90(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq *0x6000(%rbx)
movl %eax, 0x19214(%rbx)
testl %eax, %eax
jne 0x4038c
movq 0x90(%rbx), %r14
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x40376
movq (%rdi), %rax
movq %rax, 0x8(%r14)
callq 0x3030
movq 0x8(%r14), %rax
leaq 0x10(%rax), %rsi
testq %rax, %rax
cmoveq %rax, %rsi
jmp 0x40378
xorl %esi, %esi
testq %rsi, %rsi
jne 0x40327
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3a980
movb $0x1, %r14b
jmp 0x4039f
xorl %r14d, %r14d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3a980
movl 0x19214(%rbx), %eax
testb %r14b, %r14b
je 0x401a2
andb $0x7f, 0xf(%rbx)
movq $0x0, 0x6110(%rbx)
movw $0x9, 0x18590(%rbx)
xorl %eax, %eax
jmp 0x401a2