// File: jstaursky[P]hutch/src/Sleigh/space.cc
// Function: JoinSpace::restoreXmlAttributes(Element const*, unsigned int&) const
uintb JoinSpace::restoreXmlAttributes(const Element *el,uint4 &size) const

{
  vector<VarnodeData> pieces;
  int4 numAttribs = el->getNumAttributes();
  uint4 sizesum = 0;
  uint4 logicalsize = 0;
  for(int4 i=0;i<numAttribs;++i) {
    string attrName = el->getAttributeName(i);
    if (0!=attrName.compare(0,5,"piece")) {
      if (attrName == "logicalsize") {
	istringstream s3(el->getAttributeValue(i));
	s3.unsetf(ios::dec | ios::hex | ios::oct);
	s3 >> logicalsize;
      }
      continue;
    }
    int4 pos = (int4)(attrName[5] - '1');
    while(pieces.size() <= pos)
      pieces.push_back(VarnodeData());
    VarnodeData &vdat( pieces[pos] );

    string attrVal = el->getAttributeValue(i);
    string::size_type offpos = attrVal.find(':');
    if (offpos == string::npos) {
      const Translate *trans = getTrans();
      const VarnodeData &point(trans->getRegister(attrVal));
      vdat = point;
    }
    else {
      string::size_type szpos = attrVal.find(':',offpos+1);
      if (szpos==string::npos)
	throw LowlevelError("join address piece attribute is malformed");
      string spcname = attrVal.substr(0,offpos);
      vdat.space = getManager()->getSpaceByName(spcname);
      istringstream s1(attrVal.substr(offpos+1,szpos));
      s1.unsetf(ios::dec | ios::hex | ios::oct);
      s1 >> vdat.offset;
      istringstream s2(attrVal.substr(szpos+1));
      s2.unsetf(ios::dec | ios::hex | ios::oct);
      s2 >> vdat.size;
    }
    sizesum += vdat.size;
  }
  JoinRecord *rec = getManager()->findAddJoin(pieces,logicalsize);
  size = rec->getUnified().size;
  return rec->getUnified().offset;
}

