// File: /workspace/github_cpp_makefile_star2_O1/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 (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rcx, %rdx
subq %rax, %rdx
movq %rcx, %rsi
subq %rax, %rsi
je 0x4dbbd
movq %rdi, %rbx
cmpq $0x18, %rsi
setne %dil
testl %r14d, %r14d
setne %r8b
orb %dil, %r8b
je 0x4dc18
testl %r14d, %r14d
je 0x4da62
cmpq $0x18, %rsi
je 0x4daa2
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x32220(%rip), %rsi     # 0x7fc44
leaq 0x3224c(%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 0x5545a(%rip), %rsi     # 0xa2ea8
movq 0x551e3(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d60
jmp 0x4dcc6
cmpq %rax, %rcx
je 0x4da96
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 0x4da88
jmp 0x4da99
xorl %r14d, %r14d
testl %r14d, %r14d
je 0x4dc70
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
movaps %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movq %r13, %rdi
movq %r15, %rsi
callq 0x41400
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 0x4daf3
movq 0x20(%rax), %rbx
jmp 0x4db94
movl $0x30, %edi
callq 0x40800
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 0x41400
leal 0xf(%r14), %eax
andl $-0x10, %eax
movq 0xb8(%rbx), %rcx
leaq 0x8(%rsp), %rsi
movq (%rsi), %rdx
movq %rcx, 0x18(%rdx)
movq 0xd0(%rbx), %rcx
movq %rcx, 0x20(%rdx)
addq %rcx, %rax
movq %rax, 0xd0(%rbx)
movl %r14d, 0x28(%rdx)
movq %r12, %rdi
callq 0x3fa80
movq 0x110(%rbx), %rsi
cmpq 0x118(%rbx), %rsi
je 0x4db78
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x110(%rbx)
jmp 0x4db89
leaq 0x108(%rbx), %rdi
leaq 0x8(%rsp), %rdx
callq 0x42180
movq 0x110(%rbx), %rax
movq -0x8(%rax), %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4dbab
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
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 0x3200d(%rip), %rsi     # 0x7fbe7
leaq 0x32029(%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 0x552a4(%rip), %rsi     # 0xa2ea8
movq 0x5502d(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d60
jmp 0x4dcc6
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x31fd6(%rip), %rsi     # 0x7fc0b
leaq 0x32007(%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 0x55249(%rip), %rsi     # 0xa2ea8
movq 0x54fd2(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d60
jmp 0x4dcc6
movl $0x20, %edi
callq 0x3fb00
movq %rax, %r14
leaq 0x20(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x31feb(%rip), %rsi     # 0x7fc78
leaq 0x32002(%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 0x551f1(%rip), %rsi     # 0xa2ea8
movq 0x54f7a(%rip), %rdx     # 0xa2c38
movq %r14, %rdi
callq 0x41d60
jmp 0x4dcd2
jmp 0x4dcee
jmp 0x4dcd2
jmp 0x4dcee
jmp 0x4dcd2
jmp 0x4dcee
movq %rax, %rbx
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x4dcf4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x40870
jmp 0x4dcf4
movq %rax, %rbx
movb $0x1, %bpl
testb %bpl, %bpl
je 0x4dd23
movq %r14, %rdi
callq 0x40080
jmp 0x4dd23
jmp 0x4dd09
jmp 0x4dd09
jmp 0x4dd09
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4dd23
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x40870
movq %rbx, %rdi
callq 0x41f00
nop