// File: /workspace/github_cpp_makefile_star2_O1/gersteinlab[P]MUSIC/src/ms_signal_track_tools.cpp
// Function: get_peaks_per_per_nucleotide_signal_profile(double*, char*, int, double, double)
vector<t_annot_region*>** get_peaks_per_per_nucleotide_signal_profile(double* signal_profile, char* chrom, int l_data, double min_thresh, double max_thresh)
{
	// Allocate the states of peaks at each position.
	vector<t_annot_region*>** peaks_per_threshes = new vector<t_annot_region*>*[(int)max_thresh-(int)min_thresh+1];
	int* peak_starts = new int[(int)max_thresh-(int)min_thresh+1];
	for(int thresh = (int)min_thresh; thresh <= (int)max_thresh; thresh++)
	{
		peaks_per_threshes[thresh-(int)min_thresh] = new vector<t_annot_region*>();
		peak_starts[thresh-(int)min_thresh] = 0;
	} // thresh loop.

	for(int i = 1; i <= l_data; i++)
	{
		for(int thresh = (int)min_thresh; thresh <= (int)max_thresh; thresh++)
		{
			if(signal_profile[i] >= thresh)
			{
				// The signal is below the threshold.
				if(peak_starts[thresh-(int)min_thresh] == 0)
				{
					// Set a new peak start.
					peak_starts[thresh-(int)min_thresh] = i;
				}
				else
				{
					// This was a peak already.
				}
			}
			else
			{
				// The signal is below the threshold.
				if(peak_starts[thresh-(int)min_thresh] != 0)
				{
					// Add this as a peak.
					t_annot_region* new_peak = get_empty_region();
					new_peak->chrom = t_string::copy_me_str(chrom);
					new_peak->start = peak_starts[thresh-(int)min_thresh];
					new_peak->end = i-1;
					new_peak->strand = '+';

					// Set the current start at this threshold to 0; no peak.
					peak_starts[thresh-(int)min_thresh] = 0;

					// Add the new peak.
					peaks_per_threshes[thresh-(int)min_thresh]->push_back(new_peak);
				}
				else
				{
				// This was not a peak already.
				}
			}
		} // thresh loop.
	} // i loop.

	delete [] peak_starts;

	return(peaks_per_threshes);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, 0x10(%rsp)
movq %rsi, 0x30(%rsp)
cvttsd2si %xmm1, %ebx
cvttsd2si %xmm0, %ebp
movq %rdi, %r15
movl %ebx, %eax
subl %ebp, %eax
cltq
cmpl $-0x1, %eax
leaq 0x8(,%rax,8), %rdi
movq $-0x1, %rcx
cmovlq %rcx, %rdi
leaq 0x4(,%rax,4), %r13
cmovlq %rcx, %r13
callq 0x2040
movq %rax, %r12
movq %r13, %rdi
callq 0x2040
movq %rax, %r13
movl %ebx, 0xc(%rsp)
movl %ebp, 0x8(%rsp)
subl %ebp, %ebx
jl 0x1dc4e
incl %ebx
xorl %r14d, %r14d
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, (%r12,%r14,8)
movl $0x0, (%r13,%r14,4)
incq %r14
cmpl %r14d, %ebx
jne 0x1dc1f
movq %r12, 0x28(%rsp)
cmpl $0x0, 0x10(%rsp)
jle 0x1dd46
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movl 0x8(%rsp), %ebx
movl 0xc(%rsp), %eax
movl %eax, %ebp
notl %ebp
addq %rbx, %rbp
movl $0x1, %r14d
movl 0x8(%rsp), %eax
cmpl %eax, 0xc(%rsp)
jl 0x1dd38
leal -0x1(%r14), %eax
movl %eax, 0x24(%rsp)
xorl %r12d, %r12d
movsd (%r15,%r14,8), %xmm0
leal (%rbx,%r12), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
ucomisd %xmm1, %xmm0
jae 0x1dd11
cmpl $0x0, (%r13,%r12,4)
je 0x1dd2a
callq 0x15990
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rdi
callq 0x273e0
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movl (%r13,%r12,4), %ecx
movq 0x18(%rsp), %rax
movl %ecx, 0xc(%rax)
movl 0x24(%rsp), %ecx
movl %ecx, 0x20(%rax)
movb $0x2b, 0x8(%rax)
movl $0x0, (%r13,%r12,4)
movq 0x28(%rsp), %rcx
movq (%rcx,%r12,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x1dd20
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x1dd2a
cmpl $0x0, (%r13,%r12,4)
jne 0x1dd2a
movl %r14d, (%r13,%r12,4)
jmp 0x1dd2a
leaq 0x18(%rsp), %rdx
callq 0xb976
incq %r12
movl %ebp, %eax
addl %r12d, %eax
jne 0x1dc98
incq %r14
cmpq 0x10(%rsp), %r14
jne 0x1dc7f
movq %r13, %rdi
callq 0x2220
movq 0x28(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq