// File: /workspace/github_cpp_makefile_star2_O1/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 0x1a69a
movq %rax, %r15
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x1756e
movq (%rax), %rsi
movq %rax, (%rsp)
movq 0x8(%rax), %rdx
subq %rsi, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1c0c2
xorl %r13d, %r13d
movq %r15, 0x8(%rsp)
cmpq %r13, %rdx
jbe 0x1c2d4
movq (%rsi,%r13,8), %rsi
movq %r15, %rdi
callq 0x1a008
movq %rax, %r15
movq (%rax), %rbp
movq 0x8(%rax), %r12
cmpq %r12, %rbp
je 0x1c02f
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 -0x4d88(%rip), %r14     # 0x17291
movq %r14, %rcx
callq 0x1c869
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1c99a
movq (%r15), %rdx
movq 0x8(%r15), %rax
subq %rdx, %rax
sarq $0x3, %rax
testl %eax, %eax
jle 0x1c095
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq %rbp, %rax
jbe 0x1c2b4
addq %r12, %rdx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1c069
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1c071
movq %rbx, %rdi
callq 0xb976
incq %rbp
movq (%r15), %rdx
movq 0x8(%r15), %rcx
subq %rdx, %rcx
movq %rcx, %rax
sarq $0x3, %rax
shrq $0x3, %rcx
movslq %ecx, %rcx
addq $0x8, %r12
cmpq %rcx, %rbp
jl 0x1c046
incq %r13
movq (%rsp), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rcx
subq %rsi, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r13
movq 0x8(%rsp), %r15
jl 0x1bfd1
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1c0d6
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 0x1a69a
movq %rax, %r15
movq (%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1c20b
xorl %r12d, %r12d
movq %r15, 0x8(%rsp)
cmpq %r12, %rdx
jbe 0x1c2ec
movq (%rax,%r12,8), %rsi
movq %r15, %rdi
callq 0x1a008
movq %rax, %rbp
movq (%rax), %r13
movq 0x8(%rax), %r15
cmpq %r15, %r13
je 0x1c175
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 -0x4ece(%rip), %r14     # 0x17291
movq %r14, %rcx
callq 0x1c869
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x1c99a
movq (%rbp), %rdx
movq 0x8(%rbp), %rax
subq %rdx, %rax
sarq $0x3, %rax
testl %eax, %eax
jle 0x1c1de
xorl %r15d, %r15d
xorl %r13d, %r13d
cmpq %r13, %rax
jbe 0x1c2c0
addq %r15, %rdx
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x1c1b1
movq (%rdx), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x1c1b9
movq %rbx, %rdi
callq 0xb976
incq %r13
movq (%rbp), %rdx
movq 0x8(%rbp), %rcx
subq %rdx, %rcx
movq %rcx, %rax
sarq $0x3, %rax
shrq $0x3, %rcx
movslq %ecx, %rcx
addq $0x8, %r15
cmpq %rcx, %r13
jl 0x1c18e
incq %r12
movq (%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r12
movq 0x8(%rsp), %r15
jl 0x1c117
movq (%r15), %rdi
testq %rdi, %rdi
je 0x1c21f
movq 0x10(%r15), %rsi
subq %rdi, %rsi
callq 0x2190
movl $0x18, %esi
movq %r15, %rdi
callq 0x2190
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
testl %edx, %edx
jle 0x1c27f
xorl %r15d, %r15d
cmpq %r15, %rdx
jbe 0x1c2e0
movq (%rdi,%r15,8), %rdi
testq %rdi, %rdi
je 0x1c25c
callq 0x2220
incq %r15
movq (%rsp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rax
subq %rdi, %rax
movq %rax, %rdx
sarq $0x3, %rdx
shrq $0x3, %rax
cltq
cmpq %rax, %r15
jl 0x1c245
testq %rdi, %rdi
je 0x1c294
movq (%rsp), %rax
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2190
movl $0x18, %esi
movq (%rsp), %rdi
callq 0x2190
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1161b(%rip), %rdi     # 0x2d8d6
movq %rbp, %rsi
jmp 0x1c2ca
leaq 0x1160f(%rip), %rdi     # 0x2d8d6
movq %r13, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2270
leaq 0x115fb(%rip), %rdi     # 0x2d8d6
movq %r13, %rsi
jmp 0x1c2cd
leaq 0x115ef(%rip), %rdi     # 0x2d8d6
movq %r15, %rsi
jmp 0x1c2cd
leaq 0x115e3(%rip), %rdi     # 0x2d8d6
movq %r12, %rsi
jmp 0x1c2cd