// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_filter_utils.cpp
// Function: get_filtered_maxima_regions_multiscale_filtered_data(double*, int, double, double, double, std::vector<double, std::allocator<double>>*, std::vector<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, std::allocator<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*>>*, double)
void get_filtered_maxima_regions_multiscale_filtered_data(double* track_data, 
														int l_track_data, 
														double scale_start, double scale_end, double log_scale_step, 
														vector<double>* scales_per_i_scale,
														vector<vector<t_annot_region*>*>* per_scale_minima_regions,
														double min_allowed_filtered_value_scale)
{
	// Start from the first scale, go over all the scales and filter the data.
	double scale = 1.0 / log_scale_step;
	int i_scale = 0;

	// Define where which quantile we set as the signal.
	double quantile = 0.5;

	FILE* f_feature_signal_vals = NULL;

if(__DUMP_FILTER_MSGS__)
	f_feature_signal_vals = open_f("features_signal_values.bed", "w");

	while(1)
	{
		scale *= log_scale_step;

		scales_per_i_scale->push_back(scale);

		// Are we going to process a scale within the requested limits? If not, we will skip this computation to save time.
		if(scale < scale_start)
		{
			i_scale++;
			per_scale_minima_regions->push_back(new vector<t_annot_region*>());
			continue;
		}
		else
		{
//if(__DUMP_FILTER_MSGS__)
//{
			//fprintf(stderr, "Processing scale %.2f (%.2f)\n", scale, scale_end);
			fprintf(stderr, "Generating ERs @ scale with %d/%d bins.                      \r", (int)scale, (int)scale_end);
//}

			// Get the filter for the current scale: The gaussian filter.
			int int_scale = (int)(scale);
			int l_averaging_win = ((int_scale % 2) == 1)?(int_scale-1):(int_scale);

			// Do copying from start to end.
			double* cur_filtered_track = new double[l_track_data + 2];
			memset(cur_filtered_track, 0, (l_track_data+1)*sizeof(double));

			int n_signal_wins = 0;
			int half_l_averaging = l_averaging_win / 2;

			// Set the maximum value for the histogram.
			int MAX_VAL = -1000*1000;
			int MIN_VAL = 1000*1000;
			for(int i_sig = 1; i_sig <= l_track_data; i_sig++)
			{
				if(MAX_VAL < (int)(track_data[i_sig]))
				{
					MAX_VAL = (int)(track_data[i_sig]);
				}

				if(MIN_VAL > (int)(track_data[i_sig]))
				{
					MIN_VAL = (int)(track_data[i_sig]);
				}
			} // i_sig loop.

			// Make sure that this is the maximum.
			MAX_VAL += 100;
			MIN_VAL -= 100;
		
			// Initialize the current pdf.
			int* cur_win_pdf = NULL;
			int cur_win_max = 0;
			int cur_win_min = 1000*1000;
			double* cur_win_vals = new double[l_averaging_win + 2];
			int prev_avg_start = 0;
			int prev_avg_end = 0;

			// Go over all the positions as the middle of the filtering window: This must be 1 based.
			for(int cur_win_mid = 1; cur_win_mid <= l_track_data; cur_win_mid++)
			{
				int cur_avg_start = (cur_win_mid > half_l_averaging)?(cur_win_mid - half_l_averaging):(1);
				int cur_avg_end = (cur_win_mid + half_l_averaging <= l_track_data)?(cur_win_mid + half_l_averaging):(l_track_data);
				if(cur_win_pdf == NULL)
				{
					cur_win_pdf = new int[MAX_VAL - MIN_VAL+ 2];
					memset(cur_win_pdf, 0, sizeof(int) * (MAX_VAL - MIN_VAL + 1));
					cur_win_pdf -= MIN_VAL;

					// Generate the pdf, get the minimum and maximum in the current window.
					for(int i = cur_avg_start; i <= cur_avg_end; i++)
					{
						cur_win_pdf[(int)(track_data[i])]++;

						if(cur_win_max < track_data[i])
						{
							cur_win_max = (int)track_data[i];
						}
					
						if(cur_win_min > track_data[i])
						{
							cur_win_min = (int)track_data[i];
						}
					} // i loop.
				} // cur_win_pdf is NULL check.
				else
				{
					// Remove the old values from the pdf, add the new values.
					for(int i = prev_avg_start; i < cur_avg_start; i++)
					{
						cur_win_pdf[(int)(track_data[i])]--;
					} // i loop.

					// Update the min and max only for the values that are new in this window.
					for(int i = prev_avg_end+1; i <= cur_avg_end; i++)
					{
						cur_win_pdf[(int)(track_data[i])]++;

						if(cur_win_max < track_data[i])
						{
							cur_win_max = (int)track_data[i];
						}
					
						if(cur_win_min > track_data[i])
						{
							cur_win_min = (int)track_data[i];
						}
					}

					// Sanity Check: The total # of points must be equal to the window length.
					int n_total_pts = 0;
					for(int i = cur_win_min; i <= cur_win_max; i++)
					{
						n_total_pts += cur_win_pdf[i];
					} // i loop.

					// Sanity check on the number of points to be processed in the current window.
					if(n_total_pts != (cur_avg_end - cur_avg_start + 1))
					{
						fprintf(stderr, "Sanity check failed at %d-%d (%d-%d): %d, %d\n", cur_avg_start, cur_avg_end, cur_win_min, cur_win_max, n_total_pts, (cur_avg_end - cur_avg_start + 1));

						for(int i = cur_win_min; i <= cur_win_max; i++)
						{
							fprintf(stderr, "%d ", cur_win_pdf[i]);
						} // i loop.

						FILE* f_op = open_f("op.txt", "w");
						for(int i_sig = cur_avg_start; i_sig <= cur_avg_end; i_sig++)
						{
							fprintf(f_op, "%lf ", track_data[i_sig]);
						} // i_sig loop.
						fclose(f_op);

						exit(0);
					}
				} // cur_win_pdf is NULL check.

				// At this point, the histogram is updated, now must find the median for the histogram.
				int n_total = 0;
				int cur_win_median = 0;
				for(int i = cur_win_min; i <= cur_win_max; i++)
				{
					n_total += cur_win_pdf[i];

					if(n_total > (cur_avg_end - cur_avg_start + 1)*quantile)
					{
						// We found the median, can break out of the loop.
						cur_win_median = i;
						break;
					}
				} // i loop.

				// Track the minimum and maximum from the histogram to update them for the current window.
				int updated_win_min = 0;			
				for(int i = cur_win_min; i <= cur_win_max; i++)
				{
					if(cur_win_pdf[i] > 0)
					{
						updated_win_min = i;
						break;
					}
				} // i loop.

				int updated_win_max = 0;
				for(int i = cur_win_max; i >= cur_win_min; i--)
				{
					if(cur_win_pdf[i] > 0)
					{
						updated_win_max = i;
						break;
					}
				} // i loop.

				// Set the median.
				//int median_per_pdf = cur_win_median;
				cur_filtered_track[cur_win_mid] = cur_win_median;

				// Update the previous averaging window limits.
				prev_avg_start = cur_avg_start;
				prev_avg_end = cur_avg_end;
				cur_win_min = updated_win_min;
				cur_win_max = updated_win_max;

#undef _QSORT_CHECK_
#ifdef _QSORT_CHECK_
				// Get the median via qsort and compare as a sanity check.
				for(int i = cur_avg_start; i <= cur_avg_end; i++)
				{
					cur_win_vals[i-cur_avg_start] = track_data[i];
				} // i loop.
				qsort(cur_win_vals, l_averaging_win, sizeof(double), sort_doubles_descending);
				//per_win_profile[n_signal_wins] = cur_win_vals[l_averaging_win/2];

				if(cur_win_vals[l_averaging_win/2] != median_per_pdf)
				{
					fprintf(stderr, "Medians do not match: %d, %d:\n", (int)cur_win_vals[l_averaging_win/2], median_per_pdf);
					for(int i = cur_avg_start; i <= cur_avg_end; i++)
					{
						fprintf(stderr, "%lf ", track_data[i]);
					} // i loop.
					fprintf(stderr, "\n");
					getc(stdin);
				}
#endif // _QSORT_CHECK_

				n_signal_wins++;
			} // main signal filtering loop.

			// Free pdf memory.
			delete [] cur_win_vals;
			delete [] (cur_win_pdf+MIN_VAL);

if(__DUMP_FILTER_MSGS__)
{
			fprintf(stderr, "Getting the extrema regions.\n");
}

			// Get the extrema regions for the current filtered regions.
			vector<t_extrema_node*>* maxima = new vector<t_extrema_node*>();
			vector<t_extrema_node*>* minima = new vector<t_extrema_node*>();
			int* derivative_map = new int[l_track_data+2];
			memset(derivative_map, 0, sizeof(int) * (l_track_data+2));
			get_extrema_per_plateaus(cur_filtered_track, l_track_data, maxima, minima, derivative_map, 0);

			// Sort the extremas.
			sort(minima->begin(), minima->end(), sort_extremas_per_posn);
			sort(maxima->begin(), maxima->end(), sort_extremas_per_posn);

			// Get the minima regions.
			vector<t_annot_region*>* cur_scale_minima_regions = new vector<t_annot_region*>();

if(__DUMP_FILTER_MSGS__)
{
			fprintf(stderr, "Generating filtered minima regions from %d minima.\n", (int)minima->size());
}

			for(int i_m = 0; 
				minima->size() > 0 &&
				i_m < (int)minima->size()-1; 
				i_m++)
			{
				t_annot_region* new_minima = get_empty_region();
				new_minima->chrom = t_string::copy_me_str("XX");
				//new_minima->start = translate_coord(minima->at(i_m)->extrema_posn+1, CODEBASE_COORDS::start_base, BED_COORDS::start_base);
				//new_minima->end = translate_coord(minima->at(i_m+1)->extrema_posn+1, CODEBASE_COORDS::end_base, BED_COORDS::end_base);
				new_minima->start = minima->at(i_m)->extrema_posn;
				new_minima->end = minima->at(i_m+1)->extrema_posn;
				new_minima->strand = '+';

				// The maximum in the original signal is found within the effective data that contributes to the filtering process.
				int i_eff_data_start = (1 > new_minima->start-(int)scale/2)?(1):(new_minima->start-(int)scale/2);
				int i_eff_data_end = (l_track_data < new_minima->end+scale/2)?(l_track_data):(new_minima->end+(int)scale/2);
				double original_max = 0.0;
				for(int i = i_eff_data_start; i <= i_eff_data_end; i++)
				{
					if(original_max < track_data[i])
					{
						original_max = track_data[i];
					}
				}

				double filtered_max = 0.0;
				for(int i = new_minima->start; i <= new_minima->end; i++)
				{
					if(filtered_max < cur_filtered_track[i])
					{
						filtered_max = cur_filtered_track[i];
					}
				} // i loop.

if(__DUMP_FILTER_MSGS__)
{
				fprintf(f_feature_signal_vals, "XX\t%d\t%d\t%lf\t%lf\t%lf\n", new_minima->start, new_minima->end, filtered_max, original_max, scale);
}

				// This is where the filtering is done.
				if(filtered_max >= original_max / min_allowed_filtered_value_scale)
				{
					cur_scale_minima_regions->push_back(new_minima);
				}
				else
				{					
					delete new_minima;
				}
			} // i_min loop.

if(__DUMP_FILTER_MSGS__)
{
			fprintf(stderr, "%ld minima regions are generated.\n", cur_scale_minima_regions->size());
}

			per_scale_minima_regions->push_back(cur_scale_minima_regions);

			delete_extrema_nodes(minima);
			delete_extrema_nodes(maxima);

if(__DUMP_FILTER_MSGS__)
{
			// Dump the current filtered track.
			char cur_filtered_data_op_fp[1000];
			sprintf(cur_filtered_data_op_fp, "filtered_%lf.bin", scale);
			dump_per_nucleotide_binary_profile(cur_filtered_track, l_track_data, cur_filtered_data_op_fp);
}

			// Free the current decomposition.
			delete [] derivative_map;
			delete [] cur_filtered_track;

			// Was the last processed value equal to or larger than what was requested?
			if(scale_end > 0 && 
				scale >= scale_end)
			{
				break;
			}

			i_scale++;
		} // scale computation check.
	} // scale loop.
	fprintf(stderr, "Generated SSERs for %d scales.                                \n", (int)scales_per_i_scale->size());

if(__DUMP_FILTER_MSGS__)
		fclose(f_feature_signal_vals);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4b8, %rsp            # imm = 0x4B8
movsd %xmm3, 0xc8(%rsp)
movq %rcx, %r13
movq %rdx, %r14
movsd %xmm2, 0x50(%rsp)
movsd %xmm1, 0x30(%rsp)
movsd %xmm0, 0xa0(%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
movsd 0x12ff8(%rip), %xmm1    # 0x24008
cmpb $0x1, 0x241ae(%rip)     # 0x351c5
jne 0x1103b
leaq 0x1674f(%rip), %rdi     # 0x2776f
leaq 0x13a81(%rip), %rsi     # 0x24aa8
callq 0x2027c
movsd 0x12fd4(%rip), %xmm1    # 0x24008
movq %rax, 0x38(%rsp)
jmp 0x11044
movq $0x0, 0x38(%rsp)
cvttsd2si 0x30(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4(%rsp), %ecx
cmpl $-0x2, %ecx
movslq %ecx, %rax
leaq 0x10(,%rax,8), %rdx
pushq $-0x1
popq %rsi
cmovlq %rsi, %rdx
movq %rdx, 0x98(%rsp)
divsd 0x50(%rsp), %xmm1
leaq 0x8(,%rax,8), %rdx
movq %rdx, 0x90(%rsp)
leaq 0x8(,%rax,4), %rdx
movq %rdx, 0x68(%rsp)
cmovlq %rsi, %rdx
movq %rdx, 0x60(%rsp)
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0xc0(%rsp)
testl %eax, %eax
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, 0x88(%rsp)
incl %eax
movq %rax, 0x58(%rsp)
leaq 0x10(%rsp), %r15
movq %r14, 0x78(%rsp)
movq %r13, 0x70(%rsp)
mulsd 0x50(%rsp), %xmm1
movsd %xmm1, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x7426
movsd 0x10(%rsp), %xmm0
movsd 0xa0(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x11131
pushq $0x18
popq %rdi
callq 0x2170
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rax, 0xd0(%rsp)
movq %r13, %rdi
leaq 0xd0(%rsp), %rsi
callq 0x11b96
movsd 0x10(%rsp), %xmm1
jmp 0x110d0
movq 0x23ea8(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
cvttsd2si %xmm0, %edx
leaq 0x16644(%rip), %rsi     # 0x2778a
movl 0x4c(%rsp), %ecx
xorl %eax, %eax
callq 0x2240
cvttsd2si 0x10(%rsp), %r14d
movl %r14d, %eax
andl $0x80000001, %eax       # imm = 0x80000001
xorl %ebp, %ebp
cmpl $0x1, %eax
sete %bpl
negl %ebp
movq 0x98(%rsp), %rdi
callq 0x2040
movq %rax, 0x18(%rsp)
movq %rax, %rdi
xorl %esi, %esi
movq 0x90(%rsp), %rdx
callq 0x20f0
movl $0xfff0bdc0, %esi       # imm = 0xFFF0BDC0
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %eax, %eax
movq 0x88(%rsp), %rdi
cmpq %rax, %rdi
je 0x111bd
cvttsd2si 0x8(%rbx,%rax,8), %edx
cmpl %edx, %esi
cmovlel %edx, %esi
cmpl %edx, %ecx
cmovgel %edx, %ecx
incq %rax
jmp 0x111a3
addl %r14d, %ebp
movl %ebp, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
subl %ecx, %esi
addl $-0x64, %ecx
leal 0xc8(%rsi), %edx
leal 0xca(%rsi), %edi
movslq %edi, %rdi
shlq $0x2, %rdi
cmpl $-0x2, %edx
pushq $-0x1
popq %rdx
cmovlq %rdx, %rdi
movq %rdi, 0xb0(%rsp)
addl $0xc9, %esi
movslq %esi, %rdx
shlq $0x2, %rdx
movq %rdx, 0xb8(%rsp)
movslq %ecx, %rdx
movq %rdx, 0x80(%rsp)
negq %rdx
movq %rdx, 0xa8(%rsp)
movslq %eax, %r9
movl $0xf4240, %r11d         # imm = 0xF4240
xorl %eax, %eax
pushq $0x1
popq %r14
xorl %ecx, %ecx
xorl %ebp, %ebp
xorl %r8d, %r8d
movq 0x58(%rsp), %rsi
movq 0x18(%rsp), %rdi
cmpq %rsi, %r14
je 0x11423
movq %r11, 0x8(%rsp)
movl %r14d, %r10d
subl %r9d, %r10d
cmpq %r9, %r14
pushq $0x1
popq %rdx
cmovlel %edx, %r10d
leal (%r9,%r14), %r11d
movl 0x4(%rsp), %edx
cmpl %edx, %r11d
cmovgel %edx, %r11d
movslq %r11d, %r13
testq %r8, %r8
movl %r11d, 0x28(%rsp)
je 0x1130b
movslq %r10d, %r12
movslq %ecx, %rcx
cmpq %r12, %rcx
jge 0x11297
cvttsd2si (%rbx,%rcx,8), %edx
movslq %edx, %rdx
decl (%r8,%rdx,4)
incq %rcx
jmp 0x11281
cltq
cmpq %r13, %rax
jge 0x112d4
movsd 0x8(%rbx,%rax,8), %xmm0
incq %rax
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
incl (%r8,%rcx,4)
cvtsi2sd %ebp, %xmm1
ucomisd %xmm1, %xmm0
cmoval %ecx, %ebp
movq 0x8(%rsp), %rdx
cvtsi2sd %edx, %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %edx
movq %rdx, 0x8(%rsp)
jmp 0x11299
movl %r10d, %edx
movslq 0x8(%rsp), %r15
movl %ebp, 0x20(%rsp)
movslq %ebp, %rbp
xorl %r10d, %r10d
movq %r15, %rax
cmpq %rbp, %rax
jg 0x112f7
addl (%r8,%rax,4), %r10d
incq %rax
jmp 0x112e9
subl %edx, %r11d
incl %r11d
cmpl %r11d, %r10d
je 0x113ab
jmp 0x117f2
movq %r14, 0x20(%rsp)
movq %r9, %r14
movq 0xb0(%rsp), %rdi
movl %ebp, %r15d
movl %r10d, %ebp
callq 0x2040
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq 0xb8(%rsp), %rdx
callq 0x20f0
movl 0x28(%rsp), %esi
movl %ebp, %edx
movl %r15d, %r9d
movq 0xa8(%rsp), %rax
leaq (%r12,%rax,4), %r8
movslq %ebp, %rax
movq 0x8(%rsp), %rdi
cmpq %r13, %rax
jg 0x1138a
movsd (%rbx,%rax,8), %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
incl (%r8,%rcx,4)
cvtsi2sd %r9d, %xmm1
ucomisd %xmm1, %xmm0
cmoval %ecx, %r9d
cvtsi2sd %edi, %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %edi
incq %rax
jmp 0x11358
movl %esi, %r11d
subl %edx, %r11d
incl %r11d
movslq %edi, %r15
movslq %r9d, %rbp
movq 0x58(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq %r14, %r9
movq 0x20(%rsp), %r14
cvtsi2sd %r11d, %xmm0
mulsd 0x12ca0(%rip), %xmm0    # 0x24058
xorl %ecx, %ecx
movq %r15, %rax
movl 0x28(%rsp), %r10d
cmpq %rbp, %rax
jg 0x113da
addl (%r8,%rax,4), %ecx
cvtsi2sd %ecx, %xmm1
ucomisd %xmm0, %xmm1
ja 0x113e0
incq %rax
jmp 0x113c2
xorpd %xmm0, %xmm0
jmp 0x113e4
cvtsi2sd %eax, %xmm0
movq %r15, %r11
cmpq %rbp, %r11
jg 0x113f8
cmpl $0x0, (%r8,%r11,4)
jg 0x113fb
incq %r11
jmp 0x113e7
xorl %r11d, %r11d
cmpq %r15, %rbp
jl 0x1140c
cmpl $0x0, (%r8,%rbp,4)
jg 0x11410
decq %rbp
jmp 0x113fb
xorl %ebp, %ebp
jmp 0x11410
movsd %xmm0, (%rdi,%r14,8)
incq %r14
movl %r10d, %eax
movl %edx, %ecx
jmp 0x1123d
testq %r8, %r8
je 0x11439
movq 0x80(%rsp), %rax
leaq (%r8,%rax,4), %rdi
callq 0x2210
cmpb $0x1, 0x23d85(%rip)     # 0x351c5
movq 0x78(%rsp), %r14
jne 0x11463
movq 0x23b92(%rip), %rax     # 0x34fe0
movq (%rax), %rcx
leaq 0x16231(%rip), %rdi     # 0x27689
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2330
pushq $0x18
popq %r13
movq %r13, %rdi
callq 0x2170
movq %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %r13, %rdi
callq 0x2170
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x60(%rsp), %rdi
callq 0x2040
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
movq 0x68(%rsp), %rdx
callq 0x20f0
movq 0x18(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %r12, %rdx
movq %r15, %rcx
movq %rbp, 0x20(%rsp)
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x1ea88
movq (%r15), %rdi
movq 0x8(%r15), %rsi
leaq 0xd59d(%rip), %rbp      # 0x1ea7d
movq %rbp, %rdx
callq 0xd2d0
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %rbp, %rdx
callq 0xd2d0
movq %r13, %rdi
callq 0x2170
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, 0x40(%rsp)
cmpb $0x1, 0x23cab(%rip)     # 0x351c5
jne 0x1153f
movq 0x23abd(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movq 0x8(%r15), %rdx
subq (%r15), %rdx
shrq $0x3, %rdx
leaq 0x16291(%rip), %rsi     # 0x277c9
xorl %eax, %eax
callq 0x2240
xorl %ebp, %ebp
leaq 0xd0(%rsp), %r13
movq 0x8(%r15), %rax
movq (%r15), %rcx
subq %rcx, %rax
je 0x116df
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
cmpq %rax, %rbp
jge 0x116df
callq 0x11e71
movq %rax, 0xd0(%rsp)
leaq 0x1616f(%rip), %rdi     # 0x276fa
callq 0x21062
movq 0xd0(%rsp), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %eax
movq 0xd0(%rsp), %rcx
movl %eax, 0xc(%rcx)
incq %rbp
movq %r15, %rdi
movq %rbp, %rsi
callq 0xcfc8
movq (%rax), %rax
movslq (%rax), %rcx
movq 0xd0(%rsp), %rax
movl %ecx, 0x20(%rax)
movb $0x2b, 0x8(%rax)
movslq 0xc(%rax), %r8
movsd 0x10(%rsp), %xmm2
cvttsd2si %xmm2, %edi
movl %edi, %eax
cltd
pushq $-0x2
popq %rsi
idivl %esi
movl %eax, %esi
addl %r8d, %esi
cmpl $0x2, %esi
pushq $0x1
popq %rax
cmovll %eax, %esi
cvtsi2sd %ecx, %xmm0
movapd %xmm2, %xmm1
mulsd 0x12a4b(%rip), %xmm1    # 0x24058
addsd %xmm0, %xmm1
ucomisd 0xc0(%rsp), %xmm1
movl 0x4(%rsp), %eax
ja 0x1162a
movl %edi, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
addl %ecx, %eax
movl %esi, %edx
cltq
xorpd %xmm1, %xmm1
movq 0x18(%rsp), %rsi
cmpq %rax, %rdx
jg 0x1164e
movsd (%rbx,%rdx,8), %xmm0
maxsd %xmm1, %xmm0
incq %rdx
movapd %xmm0, %xmm1
jmp 0x11637
xorpd %xmm0, %xmm0
movq %r8, %rax
cmpq %rcx, %rax
jg 0x1166c
movsd (%rsi,%rax,8), %xmm3
maxsd %xmm0, %xmm3
incq %rax
movapd %xmm3, %xmm0
jmp 0x11655
cmpb $0x0, 0x23b52(%rip)     # 0x351c5
je 0x116a9
movq 0x38(%rsp), %rdi
leaq 0x1617c(%rip), %rsi     # 0x277fd
movl %r8d, %edx
movsd %xmm1, 0x8(%rsp)
movsd 0x8(%rsp), %xmm1
movb $0x3, %al
movsd %xmm0, 0x28(%rsp)
callq 0x2240
movsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
divsd 0xc8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jae 0x116cd
movq 0xd0(%rsp), %rdi
pushq $0x50
popq %rsi
callq 0x2180
jmp 0x11549
movq 0x40(%rsp), %rdi
movq %r13, %rsi
callq 0x7448
jmp 0x11549
cmpb $0x0, 0x23adf(%rip)     # 0x351c5
je 0x11710
movq 0x238f1(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdx
subq (%rax), %rdx
sarq $0x3, %rdx
leaq 0x1610a(%rip), %rsi     # 0x27813
xorl %eax, %eax
callq 0x2240
movq 0x70(%rsp), %r13
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
callq 0xcfaa
movq %r15, %rdi
callq 0x1f2b3
movq %r12, %rdi
callq 0x1f2b3
cmpb $0x1, 0x23a8c(%rip)     # 0x351c5
leaq 0x10(%rsp), %r15
jne 0x11770
movsd 0x10(%rsp), %xmm0
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
leaq 0x160de(%rip), %rsi     # 0x27836
movb $0x1, %al
callq 0x2080
movq 0x18(%rsp), %rdi
movl 0x4(%rsp), %esi
movq %r12, %rdx
callq 0x18dfd
movq 0x20(%rsp), %rdi
callq 0x2210
movq 0x18(%rsp), %rdi
callq 0x2210
movsd 0x30(%rsp), %xmm0
ucomisd 0x1291e(%rip), %xmm0    # 0x240b0
movsd 0x10(%rsp), %xmm1
jbe 0x110d0
ucomisd 0x30(%rsp), %xmm1
jb 0x110d0
movq 0x2382f(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movq 0x8(%r14), %rdx
subq (%r14), %rdx
shrq $0x3, %rdx
leaq 0x16081(%rip), %rsi     # 0x27847
xorl %eax, %eax
callq 0x2240
cmpb $0x1, 0x239f1(%rip)     # 0x351c5
jne 0x117e0
movq 0x38(%rsp), %rdi
callq 0x2160
addq $0x4b8, %rsp            # imm = 0x4B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r14
movq 0x237e4(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x15f15(%rip), %rsi     # 0x2771b
movl 0x28(%rsp), %ecx
movq 0x8(%rsp), %r8
movl 0x20(%rsp), %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x2240
addq $0x10, %rsp
cmpq %rbp, %r15
jg 0x11849
movq 0x237b1(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movl (%r14,%r15,4), %edx
leaq 0x15f0c(%rip), %rsi     # 0x27749
xorl %eax, %eax
callq 0x2240
incq %r15
jmp 0x11823
leaq 0x16f0c(%rip), %rdi     # 0x2875c
leaq 0x13251(%rip), %rsi     # 0x24aa8
callq 0x2027c
movq %rax, %r14
leaq 0x15ee7(%rip), %r15     # 0x2774d
cmpq %r13, %r12
jg 0x11883
movsd (%rbx,%r12,8), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x2240
incq %r12
jmp 0x11866
movq %r14, %rdi
callq 0x2160
xorl %edi, %edi
callq 0x21d0