// File: /workspace/github_cpp_makefile_star2_O1/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 %rsi, 0x28(%rsp)
movq (%rcx), %rax
movl 0x8(%rax), %edx
leal -0x3(%rdx), %ecx
cmpl $-0x2, %ecx
jb 0x4e21b
movq %r9, %r14
movq %rdi, %rbx
movq (%r9), %rcx
movl 0x8(%rcx), %esi
leal -0x3(%rsi), %edi
cmpl $-0x3, %edi
jbe 0x4e21b
movl %r8d, %r13d
cmpl $0x2, %edx
sete %dl
cmpl $0x2, %esi
sete %sil
orb %dl, %sil
jne 0x4e045
movq 0x28(%rsp), %rdx
movq 0xa0(%rdx), %rdx
cmpq %rdx, %rax
setne %al
cmpq %rdx, %rcx
setne %cl
movb $0x1, %r12b
testb %cl, %al
jne 0x4e048
xorl %r12d, %r12d
movq %r15, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl 0x80(%rsp), %ecx
callq 0x3fd50
testb %al, %al
je 0x4e123
movq (%r15), %rdx
movl 0x24(%rdx), %eax
testb %r12b, %r12b
je 0x4e0bd
testb $0x1, %al
jne 0x4e0d4
movq (%r14), %rdx
movq 0x8(%r14), %rcx
movl 0x80(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %r12
movq %r12, %rdi
movq %rbp, %rsi
callq *0x40(%rax)
movq (%r12), %rdi
movq 0x8(%r12), %r12
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4e0b6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40870
testq %r12, %r12
jne 0x4e0c5
jmp 0x4e123
testb $0x1, %al
jne 0x4e1fe
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rax
jmp 0x4e205
movq 0x8(%r15), %rcx
movl 0x80(%rsp), %eax
leal (%rax,%r13), %r8d
movq (%rbp), %rax
movq %rsp, %r12
movq %r12, %rdi
movq %rbp, %rsi
callq *0x40(%rax)
movq (%r12), %rdi
movq 0x8(%r12), %r12
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x4e113
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40870
testq %r12, %r12
je 0x4e123
movq (%r15), %rax
movq %rax, (%rbx)
jmp 0x4e201
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x4e158
movups %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x4e165
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x41460
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x4e195
movups %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x4e1a2
movq %rsp, %rdi
leaq 0x30(%rsp), %rdx
callq 0x41460
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 0x410a0
movups 0x18(%rax), %xmm0
movups %xmm0, (%rbx)
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4e209
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
jmp 0x4e209
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
movl $0x20, %edi
callq 0x3fb00
movq %rax, %rbx
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x31aa1(%rip), %rsi     # 0x7fcd9
leaq 0x31ac1(%rip), %rdx     # 0x7fd00
movq %rsp, %rdi
callq 0x3f8a0
movb $0x1, %bpl
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x54c4a(%rip), %rsi     # 0xa2ea8
movq 0x549d3(%rip), %rdx     # 0xa2c38
movq %rbx, %rdi
callq 0x41d60
jmp 0x4e2a1
jmp 0x4e2a1
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4e292
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x40870
jmp 0x4e292
movq %rax, %r14
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4e2ba
movq %rbx, %rdi
callq 0x40080
jmp 0x4e2ba
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x4e2ba
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
movq %r14, %rdi
callq 0x41f00