// File: gersteinlab[P]MUSIC/src/ms_signal_track_tools.cpp
// Function: joint_prune_multiple_profiles_per_thresholds(double**, int, int, double*, int&)
double** joint_prune_multiple_profiles_per_thresholds(double** profiles, int n_profiles, int l_profile, double* threshold_per_profile, int& l_pruned_profile)
{
	// Go over all the profiles, find the regions.	
	double** pruned_profiles = new double*[n_profiles];
	for(int i_p = 0; i_p < n_profiles; i_p++)
	{
		pruned_profiles[i_p] = new double[l_profile+2];
	} // i_p loop.

	// Prune the columns.
	l_pruned_profile = 1;
	for(int i_sig = 1; i_sig <= l_profile; i_sig++)
	{
		bool include_cur_val = false;
		for(int i_p = 0; i_p < n_profiles; i_p++)
		{
			if(threshold_per_profile[i_p] <= -1000)
			{
				//fprintf(stderr, "Not using %d. profile for joint pruning.\n");
			}
			else if(profiles[i_p][i_sig] > threshold_per_profile[i_p])
			{
				include_cur_val = true;
			}
		} // i_p loop.

		if(include_cur_val)
		{
			// Add this columns to all the pruned profiles.
			for(int i_p = 0; i_p < n_profiles; i_p++)
			{
				// Copy the value.
				pruned_profiles[i_p][l_pruned_profile] = profiles[i_p][i_sig];
			} // i_p loop.	

			l_pruned_profile++;
		}
	} // i_sig loop.

	// Pruned profiles are indexed 1 based.
	l_pruned_profile--;

	return(pruned_profiles);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movl %esi, 0x3c(%rsp)
movl %edx, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %r8, 0x28(%rsp)
movslq 0x3c(%rsp), %rax
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, 0x20(%rsp)
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x34900
movl 0x38(%rsp), %eax
addl $0x2, %eax
cltq
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2040
movq %rax, %rdx
movq 0x20(%rsp), %rax
movslq 0x1c(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x348ae
movq 0x28(%rsp), %rax
movl $0x1, (%rax)
movl $0x1, 0x18(%rsp)
movl 0x18(%rsp), %eax
cmpl 0x38(%rsp), %eax
jg 0x34a09
movb $0x0, 0x17(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x34992
movq 0x30(%rsp), %rax
movslq 0x10(%rsp), %rcx
movsd 0x219ae(%rip), %xmm0    # 0x562f8
ucomisd (%rax,%rcx,8), %xmm0
jb 0x34953
jmp 0x34983
movq 0x40(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x30(%rsp), %rax
movslq 0x10(%rsp), %rcx
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x34981
movb $0x1, 0x17(%rsp)
jmp 0x34983
jmp 0x34985
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x3492e
testb $0x1, 0x17(%rsp)
je 0x349f7
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x349eb
movq 0x40(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0x18(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x20(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x28(%rsp), %rcx
movslq (%rcx), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x349a1
movq 0x28(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x349f9
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x34913
movq 0x28(%rsp), %rax
movl (%rax), %ecx
addl $-0x1, %ecx
movl %ecx, (%rax)
movq 0x20(%rsp), %rax
addq $0x48, %rsp
retq
nop