// File: /workspace/github_c_makefile_star2_O3/hkshenSmart[P]ONVIF-discovery_cs/stdsoap2.c
// Function: soap_end_send
SOAP_FMAC2
soap_end_send(struct soap *soap)
{
#ifndef WITH_LEANER
  int err;
  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 (!(err = soap_putdime(soap)))
    err = soap_putmime(soap);
  soap->mime.list = NULL;
  soap->mime.first = NULL;
  soap->mime.last = NULL;
  soap->dime.list = NULL;
  soap->dime.first = NULL;
  soap->dime.last = NULL;
  if (err)
    return err;
#endif
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End send mode=0x%x\n", soap->mode));
  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, SOAP_SHUT_WR); /* Send TCP FIN */
#else
  if (soap_valid_socket(soap->socket) && !soap->keep_alive && !(soap->omode & SOAP_IO_UDP))
    soap->fshutdownsocket(soap, soap->socket, SOAP_SHUT_WR); /* Send TCP FIN */
#endif
#endif
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "End of send phase\n"));
  soap->omode &= ~SOAP_SEC_WSUID;
  soap->count = 0;
  soap->part = SOAP_END;
  return SOAP_OK;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x1f2d0(%rdi), %rax
testq %rax, %rax
je 0x190f0
movq 0x1f2d8(%rbx), %rcx
movq 0x1f2e0(%rbx), %rdx
movq %rcx, (%rdx)
movq (%rax), %rcx
movq %rcx, 0x1f2d8(%rbx)
movq $0x0, (%rax)
movq %rax, 0x1f2e0(%rbx)
leaq 0x1f2d0(%rbx), %r14
movq %rbx, %rdi
callq 0x192d6
testl %eax, %eax
jne 0x1910b
movq %rbx, %rdi
callq 0x1952b
xorl %ecx, %ecx
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq %rcx, 0x10(%r14)
movq %rcx, 0x1f308(%rbx)
movups %xmm0, 0x1f2f8(%rbx)
testl %eax, %eax
jne 0x192bf
testb $0x3, 0x4(%rbx)
je 0x192a5
movq %rbx, %rdi
callq 0x1041c
testl %eax, %eax
je 0x1914f
movl 0x1f274(%rbx), %eax
jmp 0x192bf
movl 0x4(%rbx), %eax
movl %eax, %ecx
andl $0x3, %ecx
cmpl $0x3, %ecx
je 0x191bc
cmpl $0x2, %ecx
jne 0x192a5
testb $0x40, %al
jne 0x19229
decl %eax
movl %eax, 0x4(%rbx)
movl 0x1f270(%rbx), %esi
cmpl $0x7d0, %esi            # imm = 0x7D0
jl 0x191e4
leaq 0x1e608(%rbx), %rsi
leaq 0x1ee08(%rbx), %rdx
movl 0x1f228(%rbx), %ecx
leaq 0x1ea08(%rbx), %r8
movq 0x1f208(%rbx), %r9
movq 0x90(%rbx), %rax
movq 0x10(%rax), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
callq *0xbf88(%rbx)
jmp 0x19208
leaq 0xd200(%rip), %rsi      # 0x263c3
movl $0x7, %edx
movq %rbx, %rdi
callq *0xc028(%rbx)
movl %eax, 0x1f274(%rbx)
testl %eax, %eax
jne 0x192bf
jmp 0x192a5
cmpl $0x3e8, %esi            # imm = 0x3E8
jne 0x191f4
movl 0x1f274(%rbx), %eax
jmp 0x1920e
movq 0x90(%rbx), %rax
movq 0x10(%rax), %rdx
movq %rbx, %rdi
callq *0xbfc8(%rbx)
movl %eax, 0x1f274(%rbx)
testl %eax, %eax
jne 0x192bf
movq %rbx, %rdi
callq 0x1041c
testl %eax, %eax
jne 0x19144
incl 0x4(%rbx)
movq 0x90(%rbx), %rax
movq 0x8(%rax), %rcx
testq %rcx, %rcx
je 0x1929b
xorl %esi, %esi
movq %rsi, %rdx
movq %rcx, %rsi
movq (%rcx), %rcx
movq %rdx, (%rsi)
testq %rcx, %rcx
jne 0x1923b
movq %rsi, 0x8(%rax)
addq $0x10, %rsi
movq 0x90(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdx
movq %rbx, %rdi
callq *0xc028(%rbx)
movl %eax, 0x1f274(%rbx)
testl %eax, %eax
jne 0x192c7
movq 0x90(%rbx), %r14
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x1929b
movq (%rdi), %rax
movq %rax, 0x8(%r14)
callq 0x3030
movq 0x8(%r14), %rsi
testq %rsi, %rsi
jne 0x19250
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13563
andb $0x7f, 0xf(%rbx)
movq $0x0, 0xc170(%rbx)
movw $0x9, 0x1e5f0(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13563
jmp 0x19144