// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rcx, %r15
movq %rdx, %rbp
movq (%rcx), %rax
movl 0x8(%rax), %edx
leal -0x3(%rdx), %ecx
cmpl $-0x2, %ecx
jb 0x5b304
movq %r9, %r14
movl %r8d, %r13d
movq %rdi, %rbx
movq (%r9), %r9
movl 0x8(%r9), %r8d
leal -0x3(%r8), %edi
cmpl $-0x3, %edi
jbe 0x5b304
movl 0x80(%rsp), %ecx
cmpl $0x2, %edx
sete %dl
cmpl $0x2, %r8d
sete %dil
orb %dl, %dil
jne 0x5b1ab
movq 0xa0(%rsi), %rdx
cmpq %rdx, %rax
setne %al
cmpq %rdx, %r9
setne %dl
movb $0x1, %r12b
testb %dl, %al
jne 0x5b1ae
xorl %r12d, %r12d
movq %rsi, 0x28(%rsp)
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x4e580
testb %al, %al
je 0x5b261
movq (%r15), %rdx
movl 0x24(%rdx), %eax
testb %r12b, %r12b
je 0x5b20e
testb $0x1, %al
jne 0x5b225
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movl 0x80(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %rdi
movq %rdi, %r12
movq %rbp, %rsi
callq *0x40(%rax)
movq %r12, %rdi
movq 0x8(%r12), %r12
callq 0x4e020
testq %r12, %r12
jne 0x5b216
jmp 0x5b261
testb $0x1, %al
jne 0x5b2e7
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
jmp 0x5b2ee
movq 0x8(%r15), %rcx
movl 0x80(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %rdi
movq %rdi, %r12
movq %rbp, %rsi
callq *0x40(%rax)
movq %r12, %rdi
movq 0x8(%r12), %r12
callq 0x4e020
testq %r12, %r12
je 0x5b261
movq (%r15), %rax
movq %rax, (%rbx)
jmp 0x5b2ea
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq 0x30(%rsp), %rsi
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
callq 0x4d0e0
leaq 0x30(%rsp), %rsi
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
andq $0x0, 0x10(%rsi)
movq %rsp, %rdi
callq 0x4d0e0
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 0x80(%rsp), %eax
movl %eax, 0x28(%rcx)
movq 0x28(%rsp), %rdi
xorl %edx, %edx
callq 0x50400
movups 0x18(%rax), %xmm0
movups %xmm0, (%rbx)
movq %rsp, %rdi
callq 0x4f8c0
jmp 0x5b2f2
movq %rdx, (%rbx)
movq 0x8(%r15), %rax
movq %rax, 0x8(%rbx)
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %rbx
leaq 0x2b9a3(%rip), %rsi     # 0x86cb9
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x53b66(%rip), %rsi     # 0xaeea0
movq 0x538f7(%rip), %rdx     # 0xaec38
movq %rbx, %rdi
callq 0x51630
movq %rax, %r14
movq %rsp, %rdi
callq 0x4e020
testb %bpl, %bpl
jne 0x5b35e
jmp 0x5b377
movq %rax, %r14
movq %rbx, %rdi
callq 0x4ea60
jmp 0x5b377
jmp 0x5b36c
jmp 0x5b36c
movq %rax, %r14
movq %rsp, %rdi
callq 0x4f8c0
movq %r14, %rdi
callq 0x518c0
nop