// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: nuc_overlap_src_over_both_overlap(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, std::vector<t_annot_region*, std::allocator<t_annot_region*>>*)
double nuc_overlap_src_over_both_overlap(vector<t_annot_region*>* annot_regions1, 
										vector<t_annot_region*>* annot_regions2)
{
	// Compute the coverage of overlap divided by the coverage of only parts that overlapped.
	vector<t_annot_region*>* overlapping_regions = intersect_annot_regions(annot_regions1, annot_regions2, false);

	// Get the overlapping regions in each list: Fix the indices: Batch intersection returns only the overlapping regions.
	vector<t_annot_region*>* overlapping_regions1 = intersect_annot_regions(annot_regions1, annot_regions2, false);
	for(int i_reg = 0; i_reg < (int)overlapping_regions1->size(); i_reg++)
	{
		if(overlapping_regions1->at(i_reg) != NULL)
		{
			overlapping_regions1->at(i_reg)->start = annot_regions1->at(i_reg)->start;
			overlapping_regions1->at(i_reg)->end = annot_regions1->at(i_reg)->end;
		}
	} // i_reg loop.

	vector<t_annot_region*>* overlapping_regions2 = intersect_annot_regions(annot_regions2, annot_regions1, false);
	for(int i_reg = 0; i_reg < (int)overlapping_regions2->size(); i_reg++)
	{
		if(overlapping_regions2->at(i_reg) != NULL)
		{
			overlapping_regions2->at(i_reg)->start = annot_regions2->at(i_reg)->start;
			overlapping_regions2->at(i_reg)->end = annot_regions2->at(i_reg)->end;
		}
	} // i_reg loop.

	int overlap_cvg = (int)coverage(overlapping_regions);
	int total_cvg = (int)coverage(overlapping_regions1) + (int)coverage(overlapping_regions2);

	if(total_cvg == 0)
	{
		return 0.0;
	}
	printf("2 * %d / (%d + %d)\n", (int)coverage(overlapping_regions), (int)coverage(overlapping_regions1), (int)coverage(overlapping_regions2));
	return((double)(2 * overlap_cvg) / total_cvg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r12
xorl %r13d, %r13d
xorl %edx, %edx
callq 0x150d3
movq %rax, %rbx
movq %r12, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x150d3
movq %rax, %r14
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r13
jge 0x15488
movq %r14, %rdi
movq %r13, %rsi
callq 0x7404
cmpq $0x0, (%rax)
je 0x15483
movq %r12, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl %ebp, 0xc(%rax)
movq %r12, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %ebp
movq %r14, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl %ebp, 0x20(%rax)
incq %r13
jmp 0x1541c
xorl %r13d, %r13d
movq %r15, %rdi
movq %r12, %rsi
xorl %edx, %edx
callq 0x150d3
movq %rax, %r12
movq 0x8(%r12), %rax
subq (%r12), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r13
jge 0x15509
movq %r12, %rdi
movq %r13, %rsi
callq 0x7404
cmpq $0x0, (%rax)
je 0x15504
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0xc(%rax), %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl %ebp, 0xc(%rax)
movq %r15, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl 0x20(%rax), %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x7404
movq (%rax), %rax
movl %ebp, 0x20(%rax)
incq %r13
jmp 0x1549b
movq %rbx, %rdi
callq 0x14fba
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0x14fba
cvttsd2si %xmm0, %ebp
movq %r12, %rdi
callq 0x14fba
cvttsd2si %xmm0, %r15d
addl %ebp, %r15d
je 0x15583
cvttsd2si (%rsp), %r13d
movq %rbx, %rdi
callq 0x14fba
cvttsd2si %xmm0, %ebx
movq %r14, %rdi
callq 0x14fba
cvttsd2si %xmm0, %ebp
movq %r12, %rdi
callq 0x14fba
cvttsd2si %xmm0, %ecx
leaq 0x1279d(%rip), %rdi     # 0x27d02
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x2050
addl %r13d, %r13d
cvtsi2sd %r13d, %xmm0
cvtsi2sd %r15d, %xmm1
divsd %xmm1, %xmm0
jmp 0x15587
xorpd %xmm0, %xmm0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq