// File: /workspace/github_cpp_makefile_star2_O3/jstaursky[P]hutch/src/Sleigh/translate.cc
// Function: AddrSpaceManager::constructJoinAddress(Translate const*, Address const&, int, Address const&, int)
Address AddrSpaceManager::constructJoinAddress(const Translate *translate,
					       const Address &hiaddr,int4 hisz,
					       const Address &loaddr,int4 losz)
{
  spacetype hitp = hiaddr.getSpace()->getType();
  spacetype lotp = loaddr.getSpace()->getType();
  bool usejoinspace = true;
  if (((hitp != IPTR_SPACEBASE)&&(hitp != IPTR_PROCESSOR))||
      ((lotp != IPTR_SPACEBASE)&&(lotp != IPTR_PROCESSOR)))
    throw LowlevelError("Trying to join in appropriate locations");
  if ((hitp == IPTR_SPACEBASE)||(lotp == IPTR_SPACEBASE)||
      (hiaddr.getSpace() == getDefaultSpace())||
      (loaddr.getSpace() == getDefaultSpace()))
    usejoinspace = false;
  if (hiaddr.isContiguous(hisz,loaddr,losz)) { // If we are contiguous
    if (!usejoinspace) { // and in a mappable space, just return the earliest address
      if (hiaddr.isBigEndian())
	return hiaddr;
      return loaddr;
    }
    else {			// If we are in a non-mappable (register) space, check to see if a parent register exists
      if (hiaddr.isBigEndian()) {
	if (translate->getRegisterName(hiaddr.getSpace(),hiaddr.getOffset(),(hisz+losz)).size() != 0)
	  return hiaddr;
      }
      else {
	if (translate->getRegisterName(loaddr.getSpace(),loaddr.getOffset(),(hisz+losz)).size() != 0)
	  return loaddr;
      }
    }
  }
  // Otherwise construct a formal JoinRecord
  vector<VarnodeData> pieces;
  pieces.push_back(VarnodeData());
  pieces.push_back(VarnodeData());
  pieces[0].space = hiaddr.getSpace();
  pieces[0].offset = hiaddr.getOffset();
  pieces[0].size = hisz;
  pieces[1].space = loaddr.getSpace();
  pieces[1].offset = loaddr.getOffset();
  pieces[1].size = losz;
  JoinRecord *join = findAddJoin(pieces,0);
  return join->getUnified().getAddr();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %r15
movq %rdx, %rbp
movq (%rcx), %rax
movl 0x8(%rax), %edx
leal -0x3(%rdx), %ecx
cmpl $-0x2, %ecx
jb 0x4e11f
movq %r9, %r14
movq %rsi, %r12
movq %rdi, %rbx
movq (%r9), %rcx
movl 0x8(%rcx), %esi
leal -0x3(%rsi), %edi
cmpl $-0x3, %edi
jbe 0x4e11f
movl %r8d, %r13d
cmpl $0x2, %edx
sete %dl
cmpl $0x2, %esi
sete %sil
orb %dl, %sil
jne 0x4df6a
movq 0xa0(%r12), %rdx
cmpq %rdx, %rax
sete %al
cmpq %rdx, %rcx
sete %cl
orb %al, %cl
je 0x4dfa0
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl 0x70(%rsp), %ecx
callq 0x3fd50
testb %al, %al
je 0x4e059
movq (%r15), %rax
testb $0x1, 0x24(%rax)
jne 0x4e049
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
jmp 0x4e050
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl 0x70(%rsp), %ecx
callq 0x3fd50
testb %al, %al
je 0x4e059
movq (%r15), %rdx
testb $0x1, 0x24(%rdx)
jne 0x4e007
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movl 0x70(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %rdi
movq %rbp, %rsi
callq *0x40(%rax)
movq %rsp, %rax
movq (%rax), %rdi
movq 0x8(%rax), %rbp
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4e000
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40880
testq %rbp, %rbp
jne 0x4df91
jmp 0x4e059
movq 0x8(%r15), %rcx
movl 0x70(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %rdi
movq %rbp, %rsi
callq *0x40(%rax)
movq %rsp, %rax
movq (%rax), %rdi
movq 0x8(%rax), %rbp
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4e041
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40880
testq %rbp, %rbp
je 0x4e059
movq (%r15), %rax
movq %rax, (%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rbx)
jmp 0x4e10d
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
xorl %eax, %eax
movq %rax, 0x10(%rdi)
leaq 0x20(%rsp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
xorl %esi, %esi
callq 0x41470
movq 0x8(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
cmpq 0x10(%rsp), %rsi
je 0x4e0ab
movups %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x4e0b8
movq %rsp, %rdi
leaq 0x20(%rsp), %rdx
callq 0x41470
movq (%r15), %rax
movq %rsp, %rsi
movq (%rsi), %rcx
movq %rax, (%rcx)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rcx)
movl %r13d, 0x10(%rcx)
movq (%r14), %rax
movq %rax, 0x18(%rcx)
movq 0x8(%r14), %rax
movq %rax, 0x20(%rcx)
movl 0x70(%rsp), %eax
movl %eax, 0x28(%rcx)
movq %r12, %rdi
xorl %edx, %edx
callq 0x410b0
movups 0x18(%rax), %xmm0
movups %xmm0, (%rbx)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4e10d
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x40880
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x31b9d(%rip), %rsi     # 0x7fcd9
leaq 0x31bbd(%rip), %rdx     # 0x7fd00
movq %rsp, %rdi
callq 0x3f8a0
movb $0x1, %bpl
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x54d46(%rip), %rsi     # 0xa2ea8
movq 0x54acf(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d70
jmp 0x4e1a2
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4e18c
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40880
testb %bpl, %bpl
jne 0x4e196
jmp 0x4e1bb
movq %rax, %r14
movq %rbx, %rdi
callq 0x40090
jmp 0x4e1bb
jmp 0x4e1a2
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4e1bb
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x40880
movq %r14, %rdi
callq 0x41f10
nop