// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: intersect_annot_regions(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, bool, bool)
vector<t_annot_region*>* intersect_annot_regions(vector<t_annot_region*>* annot_regions1,
														vector<t_annot_region*>* annot_regions2,
														bool match_strands,
														bool find_all_overlaps)
{
	// Merged annot. regions.
	if(match_strands)
	{
		vector<t_annot_region*>* plus_strand_regions1 = get_regions_per_strand(annot_regions1, '+');
		vector<t_annot_region*>* plus_strand_regions2 = get_regions_per_strand(annot_regions2, '+');
		vector<t_annot_region*>* intersected_pos_strand_regions = intersect_annot_regions(plus_strand_regions1, plus_strand_regions2, find_all_overlaps);

		// Merge negative strand regions.
		vector<t_annot_region*>* neg_strand_regions1 = get_regions_per_strand(annot_regions1, '-');
		vector<t_annot_region*>* neg_strand_regions2 = get_regions_per_strand(annot_regions2, '-');
		vector<t_annot_region*>* intersected_neg_strand_regions = intersect_annot_regions(neg_strand_regions1, neg_strand_regions2, find_all_overlaps);

		// Pool the merged plus and minus strand regions.
		vector<t_annot_region*>* intersected_annot_regions = new vector<t_annot_region*>();
		intersected_annot_regions->insert(intersected_annot_regions->end(), intersected_pos_strand_regions->begin(), intersected_pos_strand_regions->end());
		intersected_annot_regions->insert(intersected_annot_regions->end(), intersected_neg_strand_regions->begin(), intersected_neg_strand_regions->end());


		delete(plus_strand_regions1);
		delete(plus_strand_regions2);

		delete(neg_strand_regions1);
		delete(neg_strand_regions2);
		return(intersected_annot_regions);
	}
	else
	{
		vector<t_annot_region*>* intersected_annot_regions = intersect_annot_regions(annot_regions1, annot_regions2, find_all_overlaps);
		return(intersected_annot_regions);
	}
}

// Assembly:
subq $0xe8, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, 0xd8(%rsp)
movq %rsi, 0xd0(%rsp)
andb $0x1, %cl
movb %cl, 0xcf(%rsp)
andb $0x1, %al
movb %al, 0xce(%rsp)
testb $0x1, 0xcf(%rsp)
je 0x2f976
movq 0xd8(%rsp), %rdi
movl $0x2b, %esi
callq 0x2ed10
movq %rax, 0xc0(%rsp)
movq 0xd0(%rsp), %rdi
movl $0x2b, %esi
callq 0x2ed10
movq %rax, 0xb8(%rsp)
movq 0xc0(%rsp), %rdi
movq 0xb8(%rsp), %rsi
movb 0xce(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x2d070
movq %rax, 0xb0(%rsp)
movq 0xd8(%rsp), %rdi
movl $0x2d, %esi
callq 0x2ed10
movq %rax, 0xa8(%rsp)
movq 0xd0(%rsp), %rdi
movl $0x2d, %esi
callq 0x2ed10
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movb 0xce(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x2d070
movq %rax, 0x98(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x18(%rsp), %rdi
callq 0xc670
movq 0x18(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x90(%rsp), %rdi
callq 0xc760
movq %rax, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xc790
movq 0xb0(%rsp), %rdi
callq 0xc7d0
movq %rax, 0x78(%rsp)
movq 0xb0(%rsp), %rdi
callq 0xc760
movq 0x20(%rsp), %rdi
movq %rax, 0x70(%rsp)
movq 0x88(%rsp), %rsi
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rcx
callq 0xc6a0
movq %rax, 0x68(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x90(%rsp), %rdi
callq 0xc760
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xc790
movq 0x98(%rsp), %rdi
callq 0xc7d0
movq %rax, 0x50(%rsp)
movq 0x98(%rsp), %rdi
callq 0xc760
movq 0x28(%rsp), %rdi
movq %rax, 0x48(%rsp)
movq 0x60(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
callq 0xc6a0
movq %rax, 0x40(%rsp)
movq 0xc0(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, %rax
je 0x2f8e3
movq 0x30(%rsp), %rdi
callq 0xc970
movq 0x30(%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0xb8(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x2f90f
movq 0x10(%rsp), %rdi
callq 0xc970
movq 0x10(%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x2f93b
movq 0x8(%rsp), %rdi
callq 0xc970
movq 0x8(%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0xa0(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x2f964
movq (%rsp), %rdi
callq 0xc970
movq (%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0x90(%rsp), %rax
movq %rax, 0xe0(%rsp)
jmp 0x2f9a9
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movb 0xce(%rsp), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x2d070
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rax
addq $0xe8, %rsp
retq
nopl (%rax)