// File: /workspace/github_cpp_makefile_star2_O2/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
movl %edx, %r12d
movq %rsi, 0x30(%rsp)
cvttsd2si %xmm1, %ebx
cvttsd2si %xmm0, %r14d
movq %rdi, 0x18(%rsp)
movl %ebx, %eax
subl %r14d, %eax
cltq
cmpl $-0x1, %eax
leaq 0x8(,%rax,8), %rdi
pushq $-0x1
popq %rcx
cmovlq %rcx, %rdi
leaq 0x4(,%rax,4), %r13
cmovlq %rcx, %r13
callq 0x2040
movq %rax, (%rsp)
movq %r13, %rdi
callq 0x2040
movq %rax, %r13
movslq %r14d, %rdx
movslq %ebx, %rbp
xorl %r15d, %r15d
pushq $0x18
popq %rbx
movq %rdx, 0x20(%rsp)
leaq (%rdx,%r15), %rax
cmpq %rbp, %rax
jg 0x191a3
movq %rbx, %rdi
callq 0x2170
movq 0x20(%rsp), %rdx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq (%rsp), %rcx
movq %rax, (%rcx,%r15,8)
andl $0x0, (%r13,%r15,4)
incq %r15
jmp 0x1916d
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
incl %r12d
movq %r12, 0x28(%rsp)
movl %r14d, %r14d
pushq $0x1
popq %r12
movq 0x18(%rsp), %rcx
cmpq 0x28(%rsp), %r12
je 0x1926d
leal -0x1(%r12), %eax
movl %eax, 0x14(%rsp)
xorl %r15d, %r15d
leaq (%rdx,%r15), %rax
cmpq %rbp, %rax
jg 0x19265
leal (%r14,%r15), %eax
cvtsi2sd %eax, %xmm0
movsd (%rcx,%r12,8), %xmm1
ucomisd %xmm0, %xmm1
movl (%r13,%r15,4), %ebx
jae 0x19254
testl %ebx, %ebx
je 0x1925d
callq 0x11e71
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x21062
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movl %ebx, 0xc(%rax)
movl 0x14(%rsp), %ecx
movl %ecx, 0x20(%rax)
movb $0x2b, 0x8(%rax)
andl $0x0, (%r13,%r15,4)
movq (%rsp), %rax
movq (%rax,%r15,8), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7448
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %rcx
jmp 0x1925d
testl %ebx, %ebx
jne 0x1925d
movl %r12d, (%r13,%r15,4)
incq %r15
jmp 0x191d7
incq %r12
jmp 0x191c0
movq %r13, %rdi
callq 0x2210
movq (%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq