// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdi, %r14
movl $0x18, %edi
callq 0x2180
movq %rax, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %r14, %rdi
movl $0x2b, %esi
callq 0x1a265
movq %rax, %r15
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x171f7
movq %rax, %r14
movq (%rax), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
movq %r14, 0x8(%rsp)
jle 0x1bcbe
xorl %r13d, %r13d
movq %r15, (%rsp)
cmpq %r13, %rdx
jbe 0x1bec8
movq (%rax,%r13,8), %rsi
movq %r15, %rdi
callq 0x19bcb
movq %rax, %r15
movq (%rax), %rbp
movq 0x8(%rax), %r12
cmpq %r12, %rbp
je 0x1bc2b
movq %r12, %rax
subq %rbp, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbp, %rdi
movq %r12, %rsi
leaq -0x4d08(%rip), %r14     # 0x16f04
movq %r14, %rcx
callq 0x1c455
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1c586
movq (%r15), %rbp
movq 0x8(%r15), %rdx
jmp 0x1bc2e
movq %rbp, %rdx
subq %rbp, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1bc91
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq %r12, %rdx
jbe 0x1beab
addq %r14, %rbp
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1bc63
movq (%rbp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1bc6e
movq %rbx, %rdi
movq %rbp, %rdx
callq 0xb74c
incq %r12
movq (%r15), %rbp
movq 0x8(%r15), %rax
subq %rbp, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
addq $0x8, %r14
cmpq %rax, %r12
jl 0x1bc3f
incq %r13
movq 0x8(%rsp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
movq (%rsp), %r15
jl 0x1bbc4
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1bcd2
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x2190
movl $0x18, %esi
movq %r15, %rdi
callq 0x2190
movq 0x10(%rsp), %rdi
movl $0x2d, %esi
callq 0x1a265
movq %rax, %r15
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1be0a
xorl %r12d, %r12d
movq %r15, (%rsp)
cmpq %r12, %rdx
jbe 0x1beab
movq (%rax,%r12,8), %rsi
movq %r15, %rdi
callq 0x19bcb
movq %rax, %rbp
movq (%rax), %r13
movq 0x8(%rax), %r15
cmpq %r15, %r13
je 0x1bd76
movq %r15, %rax
subq %r13, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r13, %rdi
movq %r15, %rsi
leaq -0x4e52(%rip), %r14     # 0x16f04
movq %r14, %rcx
callq 0x1c455
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1c586
movq (%rbp), %r13
movq 0x8(%rbp), %rdx
jmp 0x1bd79
movq %r13, %rdx
subq %r13, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1bddd
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %r15, %rdx
jbe 0x1beb7
addq %r14, %r13
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1bdae
movq (%r13), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1bdb9
movq %rbx, %rdi
movq %r13, %rdx
callq 0xb74c
incq %r15
movq (%rbp), %r13
movq 0x8(%rbp), %rax
subq %r13, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
addq $0x8, %r14
cmpq %rax, %r15
jl 0x1bd8a
incq %r12
movq 0x8(%rsp), %r14
movq (%r14), %rax
movq 0x8(%r14), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r12
movq (%rsp), %r15
jl 0x1bd0e
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1be1e
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x2190
movl $0x18, %esi
movq %r15, %rdi
callq 0x2190
movq (%r14), %rdi
movq 0x8(%r14), %rcx
movq %rcx, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1be7b
xorl %r15d, %r15d
cmpq %r15, %rdx
jbe 0x1beb7
movq (%rdi,%r15,8), %rax
testq %rax, %rax
je 0x1be60
movq %rax, %rdi
callq 0x2220
movq (%r14), %rdi
movq 0x8(%r14), %rcx
incq %r15
movq %rcx, %rax
subq %rdi, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
cmpq %rax, %r15
jl 0x1be43
testq %rdi, %rdi
je 0x1be8c
movq 0x10(%r14), %rsi
subq %rdi, %rsi
callq 0x2190
movl $0x18, %esi
movq %r14, %rdi
callq 0x2190
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10a1e(%rip), %rdi     # 0x2c8d0
movq %r12, %rsi
jmp 0x1bec1
leaq 0x10a12(%rip), %rdi     # 0x2c8d0
movq %r15, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x10a01(%rip), %rdi     # 0x2c8d0
movq %r13, %rsi
jmp 0x1bec1