// File: /workspace/github_cpp_makefile_star2_O3/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), %r15
jne 0x95cd
addq $0x30, %rsi
movq %r15, %rdi
callq 0xdc02
movq %rax, %r15
jmp 0x95d1
addq $0x8, %r15
movq (%r12), %rsi
testb $0x4, 0x28(%rsi)
movq 0x38(%rbx), %rdi
jne 0x95f1
addq $0x30, %rsi
callq 0xdc02
movq %rax, %r14
movq 0x38(%rbx), %rdi
jmp 0x95f5
leaq 0x8(%rdi), %r14
addq $0x8, %rdi
movq %r15, %rax
xorq %rdi, %rax
movq %r14, %rcx
xorq %rdi, %rcx
orq %rax, %rcx
je 0x9bc3
movb $0x1, %al
movl %eax, -0x30(%rbp)
cmpq %rdi, %r15
je 0x965b
movq (%r13), %rax
movq 0x50(%rax), %rcx
movq (%rbx), %rdx
cmpq %rdx, %rcx
jae 0x962e
testb $0x10, 0x28(%rax)
jne 0x9665
movq 0x40(%r15), %rsi
movq 0x30(%rsi), %rsi
subq %rdx, %rsi
cmpq %rsi, %rcx
jbe 0x965b
movq 0x28(%rax), %rax
andl $0x10, %eax
movl %eax, %ecx
shrl $0x4, %ecx
movl %ecx, -0x2c(%rbp)
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leaq (%rcx,%rcx,2), %r13
jmp 0x9672
xorl %r13d, %r13d
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x9672
movl $0x5, %r13d
movl $0x0, -0x2c(%rbp)
cmpq %rdi, %r14
je 0x96ba
movq (%r12), %rax
movq 0x50(%rax), %rcx
movq (%rbx), %rdx
cmpq %rdx, %rcx
jae 0x968d
testb $0x10, 0x28(%rax)
jne 0x96be
movq 0x40(%r14), %rsi
movq 0x30(%rsi), %rsi
subq %rdx, %rsi
cmpq %rsi, %rcx
jbe 0x96ba
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 0x96ca
xorl %esi, %esi
jmp 0x96ca
movl $0x5, %esi
movl $0x0, -0x30(%rbp)
cmpq %r14, %r15
je 0x96dc
movl -0x2c(%rbp), %edx
testb %dl, -0x30(%rbp)
je 0x96f2
jmp 0x9bc3
cmpl %esi, %r13d
sete %al
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %edx
orb %dl, %cl
orb %al, %cl
jne 0x9bc3
movq %rsi, -0xe0(%rbp)
leaq -0x110(%rbp), %rax
leaq -0x120(%rbp), %rdi
movq %rax, %r12
testb %dl, %dl
je 0x9722
movq %rax, (%rdi)
leaq 0x7b52(%rip), %rdx      # 0x1126a
movq %rdx, %rsi
callq 0x6440
jmp 0x9735
movq %rax, (%rdi)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
callq 0x63a2
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x63a2
movq %r13, -0x38(%rbp)
movq -0x120(%rbp), %rdi
cmpq %r12, %rdi
je 0x976c
callq 0x4280
leaq -0xf0(%rbp), %r15
cmpb $0x0, -0x30(%rbp)
je 0x9794
leaq -0x100(%rbp), %rdi
movq %r15, (%rdi)
leaq 0x7ae0(%rip), %rdx      # 0x1126a
movq %rdx, %rsi
callq 0x6440
jmp 0x97ae
leaq -0x100(%rbp), %rdi
movq %r15, (%rdi)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x63a2
leaq -0x70(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x100(%rbp), %rsi
movq -0xf8(%rbp), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x63a2
movq -0xe0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
je 0x97ec
callq 0x4280
movl -0x2c(%rbp), %r12d
testb %r12b, %r12b
jne 0x9917
leaq 0x8(%rbx), %r14
leaq -0x58(%rbp), %rsi
movq %r14, %rdi
callq 0xdca0
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x9917
leaq -0x148(%rbp), %r12
xorl %eax, %eax
movq %rax, 0x8(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq -0xc8(%rbp), %r15
movq %r15, -0x10(%r15)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x63a2
movq -0x38(%rbp), %rcx
leaq -0xa8(%rbp), %rax
movq %rcx, -0x10(%rax)
movq -0x140(%rbp), %rsi
testq %rsi, %rsi
je 0x98b5
leaq -0x128(%rbp), %rcx
movl -0x20(%rcx), %edx
movq %rsi, -0xa0(%rbp)
movq -0x10(%rcx), %r8
movq -0x8(%rcx), %rdi
movq %rax, 0x8(%rsi)
movq (%rcx), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x18(%rcx)
movq %r12, -0x10(%rcx)
movq %r12, -0x8(%rcx)
movq %r8, %rax
jmp 0x98c9
leaq -0x88(%rbp), %rcx
movq $0x0, -0x18(%rcx)
xorl %edx, %edx
movq %rax, %rdi
movl -0x2c(%rbp), %r12d
leaq -0xd8(%rbp), %rsi
movq %rax, 0x40(%rsi)
movq %rdi, 0x48(%rsi)
movq $0x0, (%rcx)
movl %edx, 0x30(%rsi)
movq %r14, %rdi
callq 0xdd04
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0xc84e
movq -0x28(%r14), %rdi
cmpq %r15, %rdi
je 0x990b
callq 0x4280
leaq -0x150(%rbp), %rdi
callq 0xc84e
cmpb $0x0, -0x30(%rbp)
jne 0x9a3f
leaq 0x8(%rbx), %r14
leaq -0x80(%rbp), %rsi
movq %r14, %rdi
callq 0xdca0
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x9a3f
leaq -0x148(%rbp), %r12
xorl %eax, %eax
movq %rax, 0x8(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
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), %rcx
leaq -0xa8(%rbp), %rax
movq %rcx, -0x10(%rax)
movq -0x140(%rbp), %rsi
testq %rsi, %rsi
je 0x99dd
leaq -0x128(%rbp), %rcx
movl -0x20(%rcx), %edx
movq %rsi, -0xa0(%rbp)
movq -0x10(%rcx), %r8
movq -0x8(%rcx), %rdi
movq %rax, 0x8(%rsi)
movq (%rcx), %rax
movq %rax, -0x88(%rbp)
movq $0x0, -0x18(%rcx)
movq %r12, -0x10(%rcx)
movq %r12, -0x8(%rcx)
movq %r8, %rax
jmp 0x99f1
leaq -0x88(%rbp), %rcx
movq $0x0, -0x18(%rcx)
xorl %edx, %edx
movq %rax, %rdi
movl -0x2c(%rbp), %r12d
leaq -0xd8(%rbp), %rsi
movq %rax, 0x40(%rsi)
movq %rdi, 0x48(%rsi)
movq $0x0, (%rcx)
movl %edx, 0x30(%rsi)
movq %r14, %rdi
callq 0xdd04
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0xc84e
movq -0x28(%r14), %rdi
cmpq %r15, %rdi
je 0x9a33
callq 0x4280
leaq -0x150(%rbp), %rdi
callq 0xc84e
addq $0x8, %rbx
testb %r12b, %r12b
je 0x9a66
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0xdca0
movq %rax, %r14
leaq 0x48(%rax), %rdi
leaq -0x58(%rbp), %rsi
callq 0xded8
jmp 0x9a82
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xdca0
movq %rax, %r14
leaq 0x48(%rax), %rdi
leaq -0x80(%rbp), %rsi
callq 0xded8
movq %rax, %r15
addq $0x50, %r14
cmpq %r14, %rax
jne 0x9b9b
movl $0x58, %edi
callq 0x42b0
movq %rax, %r14
leaq -0x58(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %rax, %rdi
callq 0xbc6a
testb %r12b, %r12b
jne 0x9b25
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xdca0
movq %rax, %r15
leaq -0xc8(%rbp), %r12
movq %r12, -0x10(%r12)
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, %r15
movq %r15, %rdi
callq 0xdf3c
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
je 0x9b16
callq 0x4280
leaq -0x80(%rbp), %rsi
movq %r15, %rdi
callq 0xded8
movq %rax, %r15
cmpb $0x0, -0x30(%rbp)
jne 0x9b9b
leaq -0x80(%rbp), %rsi
movq %rbx, %rdi
callq 0xdca0
movq %rax, %rbx
leaq -0xc8(%rbp), %r15
movq %r15, -0x10(%r15)
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, %rbx
movq %rbx, %rdi
callq 0xdf3c
movq -0xd8(%rbp), %rdi
cmpq %r15, %rdi
je 0x9b8c
callq 0x4280
leaq -0x58(%rbp), %rsi
movq %rbx, %rdi
callq 0xded8
movq %rax, %r15
movq 0x48(%r15), %rax
incq 0x50(%rax)
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x9bb1
callq 0x4280
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9bc3
callq 0x4280
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x9c45
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r15, %rdi
jne 0x9c2f
jmp 0x9c48
jmp 0x9c45
jmp 0x9c45
jmp 0x9c45
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r12, %rdi
jne 0x9c2f
jmp 0x9c48
jmp 0x9c45
jmp 0x9c45
jmp 0x9c05
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0xbc3e
jmp 0x9c1b
jmp 0x9c18
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0xc84e
jmp 0x9c48
movq %rax, %rbx
movq %r14, %rdi
callq 0x4280
jmp 0x9c48
jmp 0x9c45
jmp 0x9c45
jmp 0x9c45
jmp 0x9c3e
movq %rax, %rbx
jmp 0x9c56
jmp 0x9c45
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x9c56
callq 0x4280
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x9c68
callq 0x4280
movq %rbx, %rdi
callq 0x44f0
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r15, %rdi
jne 0x9c51
jmp 0x9c56
movq %rax, %rbx
movq -0x120(%rbp), %rdi
cmpq %r12, %rdi
jne 0x9c63
jmp 0x9c68