// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: sort_regions_per_chromosome_per_strand(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*)
vector<t_annot_region*>* sort_regions_per_chromosome_per_strand(vector<t_annot_region*>* annot_region_list)
{
	vector<t_annot_region*>* sorted_region_list = new vector<t_annot_region*>();

	// No mallocation in following.
	vector<t_annot_region*>* pos_strand_regions = get_regions_per_strand(annot_region_list, '+');

	vector<char*>* chr_ids = get_chr_ids(annot_region_list);

	for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
	{
		vector<t_annot_region*>* cur_chr_regions = get_regions_per_chromosome(pos_strand_regions, chr_ids->at(i_chr));

		sort(cur_chr_regions->begin(), cur_chr_regions->end(), sort_regions);

		for(int i_reg = 0; i_reg < (int)cur_chr_regions->size(); i_reg++)
		{
			sorted_region_list->push_back(cur_chr_regions->at(i_reg));
		}
	} // i_chr loop.
	delete(pos_strand_regions);

	vector<t_annot_region*>* neg_strand_regions = get_regions_per_strand(annot_region_list, '-');
	for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
	{
		vector<t_annot_region*>* cur_chr_regions = get_regions_per_chromosome(neg_strand_regions, chr_ids->at(i_chr));

		sort(cur_chr_regions->begin(), cur_chr_regions->end(), sort_regions);

		for(int i_reg = 0; i_reg < (int)cur_chr_regions->size(); i_reg++)
		{
			sorted_region_list->push_back(cur_chr_regions->at(i_reg));
		}
	} // i_chr loop.
	delete(neg_strand_regions);

	// Delete chr_ids.
	for(int i_chr = 0; i_chr < (int)chr_ids->size(); i_chr++)
	{
		delete [] chr_ids->at(i_chr);
	}
	delete(chr_ids);

	return(sorted_region_list);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
pushq $0x18
popq %rdi
callq 0x2170
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
pushq $0x2b
popq %rsi
movq %r14, %rdi
callq 0x16108
movq %rax, %r12
movq %r14, (%rsp)
movq %r14, %rdi
callq 0x137a1
movq %rax, %r14
xorl %r13d, %r13d
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r13
jge 0x1760a
movq %r14, %rdi
movq %r13, %rsi
callq 0x7342
movq (%rax), %rsi
movq %r12, %rdi
callq 0x15b31
movq %rax, %r15
movq (%rax), %rdi
movq 0x8(%rax), %rsi
leaq -0x413a(%rip), %rdx     # 0x13497
callq 0x17bcf
xorl %ebp, %ebp
movq 0x8(%r15), %rax
subq (%r15), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %rbp
jge 0x17605
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7404
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7448
incq %rbp
jmp 0x175d8
incq %r13
jmp 0x17598
movq %r12, %rdi
callq 0x832c
pushq $0x18
popq %rsi
movq %r12, %rdi
callq 0x2180
pushq $0x2d
popq %rsi
movq (%rsp), %rdi
callq 0x16108
movq %rax, %r15
xorl %r12d, %r12d
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r12
jge 0x176a3
movq %r14, %rdi
movq %r12, %rsi
callq 0x7342
movq (%rax), %rsi
movq %r15, %rdi
callq 0x15b31
movq %rax, %rbp
movq (%rax), %rdi
movq 0x8(%rax), %rsi
leaq -0x41d1(%rip), %rdx     # 0x13497
callq 0x17bcf
xorl %r13d, %r13d
movq 0x8(%rbp), %rax
subq (%rbp), %rax
shrq $0x3, %rax
cltq
cmpq %rax, %r13
jge 0x1769e
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7404
movq %rbx, %rdi
movq %rax, %rsi
callq 0x7448
incq %r13
jmp 0x17670
incq %r12
jmp 0x1762f
movq %r15, %rdi
callq 0x832c
pushq $0x18
popq %rsi
movq %r15, %rdi
callq 0x2180
xorl %r15d, %r15d
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x3, %rax
cltq
movq %r14, %rdi
cmpq %rax, %r15
jge 0x176e8
movq %r15, %rsi
callq 0x7342
movq (%rax), %rdi
testq %rdi, %rdi
je 0x176e3
callq 0x2210
incq %r15
jmp 0x176b9
callq 0x7cb8
pushq $0x18
popq %rsi
movq %r14, %rdi
callq 0x2180
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq