// File: /workspace/github_cpp_makefile_star2_O2/gersteinlab[P]MUSIC/src/ms_filter_utils.cpp
// Function: multiscale_median_filter_data(double*, int, double, double, double, std::vector<double, std::allocator<double>>*, bool, bool, bool, bool, std::vector<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, std::allocator<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*>>*, std::vector<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, std::allocator<std::vector<t_annot_region*, std::allocator<t_annot_region*>>*>>*, char const*)
vector<double*>* multiscale_median_filter_data(double* track_data, 
	int l_track_data, 
	double scale_start, double scale_end, double log_scale_step, 
	vector<double>* scales_per_i_scale,
	bool dump_decomposition,
	bool compute_extrema_regions,
	bool dump_extrema_regions,
	bool return_filtered_tracks,
	vector<vector<t_annot_region*>*>* per_scale_minima_regions, 
	vector<vector<t_annot_region*>*>* per_scale_maxima_regions,
	const char* op_file_prefix)
{
	vector<double*>* decomps = new vector<double*>();

	// 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;
	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)
		{
			decomps->push_back(NULL);

			if(compute_extrema_regions)
			{
				if(per_scale_minima_regions != NULL)
				{
					per_scale_minima_regions->push_back(new vector<t_annot_region*>());
				}

				if(per_scale_maxima_regions != NULL)
				{
					per_scale_maxima_regions->push_back(new vector<t_annot_region*>());
				}
			}

			i_scale++;
			continue;
		}
		else
		{
if(__DUMP_FILTER_MSGS__)
			fprintf(stderr, "Processing scale %.2f (%.2f)\n", scale, 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];

			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 += 1000;
			MIN_VAL -= 1000;
		
			// 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.
			//for(int cur_win_mid = 0; cur_win_mid < l_track_data; cur_win_mid++)
			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;
				for(int i = cur_win_min; i <= cur_win_max; i++)
				{
					n_total += cur_win_pdf[i];
				} // i loop.

				// At this point, the histogram is updated, now must find the median for the histogram.
				int cur_n_total = 0;
				int cur_win_median = 0;
				for(int i = cur_win_min; i <= cur_win_max; i++)
				{
					cur_n_total += cur_win_pdf[i];
					if(cur_n_total > n_total/2)
					{
						// 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);

			// Copy the data.
			if(dump_decomposition)
			{
				// Dump and free memory.
				char cur_decomp_fp[1000];
				//sprintf(cur_decomp_fp, "decomp_%d_%d_%d.bin", i_scale, cur_win_start, cur_win_start + cur_l_win);
				sprintf(cur_decomp_fp, "%s_scale_%d.bin", op_file_prefix, i_scale);

if(__DUMP_FILTER_MSGS__)
				fprintf(stderr, "Dumping %s\n", cur_decomp_fp);

				double* _cur_filtered_track = get_one_indexed_per_zero_indexed_data(cur_filtered_track, l_track_data);
				dump_per_nucleotide_binary_profile(_cur_filtered_track, l_track_data, cur_decomp_fp);
				delete [] _cur_filtered_track;

if(__DUMP_FILTER_MSGS__)
				fprintf(stderr, "Closing file\n");
			}
			
			if(compute_extrema_regions)
			{
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);

				if(dump_extrema_regions)
				{
					// Get the minima and maxima, then dump.
					char cur_minima_regs_fp[1000];
					char cur_maxima_regs_fp[1000];
					sprintf(cur_minima_regs_fp, "%s_scale_%d_mins.bed", op_file_prefix, i_scale);
					sprintf(cur_maxima_regs_fp, "%s_scale_%d_maxes.bed", op_file_prefix, i_scale);

					fprintf(stderr, "Dumping the extrema regions.\n");
					FILE* f_maxes = open_f(cur_maxima_regs_fp, "w");
					for(int i_m = 0; i_m < (int)maxima->size()-1; i_m++)
					{
						fprintf(f_maxes, "XX\t%d\t%d\n", translate_coord(maxima->at(i_m)->extrema_posn+1, CODEBASE_COORDS::start_base, BED_COORDS::start_base),
							translate_coord(maxima->at(i_m)->extrema_posn+1, CODEBASE_COORDS::end_base, BED_COORDS::end_base));
					} // i_m loop.
					fclose(f_maxes);

					FILE* f_mins = open_f(cur_minima_regs_fp, "w");
					for(int i_m = 0; i_m < (int)minima->size()-1; i_m++)
					{
						fprintf(f_mins, "XX\t%d\t%d\n", translate_coord(minima->at(i_m)->extrema_posn+1, CODEBASE_COORDS::start_base, BED_COORDS::start_base),
							translate_coord(minima->at(i_m+1)->extrema_posn+1, CODEBASE_COORDS::end_base, BED_COORDS::end_base));
					} // i_m loop.
					fclose(f_mins);
				}

				if(per_scale_minima_regions != NULL)
				{
					vector<t_annot_region*>* cur_scale_minima_regions = new vector<t_annot_region*>();
					for(int i_m = 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->strand = '+';

						cur_scale_minima_regions->push_back(new_minima);
					} // i_min loop.

					per_scale_minima_regions->push_back(cur_scale_minima_regions);
				}
			
				if(per_scale_maxima_regions != NULL)
				{
					vector<t_annot_region*>* cur_scale_maxima_regions = new vector<t_annot_region*>();
					for(int i_m = 0; i_m < (int)maxima->size()-1; i_m++)
					{
						t_annot_region* new_maxima = get_empty_region();
						new_maxima->chrom = t_string::copy_me_str("XX");
						new_maxima->start = translate_coord(maxima->at(i_m)->extrema_posn+1, CODEBASE_COORDS::start_base, BED_COORDS::start_base);
						new_maxima->end = translate_coord(maxima->at(i_m+1)->extrema_posn+1, CODEBASE_COORDS::end_base, BED_COORDS::end_base);
						new_maxima->strand = '+';

						cur_scale_maxima_regions->push_back(new_maxima);
					} // i_m loop.

					per_scale_maxima_regions->push_back(cur_scale_maxima_regions);
				}

				delete_extrema_nodes(minima);
				delete_extrema_nodes(maxima);
			
				// Free the current decomposition.
				delete [] derivative_map;
			}
			
			// Do we need the filtered track back?
			if(return_filtered_tracks)
			{
				// Store the decompositions.
				decomps->push_back(cur_filtered_track);
			}
			else
			{
				// Clean track memory.
				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.

	return(decomps);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x898, %rsp            # imm = 0x898
movl %r9d, 0x38(%rsp)
movl %r8d, 0x24(%rsp)
movl %ecx, 0x3c(%rsp)
movq %rdx, 0x88(%rsp)
movsd %xmm2, 0x48(%rsp)
movsd %xmm1, 0x40(%rsp)
movsd %xmm0, 0x80(%rsp)
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8d8(%rsp), %r14
pushq $0x18
popq %rdi
callq 0x2170
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x30(%rsp)
andq $0x0, 0x10(%rax)
movsd 0x13bae(%rip), %xmm0    # 0x24008
divsd 0x48(%rsp), %xmm0
movslq %ebp, %rax
cmpl $-0x2, %eax
leaq 0x10(,%rax,8), %rcx
pushq $-0x1
popq %rdx
cmovlq %rdx, %rcx
movq %rcx, 0x70(%rsp)
leaq 0x8(,%rax,4), %rcx
movq %rcx, 0x60(%rsp)
cmovlq %rdx, %rcx
movq %rcx, 0x58(%rsp)
testl %eax, %eax
movl $0x0, %eax
movl %ebp, 0x8(%rsp)
cmovgl %ebp, %eax
movq %rax, 0x68(%rsp)
incl %eax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x88(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x7426
movsd 0x18(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x10580
andq $0x0, 0xc0(%rsp)
movq 0x30(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x11a1a
cmpb $0x0, 0x24(%rsp)
je 0x10575
testq %r14, %r14
je 0x10538
pushq $0x18
popq %rdi
callq 0x2170
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq %r14, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x11b96
cmpq $0x0, 0x8e0(%rsp)
je 0x10575
pushq $0x18
popq %rdi
callq 0x2170
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq 0x8e0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x11b96
movsd 0x18(%rsp), %xmm0
jmp 0x10bf1
cmpb $0x1, 0x24c3e(%rip)     # 0x351c5
je 0x10bf9
cvttsd2si %xmm0, %r14d
movl %r14d, %eax
andl $0x80000001, %eax       # imm = 0x80000001
xorl %ebp, %ebp
cmpl $0x1, %eax
sete %bpl
negl %ebp
movq 0x70(%rsp), %rdi
callq 0x2040
movq %rax, 0xb0(%rsp)
movq %rax, 0x28(%rsp)
movl $0xfff0bdc0, %esi       # imm = 0xFFF0BDC0
movl $0xf4240, %ecx          # imm = 0xF4240
xorl %eax, %eax
movq 0x68(%rsp), %rdi
pushq $0x2
popq %r8
pushq $0x1
popq %r9
cmpq %rax, %rdi
je 0x105ef
cvttsd2si 0x8(%rbx,%rax,8), %edx
cmpl %edx, %esi
cmovlel %edx, %esi
cmpl %edx, %ecx
cmovgel %edx, %ecx
incq %rax
jmp 0x105d5
movl %r13d, 0x4(%rsp)
addl %r14d, %ebp
movl %ebp, %eax
cltd
idivl %r8d
subl %ecx, %esi
addl $0xfffffc18, %ecx       # imm = 0xFFFFFC18
leal 0x7d0(%rsi), %edx
leal 0x7d2(%rsi), %edi
movslq %edi, %rdi
shlq $0x2, %rdi
cmpl $-0x2, %edx
pushq $-0x1
popq %rdx
cmovlq %rdx, %rdi
movq %rdi, 0xa0(%rsp)
addl $0x7d1, %esi            # imm = 0x7D1
movslq %esi, %rdx
shlq $0x2, %rdx
movq %rdx, 0x98(%rsp)
movslq %ecx, %rdx
movq %rdx, 0x78(%rsp)
negq %rdx
movq %rdx, 0x90(%rsp)
cltq
movq %rax, 0xb8(%rsp)
movl $0xf4240, %edx          # imm = 0xF4240
xorl %eax, %eax
pushq $0x1
popq %r14
xorl %ecx, %ecx
xorl %r15d, %r15d
xorl %r11d, %r11d
movl 0x8(%rsp), %esi
movq 0x50(%rsp), %rdi
cmpq %rdi, %r14
je 0x10869
movq %rdx, %r12
movl %r14d, %r10d
movq 0xb8(%rsp), %rdx
subl %edx, %r10d
cmpq %rdx, %r14
cmovlel %r9d, %r10d
addl %r14d, %edx
cmpl %esi, %edx
cmovgel %esi, %edx
movl %edx, 0x10(%rsp)
movslq %edx, %r13
testq %r11, %r11
je 0x10758
movslq %r10d, %rbp
movslq %ecx, %rcx
cmpq %rbp, %rcx
jge 0x106cd
cvttsd2si (%rbx,%rcx,8), %edx
movslq %edx, %rdx
decl (%r11,%rdx,4)
incq %rcx
jmp 0x106b7
cltq
cmpq %r13, %rax
jge 0x10704
movsd 0x8(%rbx,%rax,8), %xmm0
incq %rax
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
incl (%r11,%rcx,4)
cvtsi2sd %r15d, %xmm1
ucomisd %xmm1, %xmm0
cmoval %ecx, %r15d
cvtsi2sd %r12d, %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %r12d
jmp 0x106cf
movl %r10d, %edx
movq %r12, 0xa8(%rsp)
movslq %r12d, %r12
movl %r15d, 0xc(%rsp)
movslq %r15d, %r15
xorl %r10d, %r10d
movq %r12, %rax
cmpq %r15, %rax
jg 0x1072e
addl (%r11,%rax,4), %r10d
incq %rax
jmp 0x10720
movq %r14, %rax
movq %r11, %r14
movl 0x10(%rsp), %ecx
movl %ecx, %r11d
subl %edx, %r11d
incl %r11d
cmpl %r11d, %r10d
jne 0x10dee
movq %r14, %r11
movq %rax, %r14
movl %edx, %r10d
jmp 0x107e8
movq 0xa0(%rsp), %rdi
movl %r15d, 0xc(%rsp)
movl %r10d, %r15d
callq 0x2040
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
movq 0x98(%rsp), %rdx
callq 0x20f0
movl %r15d, %r10d
movl 0xc(%rsp), %edx
movq 0x90(%rsp), %rax
leaq (,%rax,4), %r11
addq %rbp, %r11
movslq %r15d, %rax
cmpq %r13, %rax
jg 0x107d1
movsd (%rbx,%rax,8), %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
incl (%r11,%rcx,4)
cvtsi2sd %edx, %xmm1
ucomisd %xmm1, %xmm0
cmoval %ecx, %edx
cvtsi2sd %r12d, %xmm1
ucomisd %xmm0, %xmm1
cmoval %ecx, %r12d
incq %rax
jmp 0x1079f
movslq %r12d, %r12
movslq %edx, %r15
movl 0x8(%rsp), %esi
movq 0x50(%rsp), %rdi
pushq $0x2
popq %r8
pushq $0x1
popq %r9
xorl %eax, %eax
movq %r12, %rcx
cmpq %r15, %rcx
jg 0x107fb
addl (%r11,%rcx,4), %eax
incq %rcx
jmp 0x107ed
cltd
idivl %r8d
xorl %edx, %edx
movq %r12, %rcx
cmpq %r15, %rcx
jg 0x10816
addl (%r11,%rcx,4), %edx
cmpl %eax, %edx
jg 0x1081c
incq %rcx
jmp 0x10804
xorpd %xmm0, %xmm0
jmp 0x10820
cvtsi2sd %ecx, %xmm0
movq %r12, %rdx
cmpq %r15, %rdx
jg 0x10834
cmpl $0x0, (%r11,%rdx,4)
jg 0x10836
incq %rdx
jmp 0x10823
xorl %edx, %edx
cmpq %r12, %r15
jl 0x10847
cmpl $0x0, (%r11,%r15,4)
jg 0x1084c
decq %r15
jmp 0x10836
xorl %r15d, %r15d
jmp 0x1084c
movq 0xb0(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
movl 0x10(%rsp), %eax
movl %r10d, %ecx
jmp 0x10678
testq %r11, %r11
je 0x1087c
movq 0x78(%rsp), %rax
leaq (%r11,%rax,4), %rdi
callq 0x2210
cmpb $0x0, 0x3c(%rsp)
movq 0x8d8(%rsp), %r14
movl 0x4(%rsp), %r13d
je 0x10903
leaq 0xc0(%rsp), %r14
movq %r14, %rdi
leaq 0x1635a(%rip), %rsi     # 0x26bfc
movq 0x8e8(%rsp), %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2080
cmpb $0x1, 0x2490a(%rip)     # 0x351c5
je 0x10c22
movq 0x28(%rsp), %rdi
movl 0x8(%rsp), %ebp
movl %ebp, %esi
callq 0x18756
movq %r14, %rdx
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x18dfd
testq %r14, %r14
je 0x108ee
movq %r14, %rdi
callq 0x2210
cmpb $0x1, 0x248d0(%rip)     # 0x351c5
movq 0x8d8(%rsp), %r14
je 0x10c42
cmpb $0x0, 0x24(%rsp)
je 0x10ba7
cmpb $0x1, 0x248b0(%rip)     # 0x351c5
je 0x10c63
pushq $0x18
popq %r14
movq %r14, %rdi
callq 0x2170
movq %rax, %r12
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x2170
movq %rax, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x58(%rsp), %rdi
callq 0x2040
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x20f0
movq 0x28(%rsp), %rdi
movl 0x8(%rsp), %esi
movq %r12, %rdx
movq %r14, %rcx
movq %rbp, %r8
xorl %r9d, %r9d
callq 0x1ea88
movq (%r14), %rdi
movq 0x8(%r14), %rsi
leaq 0xe0ea(%rip), %r15      # 0x1ea7d
movq %r15, %rdx
callq 0xd2d0
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq %r15, %rdx
callq 0xd2d0
cmpb $0x0, 0x38(%rsp)
jne 0x10c84
cmpq $0x0, 0x8d8(%rsp)
je 0x10a9e
pushq $0x18
popq %rdi
callq 0x2170
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, 0xc0(%rsp)
xorl %r13d, %r13d
movq 0x8(%r14), %rax
subq (%r14), %rax
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
cmpq %rax, %r13
jge 0x10a84
callq 0x11e71
movq %rax, 0x4b0(%rsp)
leaq 0x16cdf(%rip), %rdi     # 0x276fa
callq 0x21062
movq 0x4b0(%rsp), %rcx
movq %rax, (%rcx)
movq %r14, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %eax
movq 0x4b0(%rsp), %rcx
movl %eax, 0xc(%rcx)
incq %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %eax
incl %eax
movq 0x4b0(%rsp), %rcx
movl %eax, 0x20(%rcx)
movb $0x2b, 0x8(%rcx)
movq 0xc0(%rsp), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0x7448
jmp 0x109e6
movq 0x8d8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0xcfaa
movl 0x4(%rsp), %r13d
cmpq $0x0, 0x8e0(%rsp)
je 0x10b87
pushq $0x18
popq %rdi
callq 0x2170
andq $0x0, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, 0xc0(%rsp)
xorl %r13d, %r13d
movq 0x8(%r12), %rax
subq (%r12), %rax
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
cmpq %rax, %r13
jge 0x10b6d
callq 0x11e71
movq %rax, 0x4b0(%rsp)
leaq 0x16bf6(%rip), %rdi     # 0x276fa
callq 0x21062
movq 0x4b0(%rsp), %rcx
movq %rax, (%rcx)
movq %r12, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %eax
movq 0x4b0(%rsp), %rcx
movl %eax, 0xc(%rcx)
incq %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %eax
incl %eax
movq 0x4b0(%rsp), %rcx
movl %eax, 0x20(%rcx)
movb $0x2b, 0x8(%rcx)
movq 0xc0(%rsp), %rdi
leaq 0x4b0(%rsp), %rsi
callq 0x7448
jmp 0x10acd
movq 0x8e0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0xcfaa
movl 0x4(%rsp), %r13d
movq %r14, %rdi
callq 0x1f2b3
movq %r12, %rdi
callq 0x1f2b3
movq %rbp, %rdi
callq 0x2210
movq 0x8d8(%rsp), %r14
cmpb $0x0, 0x8d0(%rsp)
je 0x10bc2
movq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x119da
jmp 0x10bd1
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x10bd1
callq 0x2210
movsd 0x40(%rsp), %xmm1
ucomisd 0x134d1(%rip), %xmm1    # 0x240b0
movsd 0x18(%rsp), %xmm0
jbe 0x10bf1
ucomisd %xmm1, %xmm0
jae 0x10e8d
incl %r13d
jmp 0x104ad
movq 0x243e0(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x16af3(%rip), %rsi     # 0x276fd
movsd 0x40(%rsp), %xmm1
movb $0x2, %al
callq 0x2240
movsd 0x18(%rsp), %xmm0
jmp 0x1058d
movq 0x243b7(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x16a3c(%rip), %rsi     # 0x2766f
movq %r14, %rdx
xorl %eax, %eax
callq 0x2240
jmp 0x108c1
movq 0x24397(%rip), %rax     # 0x34fe0
movq (%rax), %rcx
leaq 0x16a28(%rip), %rdi     # 0x2767b
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
callq 0x2330
jmp 0x10903
movq 0x24376(%rip), %rax     # 0x34fe0
movq (%rax), %rcx
leaq 0x16a15(%rip), %rdi     # 0x27689
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2330
jmp 0x1091b
movq %rbp, 0x10(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x16a0f(%rip), %rsi     # 0x276a7
movq 0x8e8(%rsp), %r15
movq %r15, %rdx
movl %r13d, %ecx
xorl %eax, %eax
callq 0x2080
movl %r13d, %ecx
leaq 0x4b0(%rsp), %r13
movq %r13, %rdi
leaq 0x169fa(%rip), %rsi     # 0x276bc
movq %r15, %rdx
xorl %eax, %eax
callq 0x2080
movq 0x2430d(%rip), %rax     # 0x34fe0
movq (%rax), %rcx
leaq 0x169f5(%rip), %rdi     # 0x276d2
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
callq 0x2330
movq %r13, %rdi
leaq 0x13db6(%rip), %rsi     # 0x24aa8
callq 0x2027c
movq %rax, %r15
xorl %r13d, %r13d
movq 0x8(%r12), %rax
subq (%r12), %rax
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
cmpq %rax, %r13
jge 0x10d5a
movq %r12, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %ecx
incl %ecx
movq %r15, %rdi
leaq 0x169a4(%rip), %rsi     # 0x276f0
movl %ebp, %edx
xorl %eax, %eax
callq 0x2240
incq %r13
jmp 0x10cfd
movq %r15, %rdi
callq 0x2160
leaq 0xc0(%rsp), %rdi
leaq 0x13d37(%rip), %rsi     # 0x24aa8
callq 0x2027c
movq %rax, %r15
xorl %r13d, %r13d
movq 0x8(%r14), %rax
subq (%r14), %rax
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
cmpq %rax, %r13
jge 0x10dd7
movq %r14, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %ebp
incq %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0xcfc8
movq (%rax), %rax
movl (%rax), %ecx
incl %ecx
movq %r15, %rdi
leaq 0x16924(%rip), %rsi     # 0x276f0
movl %ebp, %edx
xorl %eax, %eax
callq 0x2240
jmp 0x10d7c
movq %r15, %rdi
callq 0x2160
movl 0x4(%rsp), %r13d
movq 0x10(%rsp), %rbp
jmp 0x109b7
movq 0x241eb(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
leaq 0x1691c(%rip), %rsi     # 0x2771b
movl 0x10(%rsp), %ecx
movq 0xa8(%rsp), %r8
movl 0xc(%rsp), %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x2240
addq $0x10, %rsp
cmpq %r15, %r12
jg 0x10e45
movq 0x241b5(%rip), %rax     # 0x34fe0
movq (%rax), %rdi
movl (%r14,%r12,4), %edx
leaq 0x16910(%rip), %rsi     # 0x27749
xorl %eax, %eax
callq 0x2240
incq %r12
jmp 0x10e1f
leaq 0x17910(%rip), %rdi     # 0x2875c
leaq 0x13c55(%rip), %rsi     # 0x24aa8
callq 0x2027c
movq %rax, %r14
leaq 0x168eb(%rip), %r15     # 0x2774d
cmpq %r13, %rbp
jg 0x10e7e
movsd (%rbx,%rbp,8), %xmm0
movq %r14, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x2240
incq %rbp
jmp 0x10e62
movq %r14, %rdi
callq 0x2160
xorl %edi, %edi
callq 0x21d0
movq 0x30(%rsp), %rax
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq