// File: 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:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x68(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x68(%rsp), %rdi
callq 0xc670
movq 0x68(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq 0xe0(%rsp), %rdi
movl $0x2b, %esi
callq 0x2ed10
movq %rax, 0xd0(%rsp)
movq 0xe0(%rsp), %rdi
callq 0x2a910
movq %rax, 0xc8(%rsp)
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, 0x64(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xc220
movq %rax, %rcx
movl 0x64(%rsp), %eax
cmpl %ecx, %eax
jge 0x312ba
movq 0xd0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xc8(%rsp), %rdi
movslq 0xc4(%rsp), %rsi
callq 0xc240
movq 0x58(%rsp), %rdi
movq (%rax), %rsi
callq 0x2e1e0
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xc7d0
movq %rax, 0xb0(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xc760
movq %rax, 0xa8(%rsp)
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %rsi
leaq -0x6e8d(%rip), %rdx     # 0x2a3a0
callq 0x31d00
movl $0x0, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
movl %eax, 0x54(%rsp)
movq 0xb8(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x54(%rsp), %eax
cmpl %ecx, %eax
jge 0x312a2
movq 0xd8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xb8(%rsp), %rdi
movslq 0xa4(%rsp), %rsi
callq 0xc800
movq 0x48(%rsp), %rdi
movq %rax, %rsi
callq 0xc8c0
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x3123d
jmp 0x312a4
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x3118e
movq 0xd0(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x312e6
movq 0x40(%rsp), %rdi
callq 0xc970
movq 0x40(%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0xe0(%rsp), %rdi
movl $0x2d, %esi
callq 0x2ed10
movq %rax, 0x98(%rsp)
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xc220
movq %rax, %rcx
movl 0x3c(%rsp), %eax
cmpl %ecx, %eax
jge 0x31422
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0xc8(%rsp), %rdi
movslq 0x94(%rsp), %rsi
callq 0xc240
movq 0x30(%rsp), %rdi
movq (%rax), %rsi
callq 0x2e1e0
movq %rax, 0x88(%rsp)
movq 0x88(%rsp), %rdi
callq 0xc7d0
movq %rax, 0x80(%rsp)
movq 0x88(%rsp), %rdi
callq 0xc760
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
leaq -0x7004(%rip), %rdx     # 0x2a3a0
callq 0x31d00
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x88(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x3140a
movq 0xd8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x88(%rsp), %rdi
movslq 0x74(%rsp), %rsi
callq 0xc800
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0xc8c0
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x313b1
jmp 0x3140c
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x3130b
movq 0x98(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x3144e
movq 0x18(%rsp), %rdi
callq 0xc970
movq 0x18(%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movl $0x0, 0x70(%rsp)
movl 0x70(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0xc8(%rsp), %rdi
callq 0xc220
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x314af
movq 0xc8(%rsp), %rdi
movslq 0x70(%rsp), %rsi
callq 0xc240
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x314a0
movq 0x8(%rsp), %rdi
callq 0x2220
jmp 0x314a2
movl 0x70(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x70(%rsp)
jmp 0x31456
movq 0xc8(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x314d8
movq (%rsp), %rdi
callq 0xc570
movq (%rsp), %rdi
movl $0x18, %esi
callq 0x21a0
movq 0xd8(%rsp), %rax
addq $0xe8, %rsp
retq
nopl (%rax,%rax)