// File: /workspace/github_cpp_makefile_star2_O3/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), %rax
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
subq %rax, %rcx
je 0x4db24
movq %rsi, %r15
movq %rdi, %rbx
cmpq $0x18, %rcx
setne %sil
testl %r14d, %r14d
setne %dil
orb %sil, %dil
je 0x4db7f
testl %r14d, %r14d
je 0x4d9c9
cmpq $0x18, %rcx
je 0x4d9ff
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x322b9(%rip), %rsi     # 0x7fc44
leaq 0x322e5(%rip), %rdx     # 0x7fc77
leaq 0x10(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x554f3(%rip), %rsi     # 0xa2ea8
movq 0x5527c(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d70
jmp 0x4dc2d
sarq $0x3, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
addq $0x10, %rax
xorl %r14d, %r14d
addl (%rax), %r14d
addq $0x18, %rax
decq %rcx
jne 0x4d9ea
testl %r14d, %r14d
je 0x4dbd7
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movq %r13, %rdi
movq %r15, %rsi
callq 0x41410
movl %r14d, 0x38(%rsp)
leaq 0xd8(%rbx), %r12
leaq 0x8(%rsp), %rsi
movq %r13, (%rsi)
movq %r12, %rdi
callq 0x3f080
leaq 0xe0(%rbx), %rcx
cmpq %rcx, %rax
je 0x4da50
movq 0x20(%rax), %rbx
jmp 0x4dafb
movl $0x30, %edi
callq 0x40810
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 0x41410
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 0x3fa80
movq 0x110(%rbx), %rsi
cmpq 0x118(%rbx), %rsi
je 0x4dadf
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
movq 0x110(%rbx), %rax
addq $0x8, %rax
movq %rax, 0x110(%rbx)
jmp 0x4daf7
leaq 0x108(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0x42190
movq 0x110(%rbx), %rax
movq -0x8(%rax), %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4db12
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40880
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, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x320a6(%rip), %rsi     # 0x7fbe7
leaq 0x320c2(%rip), %rdx     # 0x7fc0a
leaq 0x10(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x5533d(%rip), %rsi     # 0xa2ea8
movq 0x550c6(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d70
jmp 0x4dc2d
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x3206f(%rip), %rsi     # 0x7fc0b
leaq 0x320a0(%rip), %rdx     # 0x7fc43
leaq 0x10(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x552e2(%rip), %rsi     # 0xa2ea8
movq 0x5506b(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d70
jmp 0x4dc2d
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x32084(%rip), %rsi     # 0x7fc78
leaq 0x3209b(%rip), %rdx     # 0x7fc96
leaq 0x10(%rsp), %rdi
callq 0x3f8a0
movb $0x1, %bpl
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x3f890
xorl %ebp, %ebp
movq 0x5528a(%rip), %rsi     # 0xa2ea8
movq 0x55013(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d70
jmp 0x4dc39
jmp 0x4dc5a
jmp 0x4dc39
jmp 0x4dc5a
jmp 0x4dc39
jmp 0x4dc5a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x4dc53
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x40880
testb %bpl, %bpl
jne 0x4dc5d
jmp 0x4dc87
movq %rax, %rbx
movq %r14, %rdi
callq 0x40090
jmp 0x4dc87
jmp 0x4dc6d
jmp 0x4dc6d
jmp 0x4dc6d
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4dc87
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40880
movq %rbx, %rdi
callq 0x41f10
nop