// Assembly:
subq $0x6c8, %rsp            # imm = 0x6C8
movq %rdi, 0x6c0(%rsp)
movq %rsi, 0x6b8(%rsp)
movq %rdx, 0x6b0(%rsp)
movq 0x6c0(%rsp), %rax
movq %rax, 0xc8(%rsp)
leaq 0x698(%rsp), %rdi
callq 0xdc410
movq 0x6b8(%rsp), %rdi
callq 0xd2b80
movl %eax, 0xd4(%rsp)
jmp 0xf8152
movl 0xd4(%rsp), %eax
movl %eax, 0x694(%rsp)
movl $0x0, 0x680(%rsp)
movl $0x0, 0x67c(%rsp)
movl $0x0, 0x678(%rsp)
movl 0x678(%rsp), %eax
cmpl 0x694(%rsp), %eax
jge 0xf893e
movq 0x6b8(%rsp), %rdi
movl 0x678(%rsp), %esi
callq 0xd5520
movq %rax, 0xc0(%rsp)
jmp 0xf81b3
movq 0xc0(%rsp), %rsi
leaq 0x658(%rsp), %rdi
callq 0xd2230
jmp 0xf81ca
leaq 0x8f6ab(%rip), %rcx     # 0x18787c
xorl %eax, %eax
movl %eax, %esi
leaq 0x658(%rsp), %rdi
movl $0x5, %edx
callq 0xdbbb0
movl %eax, 0xbc(%rsp)
jmp 0xf81f0
movl 0xbc(%rsp), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0xf835a
leaq 0x8f67e(%rip), %rsi     # 0x187886
leaq 0x658(%rsp), %rdi
callq 0xe30f0
movb %al, 0xbb(%rsp)
jmp 0xf821e
movb 0xbb(%rsp), %al
testb $0x1, %al
jne 0xf822e
jmp 0xf834a
movq 0x6b8(%rsp), %rdi
movl 0x678(%rsp), %esi
callq 0xd9670
movq %rax, 0xb0(%rsp)
jmp 0xf824c
movq 0xb0(%rsp), %rsi
leaq 0x4d8(%rsp), %rdi
movl $0x8, %edx
callq 0xdfcc0
jmp 0xf8268
movq 0x4d8(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x4d8(%rsp,%rax), %rax
movq %rax, 0xa0(%rsp)
movl $0x2, %edi
movl $0x8, %esi
callq 0xe0e70
movl %eax, 0xac(%rsp)
jmp 0xf829c
movl 0xac(%rsp), %edi
movl $0x40, %esi
callq 0xe0e70
movl %eax, 0x9c(%rsp)
jmp 0xf82b6
movl 0x9c(%rsp), %esi
movq 0xa0(%rsp), %rdi
callq 0xda6e0
jmp 0xf82cc
leaq 0x4d8(%rsp), %rdi
leaq 0x67c(%rsp), %rsi
callq 0xceae0
jmp 0xf82e3
leaq 0x4d8(%rsp), %rdi
callq 0xd25a0
jmp 0xf834a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf89ec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf892c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
leaq 0x4d8(%rsp), %rdi
callq 0xd25a0
jmp 0xf892c
movl $0x4, 0x4d4(%rsp)
jmp 0xf88eb
leaq 0x658(%rsp), %rdi
movl $0x5, %esi
callq 0xe2f50
movq %rax, 0x90(%rsp)
jmp 0xf8376
movq 0x90(%rsp), %rax
movsbl (%rax), %eax
subl $0x31, %eax
movl %eax, 0x4d0(%rsp)
leaq 0x698(%rsp), %rdi
callq 0xdf340
movslq 0x4d0(%rsp), %rcx
cmpq %rcx, %rax
ja 0xf83d5
xorps %xmm0, %xmm0
movaps %xmm0, 0x4b0(%rsp)
movq $0x0, 0x4c0(%rsp)
leaq 0x698(%rsp), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0xde8e0
jmp 0xf83d3
jmp 0xf838b
movslq 0x4d0(%rsp), %rsi
leaq 0x698(%rsp), %rdi
callq 0xdbe50
movq %rax, 0x4a8(%rsp)
movq 0x6b8(%rsp), %rdi
movl 0x678(%rsp), %esi
callq 0xd9670
movq %rax, 0x88(%rsp)
jmp 0xf8410
movq 0x88(%rsp), %rsi
leaq 0x488(%rsp), %rdi
callq 0xd2230
jmp 0xf8427
leaq 0x488(%rsp), %rdi
movl $0x3a, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0xdb750
movq %rax, 0x480(%rsp)
cmpq $-0x1, 0x480(%rsp)
jne 0xf84ec
movq 0xc8(%rsp), %rdi
callq 0xdf7e0
movq %rax, 0x80(%rsp)
jmp 0xf846b
movq 0x80(%rsp), %rax
movq %rax, 0x478(%rsp)
movq 0x478(%rsp), %rdi
movq (%rdi), %rax
movq 0x38(%rax), %rax
leaq 0x488(%rsp), %rsi
callq *%rax
movq %rax, 0x78(%rsp)
jmp 0xf849b
movq 0x78(%rsp), %rax
movq %rax, 0x470(%rsp)
movq 0x470(%rsp), %rcx
movq 0x4a8(%rsp), %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
jmp 0xf88ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf891f
movq 0x480(%rsp), %rdx
addq $0x1, %rdx
leaq 0x488(%rsp), %rdi
movl $0x3a, %esi
callq 0xdb750
movq %rax, 0x468(%rsp)
cmpq $-0x1, 0x468(%rsp)
jne 0xf85fd
movb $0x1, 0x446(%rsp)
movl $0x20, %edi
callq 0xd2b40
movq %rax, 0x68(%rsp)
leaq 0x447(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xe0c80
movq 0x70(%rsp), %rdx
leaq 0x8f375(%rip), %rsi     # 0x1878cb
leaq 0x448(%rsp), %rdi
callq 0xe00a0
jmp 0xf8565
movq 0x68(%rsp), %rdi
leaq 0x448(%rsp), %rsi
callq 0xd1ae0
jmp 0xf8579
movq 0x68(%rsp), %rdi
movb $0x0, 0x446(%rsp)
movq 0xcf903(%rip), %rsi     # 0x1c7e90
movq 0xcf63c(%rip), %rdx     # 0x1c7bd0
callq 0xe01f0
jmp 0xf8a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf85d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
leaq 0x448(%rsp), %rdi
callq 0xd4550
leaq 0x447(%rsp), %rdi
callq 0xd8ec0
testb $0x1, 0x446(%rsp)
jne 0xf85ee
jmp 0xf85f8
movq 0x68(%rsp), %rdi
callq 0xd5400
jmp 0xf891f
movq 0x480(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x420(%rsp), %rdi
leaq 0x488(%rsp), %rsi
callq 0xd8920
jmp 0xf8620
movq 0xc8(%rsp), %rdi
callq 0xd6150
movq %rax, 0x60(%rsp)
jmp 0xf8634
movq 0x60(%rsp), %rdi
leaq 0x420(%rsp), %rsi
callq 0xe10d0
movq %rax, 0x58(%rsp)
jmp 0xf864d
movq 0x58(%rsp), %rcx
movq 0x4a8(%rsp), %rax
movq %rcx, (%rax)
movq 0x480(%rsp), %rdx
incq %rdx
movq 0x468(%rsp), %rcx
leaq 0x280(%rsp), %rdi
leaq 0x488(%rsp), %rsi
callq 0xd8920
jmp 0xf8687
leaq 0x2a0(%rsp), %rdi
leaq 0x280(%rsp), %rsi
movl $0x8, %edx
callq 0xdfcc0
jmp 0xf86a3
leaq 0x280(%rsp), %rdi
callq 0xd4550
movq 0x2a0(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x2a0(%rsp,%rax), %rax
movq %rax, 0x48(%rsp)
movl $0x2, %edi
movl $0x8, %esi
callq 0xe0e70
movl %eax, 0x54(%rsp)
jmp 0xf86de
movl 0x54(%rsp), %edi
movl $0x40, %esi
callq 0xe0e70
movl %eax, 0x44(%rsp)
jmp 0xf86f2
movl 0x44(%rsp), %esi
movq 0x48(%rsp), %rdi
callq 0xda6e0
jmp 0xf8702
movq 0x4a8(%rsp), %rsi
addq $0x8, %rsi
leaq 0x2a0(%rsp), %rdi
callq 0xdcd70
jmp 0xf871d
movq 0x468(%rsp), %rdx
incq %rdx
leaq 0xe0(%rsp), %rdi
leaq 0x488(%rsp), %rsi
movq $-0x1, %rcx
callq 0xd8920
jmp 0xf8746
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
movl $0x8, %edx
callq 0xdfcc0
jmp 0xf8762
leaq 0xe0(%rsp), %rdi
callq 0xd4550
movq 0x100(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x100(%rsp,%rax), %rax
movq %rax, 0x38(%rsp)
movl $0x2, %edi
movl $0x8, %esi
callq 0xe0e70
movl %eax, 0x40(%rsp)
jmp 0xf879d
movl 0x40(%rsp), %edi
movl $0x40, %esi
callq 0xe0e70
movl %eax, 0x34(%rsp)
jmp 0xf87b1
movl 0x34(%rsp), %esi
movq 0x38(%rsp), %rdi
callq 0xda6e0
jmp 0xf87c1
movq 0x4a8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x100(%rsp), %rdi
callq 0xceae0
jmp 0xf87dc
leaq 0x100(%rsp), %rdi
callq 0xd25a0
leaq 0x2a0(%rsp), %rdi
callq 0xd25a0
leaq 0x420(%rsp), %rdi
callq 0xd4550
jmp 0xf88ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf88ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
leaq 0x280(%rsp), %rdi
callq 0xd4550
jmp 0xf88ab
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
jmp 0xf889e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0xd4550
jmp 0xf889e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x688(%rsp)
movl %eax, 0x684(%rsp)
leaq 0x100(%rsp), %rdi
callq 0xd25a0
leaq 0x2a0(%rsp), %rdi
callq 0xd25a0
leaq 0x420(%rsp), %rdi
callq 0xd4550
jmp 0xf891f
movq 0x4a8(%rsp), %rax
movl 0x10(%rax), %eax
addl 0x680(%rsp), %eax
movl %eax, 0x680(%rsp)
leaq 0x488(%rsp), %rdi
callq 0xd4550
movl $0x0, 0x4d4(%rsp)
leaq 0x658(%rsp), %rdi
callq 0xd4550
movl 0x4d4(%rsp), %eax
testl %eax, %eax
je 0xf8907
jmp 0xf8905
jmp 0xf8909
jmp 0xf8909
movl 0x678(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x678(%rsp)
jmp 0xf8181
leaq 0x488(%rsp), %rdi
callq 0xd4550
leaq 0x658(%rsp), %rdi
callq 0xd4550
jmp 0xf89ec
movq 0xc8(%rsp), %rdi
callq 0xd6150
movq %rax, 0x28(%rsp)
jmp 0xf8952
movq 0x28(%rsp), %rdi
movl 0x67c(%rsp), %edx
leaq 0x698(%rsp), %rsi
callq 0xdbc00
movq %rax, 0x20(%rsp)
jmp 0xf8972
movq 0x20(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xd8(%rsp), %rdi
callq 0xd20e0
movq %rax, 0x18(%rsp)
jmp 0xf8993
movq 0x18(%rsp), %rax
movl 0x10(%rax), %ecx
movq 0x6b0(%rsp), %rax
movl %ecx, (%rax)
movq 0xd8(%rsp), %rdi
callq 0xd20e0
movq %rax, 0x10(%rsp)
jmp 0xf89b9
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x8(%rsp)
movl $0x1, 0x4d4(%rsp)
leaq 0x698(%rsp), %rdi
callq 0xdc1e0
movq 0x8(%rsp), %rax
addq $0x6c8, %rsp            # imm = 0x6C8
retq
leaq 0x698(%rsp), %rdi
callq 0xdc1e0
movq 0x688(%rsp), %rdi
callq 0xe0be0
nopw %cs:(%rax,%rax)