// File: /workspace/github_c_makefile_star2_O3/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 0x3f389
cmpq $0x0, (%r15)
je 0x3f389
movq %r10, %rax
orq 0x50(%rsp), %rax
je 0x3f389
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 0x3e889
testl %eax, %eax
jne 0x3f2ef
leaq 0x8(%rsp), %r9
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %r13d, %r8d
callq 0x3e9d4
testl %eax, %eax
je 0x3f3ea
movq 0x10(%rsp), %r8
testq %r8, %r8
jne 0x3f323
testl %ebp, %ebp
cmovgl %ebp, %eax
leaq 0x16538(%r14), %rbx
movq 0x20(%r14), %rsi
movq %rbx, %rdi
movl %eax, %edx
xorl %eax, %eax
callq 0x3360
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3a6c4
movq %rax, %r8
testb $0x2, 0x5(%r14)
je 0x3f3b1
leaq 0x12ef3(%rip), %rsi     # 0x52228
movq %r12, %rdi
movq %r8, %rbx
callq 0x3210
movq 0x68(%rsp), %rcx
movq %rbx, %r8
testl %eax, %eax
je 0x3f3b1
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x3f670
testl %eax, %eax
jne 0x3f3cc
leaq 0x12ec4(%rip), %rsi     # 0x52228
leaq 0x131a8(%rip), %rcx     # 0x52513
movq %r14, %rdi
xorl %edx, %edx
movq %rbx, %r8
callq 0x3f697
testl %eax, %eax
jne 0x3f3cc
movq %r14, %rdi
movq %r12, %rsi
callq 0x3f6ed
jmp 0x3f3c8
movq %r14, %rdi
movq %r12, %rsi
movl %ebp, %edx
movq %rbx, %rcx
movq %r15, %r8
pushq %r13
pushq 0x70(%rsp)
callq 0x3f4fb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1315b(%rip), %rcx     # 0x52513
movq %r14, %rdi
movq %r12, %rsi
xorl %edx, %edx
movq %r8, %rbx
callq 0x3f697
testl %eax, %eax
je 0x3f3d5
movl 0x19214(%r14), %ebp
jmp 0x3f3fa
movl 0x4(%r14), %eax
movq 0x8(%rsp), %r12
testb $0x8, %al
jne 0x3f402
movb $0x3, 0x21(%r12)
jmp 0x3f3f5
movl $0x14, 0x19214(%r14)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
jmp 0x3f3a6
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x3, 0x20(%r12)
je 0x3f3fa
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 0x3f7e5
testq %rax, %rax
je 0x3f49a
movq %rax, %r15
leaq 0x130c3(%rip), %rsi     # 0x52518
movl $0x4, %edx
movq %rbx, %rdi
callq 0x3080
testl %eax, %eax
jne 0x3f471
testb $0x2, 0x5(%r14)
jne 0x3f4aa
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 0x3f3fa
movl $0x14, 0x19214(%r14)
jmp 0x3f3fa
movq %rbx, %r13
movq %rbx, %rdi
callq 0x3110
leaq -0x1(%rax), %rsi
movq %r14, %rdi
callq 0x39272
testq %rax, %rax
movq 0x50(%rsp), %rcx
je 0x3f47a
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 0x3f476