// File: /workspace/github_c_makefile_star2_O2/loversmile[P]sugarcrm/sugar_stdsoap2.c
// Function: soap_attachment
SOAP_FMAC2
soap_attachment(struct soap *soap, const char *tag, int id, const void *p, const struct soap_array *a, const char *aid, const char *atype, const char *aoptions, int n, const char *type, int t) 
{
#ifndef WITH_NOIDREF
  struct soap_plist *pp;
  int i;
  if (!p || !a->__ptr || (!aid && !atype))
    return soap_element_id(soap, tag, id, p, a, n, type, t);
  DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Attachment tag='%s' id='%s' (%d) type='%s'\n", tag, aid?aid:SOAP_STR_EOS, id, atype?atype:SOAP_STR_EOS));
  i = soap_array_pointer_lookup(soap, p, a, n, t, &pp);
  if (!i)
  { i = soap_pointer_enter(soap, p, a, n, t, &pp);
    if (!i)
    { soap->error = SOAP_EOM;
      return -1;
    }
  }
  if (id <= 0)
    id = i;
  if (!aid)
  { sprintf(soap->tmpbuf, soap->dime_id_format, id);
    aid = soap_strdup(soap, soap->tmpbuf);
  }
  /* Add MTOM xop:Include element when necessary */
  /* TODO: this code to be obsoleted with new import/xop.h conventions */
  if ((soap->mode & SOAP_ENC_MTOM) && strcmp(tag, "xop:Include"))
  { if (soap_element_begin_out(soap, tag, 0, type)
     || soap_element_href(soap, "xop:Include", 0, "href", aid)
     || soap_element_end_out(soap, tag))
      return soap->error;
  }
  else if (soap_element_href(soap, tag, 0, "href", aid))
    return soap->error;
  if (soap->mode & SOAP_IO_LENGTH)
  { if (pp->mark1 != 3)
    { struct soap_multipart *content;
      if (soap->mode & SOAP_ENC_MTOM)
        content = soap_new_multipart(soap, &soap->mime.first, &soap->mime.last, (char*)a->__ptr, a->__size);
      else
        content = soap_new_multipart(soap, &soap->dime.first, &soap->dime.last, (char*)a->__ptr, a->__size);
      if (!content)
      { soap->error = SOAP_EOM;
        return -1;
      }
      if (!strncmp(aid, "cid:", 4)) /* RFC 2111 */
      { if (soap->mode & SOAP_ENC_MTOM)
        { char *s = (char*)soap_malloc(soap, strlen(aid) - 1);
          if (s)
          { *s = '<';
            strcpy(s + 1, aid + 4);
            strcat(s, ">");
            content->id = s;
          }
        }
        else
          content->id = aid + 4;
      }
      else
        content->id = aid;
      content->type = atype;
      content->options = aoptions;
      content->encoding = SOAP_MIME_BINARY;
      pp->mark1 = 3;
    }
  }
  else
    pp->mark2 = 3;
#endif
  return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r10
movq %r8, %r15
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r14
movl 0x70(%rsp), %r13d
movl 0x60(%rsp), %r9d
testq %rcx, %rcx
je 0x3b78a
cmpq $0x0, (%r15)
je 0x3b78a
movq %r10, %rax
orq 0x50(%rsp), %rax
je 0x3b78a
movq %r10, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %r9d, %ecx
movl %r13d, %r8d
movq %rax, %r9
callq 0x3ad91
testl %eax, %eax
jne 0x3b6f0
leaq 0x8(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %r13d, %r8d
callq 0x3aed6
testl %eax, %eax
je 0x3b7eb
movq 0x10(%rsp), %r8
testq %r8, %r8
jne 0x3b724
testl %ebp, %ebp
cmovgl %ebp, %eax
leaq 0x16538(%r14), %rbx
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x3370
movq %r14, %rdi
movq %rbx, %rsi
callq 0x37284
movq %rax, %r8
testb $0x2, 0x5(%r14)
je 0x3b7b2
leaq 0x11af2(%rip), %rsi     # 0x4d228
movq %r12, %rdi
movq %r8, %rbx
callq 0x3210
movq 0x68(%rsp), %rcx
movq %rbx, %r8
testl %eax, %eax
je 0x3b7b2
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3b9c9
testl %eax, %eax
jne 0x3b7cd
leaq 0x11ac3(%rip), %rsi     # 0x4d228
leaq 0x11da7(%rip), %rcx     # 0x4d513
movq %r14, %rdi
xorl %edx, %edx
movq %rbx, %r8
callq 0x3b9f0
testl %eax, %eax
jne 0x3b7cd
movq %r14, %rdi
movq %r12, %rsi
callq 0x3ba46
jmp 0x3b7c9
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movq %r15, %r8
pushq %r13
pushq 0x70(%rsp)
callq 0x3b8f6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11d5a(%rip), %rcx     # 0x4d513
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r8, %rbx
callq 0x3b9f0
testl %eax, %eax
je 0x3b7d6
movl 0x19214(%r14), %ebp
jmp 0x3b7f9
movl 0x4(%r14), %eax
movq 0x8(%rsp), %r12
testb $0x8, %al
jne 0x3b801
movb $0x3, 0x21(%r12)
jmp 0x3b7f6
movl $0x14, 0x19214(%r14)
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x18, %rsp
jmp 0x3b7a7
pushq $-0x1
popq %rbp
cmpb $0x3, 0x20(%r12)
je 0x3b7f9
leaq 0x192a0(%r14), %rsi
leaq 0x19278(%r14), %rdi
leaq 0x192a8(%r14), %r9
leaq 0x19280(%r14), %rdx
btl $0x9, %eax
movq (%r15), %rcx
movslq 0x8(%r15), %r8
cmovaeq %rdi, %rsi
cmovbq %r9, %rdx
movq %r14, %rdi
callq 0x3bb26
testq %rax, %rax
je 0x3b895
movq %rax, %r15
leaq 0x11cc6(%rip), %rsi     # 0x4d518
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x3080
testl %eax, %eax
jne 0x3b86c
testb $0x2, 0x5(%r14)
jne 0x3b8a5
addq $0x4, %rbx
movq 0x50(%rsp), %rcx
movq %rbx, 0x18(%r15)
movq %rcx, 0x20(%r15)
movq 0x58(%rsp), %rax
movq %rax, 0x28(%r15)
movl $0x3, 0x30(%r15)
movb $0x3, 0x20(%r12)
jmp 0x3b7f9
movl $0x14, 0x19214(%r14)
jmp 0x3b7f9
movq %rbx, %r13
movq %rbx, %rdi
callq 0x3110
leaq -0x1(%rax), %rsi
movq %r14, %rdi
callq 0x35f17
testq %rax, %rax
movq 0x50(%rsp), %rcx
je 0x3b875
movq %rax, %rbx
movb $0x3c, (%rax)
movq %rax, %rdi
incq %rdi
addq $0x4, %r13
movq %r13, %rsi
callq 0x3090
movq %rbx, %rdi
callq 0x3110
movq 0x50(%rsp), %rcx
movw $0x3e, (%rbx,%rax)
jmp 0x3b871