// File: /workspace/github_cpp_makefile_star2_O2/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 0x7b13
addq $0x30, %rsi
movq %r15, %rdi
callq 0xb58e
movq %rax, %r15
jmp 0x7b17
addq $0x8, %r15
movq (%r12), %rsi
testb $0x4, 0x28(%rsi)
movq 0x38(%rbx), %rdi
jne 0x7b37
addq $0x30, %rsi
callq 0xb58e
movq %rax, %r14
movq 0x38(%rbx), %rdi
jmp 0x7b3b
leaq 0x8(%rdi), %r14
addq $0x8, %rdi
movq %r15, %rax
xorq %rdi, %rax
movq %r14, %rcx
xorq %rdi, %rcx
orq %rax, %rcx
je 0x7f30
movb $0x1, %al
movl %eax, -0x30(%rbp)
cmpq %rdi, %r15
je 0x7ba1
movq (%r13), %rax
movq 0x50(%rax), %rcx
movq (%rbx), %rdx
cmpq %rdx, %rcx
jae 0x7b74
testb $0x10, 0x28(%rax)
jne 0x7bab
movq 0x40(%r15), %rsi
movq 0x30(%rsi), %rsi
subq %rdx, %rsi
cmpq %rsi, %rcx
jbe 0x7ba1
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 0x7bb6
xorl %r13d, %r13d
movb $0x1, %al
movl %eax, -0x2c(%rbp)
jmp 0x7bb6
pushq $0x5
popq %r13
movl $0x0, -0x2c(%rbp)
cmpq %rdi, %r14
je 0x7bfe
movq (%r12), %rax
movq 0x50(%rax), %rcx
movq (%rbx), %rdx
cmpq %rdx, %rcx
jae 0x7bd1
testb $0x10, 0x28(%rax)
jne 0x7c03
movq 0x40(%r14), %rsi
movq 0x30(%rsi), %rsi
subq %rdx, %rsi
cmpq %rsi, %rcx
jbe 0x7bfe
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), %r12
jmp 0x7c0e
xorl %r12d, %r12d
jmp 0x7c0e
pushq $0x5
popq %r12
movl $0x0, -0x30(%rbp)
cmpq %r14, %r15
je 0x7c20
movl -0x2c(%rbp), %edx
testb %dl, -0x30(%rbp)
je 0x7c36
jmp 0x7f30
cmpl %r12d, %r13d
sete %al
movl -0x30(%rbp), %ecx
movl -0x2c(%rbp), %edx
orb %dl, %cl
orb %al, %cl
jne 0x7f30
testb %dl, %dl
je 0x7c53
leaq 0x6629(%rip), %rsi      # 0xe26a
leaq -0x150(%rbp), %rdi
leaq -0x32(%rbp), %rdx
callq 0x40f0
jmp 0x7c66
addq $0x20, %r15
leaq -0x150(%rbp), %rdi
movq %r15, %rsi
callq 0x43a0
leaq -0x88(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movl -0x2c(%rbp), %r15d
callq 0x43a0
movq %r13, -0x68(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x4130
testb %r15b, %r15b
movl -0x30(%rbp), %r13d
testb %r13b, %r13b
je 0x7cb2
leaq 0x65ca(%rip), %rsi      # 0xe26a
leaq -0x130(%rbp), %rdi
leaq -0x31(%rbp), %rdx
callq 0x40f0
jmp 0x7cc5
addq $0x20, %r14
leaq -0x130(%rbp), %rdi
movq %r14, %rsi
callq 0x43a0
leaq -0x60(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x43a0
movq %r12, -0x40(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x4130
testb %r13b, %r13b
testb %r15b, %r15b
jne 0x7d6a
leaq 0x8(%rbx), %r14
leaq -0x88(%rbp), %rsi
movq %r14, %rdi
callq 0xb618
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x7d6a
leaq -0x108(%rbp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xe0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x966e
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0xb6a2
leaq -0xe0(%rbp), %rdi
callq 0x9698
leaq -0x110(%rbp), %rdi
callq 0xa036
testb %r13b, %r13b
jne 0x7de6
leaq 0x8(%rbx), %r14
leaq -0x60(%rbp), %rsi
movq %r14, %rdi
callq 0xb618
leaq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x7de6
leaq -0x108(%rbp), %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0x8(%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xe0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x966e
leaq -0xe0(%rbp), %rsi
movq %r14, %rdi
callq 0xb6a2
leaq -0xe0(%rbp), %rdi
callq 0x9698
leaq -0x110(%rbp), %rdi
callq 0xa036
addq $0x8, %rbx
testb %r15b, %r15b
je 0x7e10
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
callq 0xb618
movq %rax, %r14
leaq 0x48(%rax), %rdi
leaq -0x88(%rbp), %rsi
callq 0xb8d6
jmp 0x7e2f
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0xb618
movq %rax, %r14
leaq 0x48(%rax), %rdi
leaq -0x60(%rbp), %rsi
callq 0xb8d6
movq %rax, %r15
addq $0x50, %r14
cmpq %r14, %rax
jne 0x7f13
pushq $0x58
popq %rdi
callq 0x4280
movq %rax, %r14
leaq -0x88(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %rax, %rdi
callq 0x96b8
cmpb $0x0, -0x2c(%rbp)
jne 0x7eb7
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0xb618
movq %rax, %r15
leaq -0xe0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x9fae
leaq -0xe0(%rbp), %rsi
movq %r14, 0x28(%rsi)
addq $0x48, %r15
movq %r15, %rdi
callq 0xb960
leaq -0xe0(%rbp), %rdi
callq 0x4130
leaq -0x60(%rbp), %rsi
movq %r15, %rdi
callq 0xb8d6
movq %rax, %r15
testb %r13b, %r13b
jne 0x7f13
leaq -0x60(%rbp), %rsi
movq %rbx, %rdi
callq 0xb618
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x9fae
leaq -0xe0(%rbp), %rsi
movq %r14, 0x28(%rsi)
addq $0x48, %rbx
movq %rbx, %rdi
callq 0xb960
leaq -0xe0(%rbp), %rdi
callq 0x4130
leaq -0x88(%rbp), %rsi
movq %rbx, %rdi
callq 0xb8d6
movq %rax, %r15
movq 0x48(%r15), %rax
incq 0x50(%rax)
leaq -0x60(%rbp), %rdi
callq 0x4130
leaq -0x88(%rbp), %rdi
callq 0x4130
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7fa8
jmp 0x7f4c
jmp 0x7fa8
jmp 0x7fa8
jmp 0x7fa8
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x4130
jmp 0x7fab
jmp 0x7fa8
jmp 0x7fa8
jmp 0x7f63
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x9698
jmp 0x7f79
jmp 0x7f76
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xa036
jmp 0x7fab
movq %rax, %rbx
movq %r14, %rdi
callq 0x4250
jmp 0x7fab
jmp 0x7fa8
jmp 0x7fa8
jmp 0x7fa8
jmp 0x7f9c
movq %rax, %rbx
jmp 0x7fb4
movq %rax, %rbx
jmp 0x7fc0
jmp 0x7fa8
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x4130
leaq -0x88(%rbp), %rdi
callq 0x4130
movq %rbx, %rdi
callq 0x44b0
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x4130
testb %r13b, %r13b
jmp 0x7fb4
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x4130
testb %r15b, %r15b
jmp 0x7fc0