// File: /workspace/github_c_makefile_star2_O1/loversmile[P]sugarcrm/sugar_stdsoap2.c
// Function: soap_begin_send
SOAP_FMAC2
soap_begin_send(struct soap *soap)
{ DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Initializing for output\n"));
  soap_free_ns(soap);
  soap->error = SOAP_OK;
  soap->mode = soap->omode | (soap->mode & (SOAP_IO_LENGTH | SOAP_ENC_DIME));
#ifdef WITH_ZLIB
  if ((soap->mode & SOAP_ENC_ZLIB) && (soap->mode & SOAP_IO) == SOAP_IO_FLUSH)
  { if (soap->mode & SOAP_ENC_XML)
      soap->mode |= SOAP_IO_BUFFER;
    else
      soap->mode |= SOAP_IO_STORE;
  }
#endif
#ifndef WITH_LEAN
  if ((soap->mode & SOAP_IO_UDP))
  { soap->mode |= SOAP_ENC_XML;
    if (soap->count > SOAP_BUFLEN)
      return soap->error = SOAP_UDP_ERROR;
  }
#endif
  if ((soap->mode & SOAP_IO) == SOAP_IO_FLUSH && soap_valid_socket(soap->socket))
  { if (soap->count || (soap->mode & SOAP_IO_LENGTH) || (soap->mode & SOAP_ENC_XML))
      soap->mode |= SOAP_IO_BUFFER;
    else
      soap->mode |= SOAP_IO_STORE;
  }
  soap->mode &= ~SOAP_IO_LENGTH;
  if ((soap->mode & SOAP_IO) == SOAP_IO_STORE)
    if (soap_new_block(soap) == NULL)
      return soap->error;
  if (!(soap->mode & SOAP_IO_KEEPALIVE))
    soap->keep_alive = 0;
  if (!soap->encodingStyle && !(soap->mode & SOAP_XML_GRAPH))
    soap->mode |= SOAP_XML_TREE;
#ifndef WITH_LEANER
  if ((soap->mode & SOAP_ENC_MTOM) && (soap->mode & SOAP_ENC_DIME))
  { soap->mode |= SOAP_ENC_MIME;
    soap->mode &= ~SOAP_ENC_DIME;
  }
  else if (!(soap->mode & SOAP_ENC_MIME))
    soap->mode &= ~SOAP_ENC_MTOM;
  if (soap->mode & SOAP_ENC_MIME)
    soap_select_mime_boundary(soap);
#ifdef WIN32
#ifndef UNDER_CE
#ifndef WITH_FASTCGI
  if (!soap_valid_socket(soap->socket)) /* Set win32 stdout or soap->sendfd to BINARY, e.g. to support DIME */
#ifdef __BORLANDC__
    setmode(soap->sendfd, _O_BINARY);
#else
    _setmode(soap->sendfd, _O_BINARY);
#endif
#endif
#endif
#endif
#endif
  if (soap->mode & SOAP_IO)
  { soap->bufidx = 0;
    soap->buflen = 0;
  }
  soap->chunksize = 0;
  soap->ns = 0;
  soap->null = 0;
  soap->position = 0;
  soap->mustUnderstand = 0;
  soap->encoding = 0;
  soap->idnum = 0;
  soap->level = 0;
  soap_clr_attr(soap);
  soap_set_local_namespaces(soap);
#ifdef WITH_ZLIB
  soap->z_ratio_out = 1.0;
  if ((soap->mode & SOAP_ENC_ZLIB) && soap->zlib_state != SOAP_ZLIB_DEFLATE)
  { if (!soap->z_buf)
      soap->z_buf = (char*)SOAP_MALLOC(soap, SOAP_BUFLEN);
    soap->d_stream->next_out = (Byte*)soap->z_buf;
    soap->d_stream->avail_out = SOAP_BUFLEN;
#ifdef WITH_GZIP
    if (soap->zlib_out != SOAP_ZLIB_DEFLATE)
    { memcpy(soap->z_buf, "\37\213\10\0\0\0\0\0\0\377", 10);
      soap->d_stream->next_out = (Byte*)soap->z_buf + 10;
      soap->d_stream->avail_out = SOAP_BUFLEN - 10;
      soap->z_crc = crc32(0L, NULL, 0);
      soap->zlib_out = SOAP_ZLIB_GZIP;
      if (soap->z_dict)
        *((Byte*)soap->z_buf + 2) = 0xff;
      if (deflateInit2(soap->d_stream, soap->z_level, Z_DEFLATED, -MAX_WBITS, 8, Z_DEFAULT_STRATEGY) != Z_OK)
        return soap->error = SOAP_ZLIB_ERROR;
    }
    else
#endif
    if (deflateInit(soap->d_stream, soap->z_level) != Z_OK)
      return soap->error = SOAP_ZLIB_ERROR;
    if (soap->z_dict)
    { if (deflateSetDictionary(soap->d_stream, (const Bytef*)soap->z_dict, soap->z_dict_len) != Z_OK)
        return soap->error = SOAP_ZLIB_ERROR;
    }
    DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Deflate initialized\n"));
    soap->zlib_state = SOAP_ZLIB_DEFLATE;
  }
#endif
#ifdef WITH_OPENSSL
  if (soap->ssl)
    ERR_clear_error();
#endif
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Begin send phase (socket=%d mode=0x%x count=%lu)\n", soap->socket, soap->mode, (unsigned long)soap->count));
  soap->part = SOAP_BEGIN;
#ifndef WITH_LEANER
  if (soap->fprepareinitsend && (soap->mode & SOAP_IO) == SOAP_IO_STORE)
    soap->fprepareinitsend(soap);   
#endif
  return SOAP_OK;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x88(%rdi), %rdi
testq %rdi, %rdi
je 0x3eed3
movq (%rdi), %r14
callq 0x3030
movq %r14, %rdi
testq %r14, %r14
jne 0x3eec3
movq $0x0, 0x88(%rbx)
movl $0x0, 0x19214(%rbx)
movl $0x88, %eax
andl 0x4(%rbx), %eax
movl 0xc(%rbx), %ecx
orl %ecx, %eax
movl %eax, 0x4(%rbx)
testb $0x4, %cl
je 0x3ef25
orl $0x40, %eax
movl %eax, 0x4(%rbx)
cmpq $0x10001, 0x6110(%rbx) # imm = 0x10001
jb 0x3ef25
movl $0x1b, 0x19214(%rbx)
movl $0x1b, %r14d
jmp 0x3f076
movl 0x4(%rbx), %eax
testb $0x3, %al
jne 0x3ef51
cmpl $-0x1, 0x60d4(%rbx)
je 0x3ef51
cmpq $0x0, 0x6110(%rbx)
sete %cl
testb $0x48, %al
sete %dl
andb %cl, %dl
movzbl %dl, %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x4(%rbx)
movl 0x4(%rbx), %r14d
movl %r14d, %ebp
andl $-0x9, %ebp
movl %ebp, 0x4(%rbx)
movl %r14d, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x3efa5
movl $0x18, %edi
callq 0x3280
testq %rax, %rax
je 0x3ef92
movq 0x90(%rbx), %rcx
movq %rcx, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax)
movq %rax, 0x90(%rbx)
jmp 0x3ef9c
movl $0x14, 0x19214(%rbx)
testq %rax, %rax
je 0x3f06f
testb $0x10, %r14b
jne 0x3efb4
movw $0x0, 0x191cc(%rbx)
btl $0x12, %r14d
jb 0x3efcb
cmpq $0x0, 0x38(%rbx)
jne 0x3efcb
orl $0x20000, %ebp          # imm = 0x20000
movl %ebp, 0x4(%rbx)
movl 0x4(%rbx), %eax
movl %eax, %ecx
notl %ecx
testl $0x280, %ecx            # imm = 0x280
jne 0x3efe6
andl $0xfffffe7f, %eax       # imm = 0xFFFFFE7F
orl $0x100, %eax            # imm = 0x100
jmp 0x3eff1
btl $0x8, %eax
jb 0x3eff4
andl $0xfffffcff, %eax       # imm = 0xFFFFFCFF
movl %eax, 0x4(%rbx)
testb $0x1, 0x5(%rbx)
je 0x3f002
movq %rbx, %rdi
callq 0x3ec6e
testb $0x3, 0x4(%rbx)
je 0x3f012
xorps %xmm0, %xmm0
movups %xmm0, 0x60f0(%rbx)
xorl %r14d, %r14d
movq %r14, 0x18598(%rbx)
movw %r14w, 0x1853a(%rbx)
movl %r14d, 0x5f40(%rbx)
movl %r14d, 0x6108(%rbx)
movq %r14, 0x18588(%rbx)
movq %rbx, %rdi
callq 0x3eda4
movq %rbx, %rdi
callq 0x3edff
movw %r14w, 0x18590(%rbx)
movq 0x6040(%rbx), %rax
testq %rax, %rax
je 0x3f076
movl 0x4(%rbx), %ecx
andl $0x3, %ecx
cmpl $0x2, %ecx
jne 0x3f076
movq %rbx, %rdi
callq *%rax
jmp 0x3f076
movl 0x19214(%rbx), %r14d
movl %r14d, %eax
popq %rbx
popq %r14
popq %rbp
retq