// File: /workspace/github_cpp_makefile_star2_O2/jstaursky[P]hutch/src/Sleigh/translate.cc
// Function: AddrSpaceManager::findAddJoin(std::vector<VarnodeData, std::allocator<VarnodeData>> const&, unsigned int)
JoinRecord *AddrSpaceManager::findAddJoin(const vector<VarnodeData> &pieces,uint4 logicalsize)

{ // Find a pre-existing split record, or create a new one corresponding to the input -pieces-
  // If -logicalsize- is 0, calculate logical size as sum of pieces
  if (pieces.size() == 0)
    throw LowlevelError("Cannot create a join without pieces");
  if ((pieces.size()==1)&&(logicalsize==0))
    throw LowlevelError("Cannot create a single piece join without a logical size");

  uint4 totalsize;
  if (logicalsize != 0) {
    if (pieces.size() != 1)
      throw LowlevelError("Cannot specify logical size for multiple piece join");
    totalsize = logicalsize;
  }
  else {
    totalsize = 0;
    for(int4 i=0;i<pieces.size();++i) // Calculate sum of the sizes of all pieces
      totalsize += pieces[i].size;
    if (totalsize == 0)
      throw LowlevelError("Cannot create a zero size join");
  }

  JoinRecord testnode;

  testnode.pieces = pieces;
  testnode.unified.size = totalsize;
  set<JoinRecord *,JoinRecordCompare>::const_iterator iter;
  iter = splitset.find(&testnode);
  if (iter != splitset.end())		// If already in the set
    return *iter;

  JoinRecord *newjoin = new JoinRecord();
  newjoin->pieces = pieces;
  
  uint4 roundsize = (totalsize + 15) & ~((uint4)0xf);	// Next biggest multiple of 16

  newjoin->unified.space = joinspace;
  newjoin->unified.offset = joinallocate;
  joinallocate += roundsize;
  newjoin->unified.size = totalsize;
  splitset.insert(newjoin);
  splitlist.push_back(newjoin);
  return splitlist.back();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rcx
movq 0x8(%rsi), %rsi
movq %rsi, %rax
subq %rcx, %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
subq %rcx, %rsi
je 0x5ae00
cmpq $0x18, %rsi
setne %dl
testl %r14d, %r14d
setne %dil
orb %dl, %dil
je 0x5ae4e
testl %r14d, %r14d
je 0x5acfd
cmpq $0x18, %rsi
je 0x5ad1c
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x2bf63(%rip), %rsi     # 0x86c24
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x541b7(%rip), %rsi     # 0xaeea0
movq 0x53f48(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5aee2
addq $0x10, %rcx
xorl %r14d, %r14d
subq $0x1, %rax
jb 0x5ad13
addl (%rcx), %r14d
addq $0x18, %rcx
jmp 0x5ad04
testl %r14d, %r14d
je 0x5ae99
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
movq %r13, %rdi
movq %r15, %rsi
callq 0x508b0
movl %r14d, 0x38(%rsp)
leaq 0xd8(%rbx), %r12
leaq 0x8(%rsp), %rsi
movq %r13, (%rsi)
movq %r12, %rdi
callq 0x4d0a0
leaq 0xe0(%rbx), %rcx
cmpq %rcx, %rax
je 0x5ad67
movq 0x20(%rax), %rbx
jmp 0x5ade4
pushq $0x30
popq %rdi
callq 0x4f5d0
movq %rax, %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %r15, %rsi
callq 0x508b0
leal 0xf(%r14), %eax
andl $-0x10, %eax
movq 0xb8(%rbx), %rcx
movq %rcx, 0x18(%r13)
movq 0xd0(%rbx), %rcx
movq %rcx, 0x20(%r13)
addq %rcx, %rax
movq %rax, 0xd0(%rbx)
movl %r14d, 0x28(%r13)
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x4e090
leaq 0x108(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4ef50
movq 0x110(%rbx), %rax
movq -0x8(%rax), %rbx
leaq 0x10(%rsp), %rdi
callq 0x4f8c0
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, %r14
leaq 0x2bdb5(%rip), %rsi     # 0x86bc7
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x54066(%rip), %rsi     # 0xaeea0
movq 0x53df7(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5aee2
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x2bd8b(%rip), %rsi     # 0x86beb
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x54018(%rip), %rsi     # 0xaeea0
movq 0x53da9(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5aee2
pushq $0x20
popq %rdi
callq 0x4e180
movq %rax, %r14
leaq 0x2bdad(%rip), %rsi     # 0x86c58
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x515e0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x4ddf0
xorl %ebp, %ebp
movq 0x53fcd(%rip), %rsi     # 0xaeea0
movq 0x53d5e(%rip), %rdx     # 0xaec38
movq %r14, %rdi
callq 0x51630
jmp 0x5aeee
jmp 0x5af02
jmp 0x5aeee
jmp 0x5af02
jmp 0x5aeee
jmp 0x5af02
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4e020
testb %bpl, %bpl
jne 0x5af05
jmp 0x5af22
movq %rax, %rbx
movq %r14, %rdi
callq 0x4ea60
jmp 0x5af22
jmp 0x5af15
jmp 0x5af15
jmp 0x5af15
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4f8c0
movq %rbx, %rdi
callq 0x518c0