// File: gersteinlab[P]MUSIC/src/ms_annot_region_tools.cpp
// Function: sort_set_sorting_info(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, bool (*)(t_annot_region*, t_annot_region*))
void sort_set_sorting_info(vector<t_annot_region*>* regions, bool (sort_regions_callback)(t_annot_region*, t_annot_region*))
{
	// Set the sorting info for each region.
	if(regions->size() == 0)
	{
		return;
	}

	// Sort the regions.
	if(sort_regions_callback != NULL)
	{
		sort(regions->begin(), regions->end(), sort_regions_callback);
	}

		// Set the cumulative start positions for each region: Cumulative start from the end of the list.
	int current_cumulative_start = regions->back()->start;
	for(int i_reg = regions->size()-1; i_reg >= 0; i_reg--)
	{
		t_sorting_info* cur_reg_sorting_info = new t_sorting_info();
		if(current_cumulative_start > regions->at(i_reg)->start)
		{
			current_cumulative_start = regions->at(i_reg)->start;	
		}

		cur_reg_sorting_info->cumulative_sorted_start = current_cumulative_start;

		regions->at(i_reg)->sort_info = cur_reg_sorting_info;
	} // i_reg loop.

	// Set the cumulative end: Cumulative end from the beginning of the list.
	int current_cumulative_end = 0;
	for(int i_reg = 0; i_reg < (int)regions->size(); i_reg++)
	{
		//t_sorting_info* cur_reg_sorting_info = new t_sorting_info();
		t_sorting_info* cur_reg_sorting_info = regions->at(i_reg)->sort_info;
		if(current_cumulative_end < regions->at(i_reg)->end)
		{
			current_cumulative_end = regions->at(i_reg)->end;	
		}

		cur_reg_sorting_info->cumulative_sorted_end = current_cumulative_end;
	} // i_reg loop.
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rdi
callq 0xc680
cmpq $0x0, %rax
jne 0x28463
jmp 0x28618
cmpq $0x0, 0x58(%rsp)
je 0x2849d
movq 0x60(%rsp), %rdi
callq 0xc7d0
movq %rax, 0x50(%rsp)
movq 0x60(%rsp), %rdi
callq 0xc760
movq %rax, 0x48(%rsp)
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x31d00
movq 0x60(%rsp), %rdi
callq 0x1b3d0
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x44(%rsp)
movq 0x60(%rsp), %rdi
callq 0xc680
subq $0x1, %rax
movl %eax, 0x40(%rsp)
cmpl $0x0, 0x40(%rsp)
jl 0x28575
movl $0x8, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x18(%rsp)
xorl %esi, %esi
movl $0x8, %edx
callq 0x2110
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x24(%rsp)
movq 0x60(%rsp), %rdi
movslq 0x40(%rsp), %rsi
callq 0xc800
movq %rax, %rcx
movl 0x24(%rsp), %eax
movq (%rcx), %rcx
cmpl 0xc(%rcx), %eax
jle 0x28535
movq 0x60(%rsp), %rdi
movslq 0x40(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x44(%rsp)
movl 0x44(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, (%rax)
movq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x60(%rsp), %rdi
movslq 0x40(%rsp), %rsi
callq 0xc800
movq 0x10(%rsp), %rcx
movq (%rax), %rax
movq %rcx, 0x38(%rax)
movl 0x40(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x284c3
movl $0x0, 0x34(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0xc(%rsp)
movq 0x60(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0xc(%rsp), %eax
cmpl %ecx, %eax
jge 0x28618
movq 0x60(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movq 0x38(%rax), %rax
movq %rax, 0x28(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0xc800
movq %rax, %rcx
movl 0x8(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x20(%rcx), %eax
jge 0x285fc
movq 0x60(%rsp), %rdi
movslq 0x30(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %ecx
movq 0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x28585
addq $0x68, %rsp
retq
nopl (%rax)