// File: 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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x2d070
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x2d070
movq %rax, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
movl %eax, 0x20(%rsp)
movq 0x40(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x20(%rsp), %eax
cmpl %ecx, %eax
jge 0x2d69e
movq 0x40(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0xc800
cmpq $0x0, (%rax)
je 0x2d68c
movq 0x58(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0xc800
movl 0x18(%rsp), %ecx
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq 0x58(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x40(%rsp), %rdi
movslq 0x3c(%rsp), %rsi
callq 0xc800
movl 0x1c(%rsp), %ecx
movq (%rax), %rax
movl %ecx, 0x20(%rax)
jmp 0x2d68e
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x2d5f2
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
xorl %edx, %edx
callq 0x2d070
movq %rax, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x2d768
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
cmpq $0x0, (%rax)
je 0x2d756
movq 0x50(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movl 0xc(%rsp), %ecx
movq (%rax), %rax
movl %ecx, 0xc(%rax)
movq 0x50(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movslq 0x2c(%rsp), %rsi
callq 0xc800
movl 0x10(%rsp), %ecx
movq (%rax), %rax
movl %ecx, 0x20(%rax)
jmp 0x2d758
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x2d6bc
movq 0x48(%rsp), %rdi
callq 0x2ced0
cvttsd2si %xmm0, %eax
movl %eax, 0x28(%rsp)
movq 0x40(%rsp), %rdi
callq 0x2ced0
cvttsd2si %xmm0, %eax
movl %eax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x2ced0
movl 0x8(%rsp), %eax
cvttsd2si %xmm0, %ecx
addl %ecx, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0x24(%rsp)
jne 0x2d7b6
xorps %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0x2d816
movq 0x48(%rsp), %rdi
callq 0x2ced0
cvttsd2si %xmm0, %eax
movl %eax, (%rsp)
movq 0x40(%rsp), %rdi
callq 0x2ced0
cvttsd2si %xmm0, %eax
movl %eax, 0x4(%rsp)
movq 0x30(%rsp), %rdi
callq 0x2ced0
movl (%rsp), %esi
movl 0x4(%rsp), %edx
cvttsd2si %xmm0, %ecx
leaq 0x28915(%rip), %rdi     # 0x5610a
movb $0x0, %al
callq 0x2050
movl 0x28(%rsp), %eax
shll %eax
cvtsi2sd %eax, %xmm0
cvtsi2sdl 0x24(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)