// File: /workspace/github_cpp_makefile_star2_O1/CK7[P]abawaca/src/abawaca-build.cpp
// Function: Links::add_pair(std::shared_ptr<Bio::ReadMapping>, std::shared_ptr<Bio::ReadMapping>)
void Links::add_pair(Bio::ReadMappingPtr mapping1, Bio::ReadMappingPtr mapping2)
{
	auto scafit1 = mapping1->unmapped()? scafs.end() : scafs.find(mapping1->ref_name());
	auto scafit2 = mapping2->unmapped()? scafs.end() : scafs.find(mapping2->ref_name());

	// Either both are unmapped or both are mapped to the same sequence
	if((scafit1 == scafs.end()) && (scafit2 == scafs.end()))
		return;

	size_t end1 = 0;
	if(scafit1 != scafs.end()) {
		if((mapping1->ref_pos() < this->insert_size) && (mapping1->direction() == Bio::ReadMapping::reverse))
			end1 = 5;
		else if((mapping1->ref_pos() > scafit1->second->get_seq().size()-this->insert_size) && (mapping1->direction() == Bio::ReadMapping::forward))
			end1 = 3;
	}

	size_t end2 = 0;
	if(scafit2 != scafs.end()) {
		if((mapping2->ref_pos() < this->insert_size) && (mapping2->direction() == Bio::ReadMapping::reverse))
			end2 = 5;
		else if((mapping2->ref_pos() > scafit2->second->get_seq().size()-this->insert_size) && (mapping2->direction() == Bio::ReadMapping::forward))
			end2 = 3;
	}

	// If both reads fall into the same read this is only interesting if they connect opposite ends
	if((scafit1 == scafit2) && ((end1 == end2) || (end1 == 0) || (end2 == 0)))
		return;

	// None of the reads is mapped to the ends
	if((end1 == 0) && (end2 == 0))
		return;

	Links::Side	side1((end1 != 0)? scafit1->first : "", end1), side2((end2 != 0)? scafit2->first : "", end2);
	if((end1 != 0) && (links.find(side1) == links.end())) {
		links.insert(pair<Links::Side, map<Links::Side, Links::Link*> >(side1, map<Links::Side, Links::Link*>()));
	}
	if((end2 != 0) && (links.find(side2) == links.end())) {
		links.insert(pair<Links::Side, map<Links::Side, Links::Link*> >(side2, map<Links::Side, Links::Link*>()));
	}

	auto		it = (end1 == 0)? links.find(side2) : links.find(side1);
	auto		itm = (end1 == 0)? it->second.find(side1) : it->second.find(side2);

	if(itm == it->second.end()) {
		Links::Link* link = new Links::Link(side1, side2);
		if(end1 != 0) {
			it = links.find(side1);
			it->second.insert(pair<Links::Side, Links::Link*>(side2, link));
			itm = it->second.find(side2);
		}
		if(end2 != 0) {
			it = links.find(side2);
			it->second.insert(pair<Links::Side, Links::Link*>(side1, link));
			itm = it->second.find(side1);
		}
	}
	itm->second->count++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movq (%rsi), %rsi
testb $0x4, 0x28(%rsi)
movq 0x38(%rdi), %r14
jne 0x95a9
addq $0x30, %rsi
movq %r14, %rdi
callq 0xdc4c
movq %rax, %r14
jmp 0x95ad
addq $0x8, %r14
movq (%r12), %rsi
testb $0x4, 0x28(%rsi)
movq 0x38(%rbx), %r15
jne 0x95cc
addq $0x30, %rsi
movq %r15, %rdi
callq 0xdc4c
movq %rax, %r15
jmp 0x95d0
addq $0x8, %r15
movq 0x38(%rbx), %rax
addq $0x8, %rax
movq %r14, %rcx
xorq %rax, %rcx
movq %r15, %rdx
xorq %rax, %rdx
orq %rcx, %rdx
je 0x9bb5
movb $0x1, %cl
movl %ecx, -0x30(%rbp)
cmpq %rax, %r14
je 0x963a
movq (%r13), %rcx
movq 0x50(%rcx), %rdx
movq (%rbx), %rsi
cmpq %rsi, %rdx
jae 0x960d
testb $0x10, 0x28(%rcx)
jne 0x9644
movq 0x40(%r14), %rdi
movq 0x30(%rdi), %rdi
subq %rsi, %rdi
cmpq %rdi, %rdx
jbe 0x963a
movq 0x28(%rcx), %rcx
andl $0x10, %ecx
movl %ecx, %edx
shrl $0x4, %edx
movl %edx, -0x2c(%rbp)
xorl %edx, %edx
testq %rcx, %rcx
sete %dl
leaq (%rdx,%rdx,2), %r13
jmp 0x9651
xorl %r13d, %r13d
movb $0x1, %cl
movl %ecx, -0x2c(%rbp)
jmp 0x9651
movl $0x5, %r13d
movl $0x0, -0x2c(%rbp)
cmpq %rax, %r15
je 0x9699
movq (%r12), %rax
movq 0x50(%rax), %rcx
movq (%rbx), %rdx
cmpq %rdx, %rcx
jae 0x966c
testb $0x10, 0x28(%rax)
jne 0x969d
movq 0x40(%r15), %rsi
movq 0x30(%rsi), %rsi
subq %rdx, %rsi
cmpq %rsi, %rcx
jbe 0x9699
movq 0x28(%rax), %rax
andl $0x10, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl %ecx, -0x30(%rbp)
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leaq (%rcx,%rcx,2), %rsi
jmp 0x96a9
xorl %esi, %esi
jmp 0x96a9
movl $0x5, %esi
movl $0x0, -0x30(%rbp)
cmpq %r15, %r14
je 0x96bb
movl -0x2c(%rbp), %edx
testb %dl, -0x30(%rbp)
je 0x96d1
jmp 0x9bb5
cmpl %esi, %r13d
sete %al
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %edx
orb %dl, %cl
orb %al, %cl
jne 0x9bb5
movq %rsi, -0xe0(%rbp)
leaq -0x110(%rbp), %rax
leaq -0x120(%rbp), %rdi
movq %rax, %r12
testb %dl, %dl
je 0x9701
movq %rax, (%rdi)
leaq 0x7b75(%rip), %rdx      # 0x1126c
movq %rdx, %rsi
callq 0x643c
jmp 0x9714
movq %rax, (%rdi)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x63a2
leaq -0x70(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %r14
movq %r14, %rdi
callq 0x63a2
movq %r13, -0x60(%rbp)
movq -0x120(%rbp), %rdi
cmpq %r12, %rdi
je 0x974e
callq 0x4280
leaq -0xf0(%rbp), %r13
cmpb $0x0, -0x30(%rbp)
je 0x9776
leaq -0x100(%rbp), %rdi
movq %r13, (%rdi)
leaq 0x7b00(%rip), %rdx      # 0x1126c
movq %rdx, %rsi
callq 0x643c
jmp 0x9790
leaq -0x100(%rbp), %rdi
movq %r13, (%rdi)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x63a2
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x63a2
movq -0xe0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
je 0x97d1
callq 0x4280
movl -0x2c(%rbp), %r13d
testb %r13b, %r13b
jne 0x990c
leaq 0x8(%rbx), %r12
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0xdcea
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x990c
leaq -0x148(%rbp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x8(%r13)
movaps %xmm0, 0x18(%r13)
movaps %xmm0, -0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq $0x0, 0x20(%r13)
leaq -0xc8(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x63a2
movq -0x60(%rbp), %rax
leaq -0xa8(%rbp), %rcx
movq %rax, -0x10(%rcx)
movq -0x140(%rbp), %rdx
testq %rdx, %rdx
je 0x98a3
leaq -0x128(%rbp), %rax
movl -0x20(%rax), %esi
movl %esi, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
movups -0x10(%rax), %xmm0
movups %xmm0, -0x98(%rbp)
movq %rcx, 0x8(%rdx)
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq $0x0, -0x18(%rax)
movq %r13, -0x10(%rax)
movq %r13, -0x8(%rax)
jmp 0x98c1
leaq -0x88(%rbp), %rax
movl $0x0, -0x20(%rax)
movq $0x0, -0x18(%rax)
movq %rcx, -0x10(%rax)
movq %rcx, -0x8(%rax)
movl -0x2c(%rbp), %r13d
movq $0x0, (%rax)
leaq -0xd8(%rbp), %rsi
movq %r12, %rdi
callq 0xdd52
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
callq 0xc832
movq -0x28(%r12), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x9900
callq 0x4280
leaq -0x150(%rbp), %rdi
callq 0xc832
cmpb $0x0, -0x30(%rbp)
jne 0x9a44
leaq 0x8(%rbx), %r12
leaq -0x58(%rbp), %rsi
movq %r12, %rdi
callq 0xdcea
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x9a44
leaq -0x148(%rbp), %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x8(%r13)
movaps %xmm0, 0x18(%r13)
movaps %xmm0, -0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq $0x0, 0x20(%r13)
leaq -0xc8(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x63a2
movq -0x38(%rbp), %rax
leaq -0xa8(%rbp), %rcx
movq %rax, -0x10(%rcx)
movq -0x140(%rbp), %rdx
testq %rdx, %rdx
je 0x99db
leaq -0x128(%rbp), %rax
movl -0x20(%rax), %esi
movl %esi, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
movups -0x10(%rax), %xmm0
movups %xmm0, -0x98(%rbp)
movq %rcx, 0x8(%rdx)
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq $0x0, -0x18(%rax)
movq %r13, -0x10(%rax)
movq %r13, -0x8(%rax)
jmp 0x99f9
leaq -0x88(%rbp), %rax
movl $0x0, -0x20(%rax)
movq $0x0, -0x18(%rax)
movq %rcx, -0x10(%rax)
movq %rcx, -0x8(%rax)
movl -0x2c(%rbp), %r13d
movq $0x0, (%rax)
leaq -0xd8(%rbp), %rsi
movq %r12, %rdi
callq 0xdd52
leaq -0xb0(%rbp), %r12
movq %r12, %rdi
callq 0xc832
movq -0x28(%r12), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x9a38
callq 0x4280
leaq -0x150(%rbp), %rdi
callq 0xc832
addq $0x8, %rbx
testb %r13b, %r13b
movq %r14, %rsi
cmovneq %r15, %rsi
movq %rbx, %rdi
callq 0xdcea
movq %rax, %r12
leaq 0x48(%rax), %rdi
testb %r13b, %r13b
cmovneq %r14, %r15
movq %r15, %rsi
callq 0xdf2e
movq %rax, %r15
addq $0x50, %r12
cmpq %r12, %rax
jne 0x9b89
movl $0x58, %edi
callq 0x42b0
movq %rax, %r14
leaq -0x80(%rbp), %rsi
leaq -0x58(%rbp), %rdx
movq %rax, %rdi
callq 0xbc4c
testb %r13b, %r13b
jne 0x9b13
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0xdcea
movq %rax, %r15
leaq -0xc8(%rbp), %r12
movq %r12, -0x10(%r12)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x63a2
movq -0x38(%rbp), %rax
leaq -0xd8(%rbp), %rsi
movq %rax, 0x20(%rsi)
movq %r14, 0x28(%rsi)
addq $0x48, %r15
movq %r15, %rdi
callq 0xdf96
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x9b04
callq 0x4280
leaq -0x58(%rbp), %rsi
movq %r15, %rdi
callq 0xdf2e
movq %rax, %r15
cmpb $0x0, -0x30(%rbp)
jne 0x9b89
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xdcea
movq %rax, %rbx
leaq -0xc8(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x63a2
movq -0x60(%rbp), %rax
leaq -0xd8(%rbp), %rsi
movq %rax, 0x20(%rsi)
movq %r14, 0x28(%rsi)
addq $0x48, %rbx
movq %rbx, %rdi
callq 0xdf96
movq -0xd8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9b7a
callq 0x4280
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0xdf2e
movq %rax, %r15
movq 0x48(%r15), %rax
incq 0x50(%rax)
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9ba3
callq 0x4280
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9bb5
callq 0x4280
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9c37
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r15, %rdi
jne 0x9c21
jmp 0x9c3a
jmp 0x9c37
jmp 0x9c37
jmp 0x9c37
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
jne 0x9c21
jmp 0x9c3a
jmp 0x9c37
jmp 0x9c37
jmp 0x9bf7
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0xbc20
jmp 0x9c0d
jmp 0x9c0a
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0xc832
jmp 0x9c3a
movq %rax, %rbx
movq %r14, %rdi
callq 0x4280
jmp 0x9c3a
jmp 0x9c37
jmp 0x9c37
jmp 0x9c37
jmp 0x9c30
movq %rax, %rbx
jmp 0x9c4c
jmp 0x9c37
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9c4c
callq 0x4280
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x9c5e
callq 0x4280
movq %rbx, %rdi
callq 0x4500
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r13, %rdi
jne 0x9c47
jmp 0x9c4c
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r12, %rdi
jne 0x9c59
jmp 0x9c5e