// File: gersteinlab[P]MUSIC/src/ms_signal_track_tools.cpp
// Function: exclude_regions_from_signal_profiles(double*, int, std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, double*, int&)
void exclude_regions_from_signal_profiles(double* signal_profile, int l_profile, vector<t_annot_region*>* regions_2_exclude, double* pruned_signal_profile, int& l_pruned_profile)
{
	sort(regions_2_exclude->begin(), regions_2_exclude->end(), sort_regions);

	bool* exclusion_profile = new bool[l_profile+2];
	for(int i = 1; i <= l_profile; i++)
	{
		exclusion_profile[i] = false;
	} // i loop.

	for(int i_reg = 0; i_reg < (int)regions_2_exclude->size(); i_reg++)
	{
		for(int i = regions_2_exclude->at(i_reg)->start; i <= regions_2_exclude->at(i_reg)->end; i++)
		{
			if(i <= l_profile)
			{
				exclusion_profile[i] = true;
			}
		} // i loop.
	} // i_reg loop.

	l_pruned_profile = 1;

	for(int i = 1; i <= l_profile; i++)
	{
		if(exclusion_profile[i])
		{
		}
		else
		{
			pruned_signal_profile[l_pruned_profile] = signal_profile[i];
			l_pruned_profile++;
		}
	} // i loop.

	// Must move the pruned profile index back by one.
	l_pruned_profile--;

	fprintf(stderr, "Pruned the signal of %d values to %d values.\n", l_profile, l_pruned_profile);
	delete [] exclusion_profile;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movl %esi, 0x5c(%rsp)
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r8, 0x40(%rsp)
movq 0x50(%rsp), %rdi
callq 0xc7d0
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rdi
callq 0xc760
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
movq 0x30(%rsp), %rsi
leaq -0xaf4b(%rip), %rdx     # 0x2a3a0
callq 0x31d00
movl 0x5c(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rdi
callq 0x2040
movq %rax, 0x28(%rsp)
movl $0x1, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jg 0x35331
movq 0x28(%rsp), %rax
movslq 0x24(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x3530c
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
jge 0x353ce
movq 0x50(%rsp), %rdi
movslq 0x20(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movslq 0x20(%rsp), %rsi
callq 0xc800
movq %rax, %rcx
movl 0x10(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x20(%rcx), %eax
jg 0x353bc
movl 0x1c(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jg 0x353ad
movq 0x28(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0x353af
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x3536f
jmp 0x353be
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x35339
movq 0x40(%rsp), %rax
movl $0x1, (%rax)
movl $0x1, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jg 0x35439
movq 0x28(%rsp), %rax
movslq 0x18(%rsp), %rcx
testb $0x1, (%rax,%rcx)
je 0x353fd
jmp 0x3542a
movq 0x60(%rsp), %rax
movslq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
movslq (%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq 0x40(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x3542c
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x353e1
movq 0x40(%rsp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq 0x2fb94(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
movl 0x5c(%rsp), %edx
movq 0x40(%rsp), %rax
movl (%rax), %ecx
leaq 0x2101d(%rip), %rsi     # 0x5647e
movb $0x0, %al
callq 0x2250
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x35482
movq 0x8(%rsp), %rdi
callq 0x2220
addq $0x68, %rsp
retq
nopw (%rax,%rax)