// File: /workspace/github_cpp_makefile_star2_O1/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, 0x70(%rsp)
movl %r8d, 0x5c(%rsp)
movl %ecx, 0x74(%rsp)
movq %rdx, %r12
movsd %xmm2, 0x80(%rsp)
movapd %xmm1, 0xb0(%rsp)
movsd %xmm0, 0xa8(%rsp)
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8e0(%rsp), %r13
movl $0x18, %edi
callq 0x2180
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq %rax, 0x60(%rsp)
movq $0x0, 0x10(%rax)
movsd 0x16c58(%rip), %xmm0    # 0x2b008
divsd 0x80(%rsp), %xmm0
leaq 0x30(%rsp), %rax
movsd %xmm0, (%rax)
movl %ebp, 0xc(%rsp)
movslq %ebp, %rax
cmpl $-0x2, %eax
leaq 0x10(,%rax,8), %rcx
movq $-0x1, %rdx
cmovlq %rdx, %rcx
movq %rcx, 0xa0(%rsp)
leaq 0x8(,%rax,4), %rcx
movq %rcx, 0x98(%rsp)
cmovlq %rdx, %rcx
movq %rcx, 0x90(%rsp)
incl %eax
movq %rax, 0x88(%rsp)
leaq 0xc0(%rsp), %r15
xorl %ebp, %ebp
movq %r12, 0x78(%rsp)
movsd 0x30(%rsp), %xmm0
mulsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
movq 0x8(%r12), %rsi
cmpq 0x10(%r12), %rsi
je 0x1444c
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%r12)
jmp 0x14459
movq %r12, %rdi
leaq 0x30(%rsp), %rdx
callq 0xb836
movsd 0x30(%rsp), %xmm0
movsd 0xa8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x14505
movq $0x0, 0xc0(%rsp)
movq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x154fc
cmpb $0x0, 0x5c(%rsp)
je 0x144fe
movq 0x8d8(%rsp), %r14
testq %r14, %r14
je 0x144cc
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x15668
testq %r13, %r13
je 0x144fe
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x15668
incl %ebp
jmp 0x1441c
movl %ebp, 0x24(%rsp)
cmpb $0x1, 0x25cbd(%rip)     # 0x3a1cd
je 0x15048
cvttsd2si 0x30(%rsp), %ebp
movl %ebp, %eax
andl $0x80000001, %eax       # imm = 0x80000001
xorl %r14d, %r14d
cmpl $0x1, %eax
sete %r15b
movq 0xa0(%rsp), %rdi
callq 0x2040
movq %rax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
cmpl $0x0, 0xc(%rsp)
movq 0x88(%rsp), %rdi
jle 0x1457d
movl $0xf4240, %esi          # imm = 0xF4240
movl $0xfff0bdc0, %eax       # imm = 0xFFF0BDC0
movl $0x1, %edx
cvttsd2si (%rbx,%rdx,8), %ecx
cmpl %ecx, %eax
cmovlel %ecx, %eax
cmpl %ecx, %esi
cmovll %esi, %ecx
incq %rdx
movl %ecx, %esi
cmpq %rdx, %rdi
jne 0x14562
jmp 0x14587
movl $0xfff0bdc0, %eax       # imm = 0xFFF0BDC0
movl $0xf4240, %ecx          # imm = 0xF4240
leal -0x3e8(%rcx), %edx
movslq %edx, %rdi
cmpl $0x0, 0xc(%rsp)
movq %rdi, 0x68(%rsp)
jle 0x14823
movb %r15b, %r14b
subl %r14d, %ebp
movl %ebp, %edx
shrl $0x1f, %edx
addl %ebp, %edx
sarl %edx
subl %ecx, %eax
leal 0x7d0(%rax), %ecx
leal 0x7d2(%rax), %esi
movslq %esi, %rsi
shlq $0x2, %rsi
cmpl $-0x2, %ecx
movq $-0x1, %rcx
cmovlq %rcx, %rsi
movq %rsi, 0x40(%rsp)
addl $0x7d1, %eax            # imm = 0x7D1
cltq
shlq $0x2, %rax
movq %rax, 0x10(%rsp)
negq %rdi
movq %rdi, 0x38(%rsp)
movslq %edx, %rax
movq %rax, 0x18(%rsp)
movl $0xf4240, %r15d         # imm = 0xF4240
xorl %r12d, %r12d
movl $0x1, %r14d
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %ecx, %ecx
movl %ecx, %eax
movl %ebp, %esi
movl %r14d, %ebp
movq 0x18(%rsp), %rcx
subl %ecx, %ebp
cmpq %rcx, %r14
movl $0x1, %edx
cmovlel %edx, %ebp
addl %r14d, %ecx
movl 0xc(%rsp), %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
testq %r12, %r12
je 0x146d5
cmpl %ebp, %esi
jge 0x14659
movslq %esi, %rdi
movslq %ebp, %rdx
cvttsd2si (%rbx,%rdi,8), %esi
movslq %esi, %rsi
decl (%r12,%rsi,4)
incq %rdi
cmpq %rdi, %rdx
jne 0x14645
cmpl %ecx, %eax
jge 0x1469b
cltq
movslq %ecx, %rsi
movsd 0x8(%rbx,%rax,8), %xmm0
incq %rax
cvttsd2si %xmm0, %edx
movslq %edx, %rdx
incl (%r12,%rdx,4)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
ucomisd %xmm1, %xmm0
cmoval %edx, %r13d
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
ucomisd %xmm0, %xmm1
cmoval %edx, %r15d
cmpq %rsi, %rax
jl 0x14662
xorl %r10d, %r10d
cmpl %r13d, %r15d
jg 0x146c2
movslq %r15d, %rax
leaq (%r12,%rax,4), %rax
movl %r13d, %esi
subl %r15d, %esi
incl %esi
xorl %edx, %edx
xorl %r10d, %r10d
addl (%rax,%rdx,4), %r10d
incq %rdx
cmpl %edx, %esi
jne 0x146b7
movl %ecx, %r11d
subl %ebp, %r11d
incl %r11d
cmpl %r11d, %r10d
je 0x1474c
jmp 0x15241
movq 0x40(%rsp), %rdi
movl %ebp, 0x28(%rsp)
movl %ecx, %ebp
callq 0x2040
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
movq 0x10(%rsp), %rdx
callq 0x20f0
movl %ebp, %ecx
movl 0x28(%rsp), %ebp
movq 0x38(%rsp), %rax
leaq (%r12,%rax,4), %r12
cmpl %ebp, %ecx
jl 0x1474c
movslq %ebp, %rax
movslq %ecx, %rsi
decq %rax
movsd 0x8(%rbx,%rax,8), %xmm0
cvttsd2si %xmm0, %edx
movslq %edx, %rdx
incl (%r12,%rdx,4)
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
ucomisd %xmm1, %xmm0
cmoval %edx, %r13d
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
ucomisd %xmm0, %xmm1
cmoval %edx, %r15d
incq %rax
cmpq %rsi, %rax
jl 0x14713
movl %r15d, %r10d
xorl %edx, %edx
movslq %r15d, %rax
cmpl %r13d, %r15d
jg 0x1477e
leaq (%r12,%rax,4), %rdx
movl %r13d, %esi
subl %eax, %esi
incl %esi
xorl %r8d, %r8d
xorl %edi, %edi
addl (%rdx,%r8,4), %edi
incq %r8
cmpl %r8d, %esi
jne 0x14769
movl %edi, %edx
shrl $0x1f, %edx
addl %edi, %edx
sarl %edx
xorpd %xmm0, %xmm0
cmpl %r13d, %r10d
jg 0x147b3
leal 0x1(%r13), %esi
leaq (%r12,%rax,4), %rdi
xorl %r8d, %r8d
movl %r10d, %r9d
addl (%rdi), %r8d
cmpl %edx, %r8d
jg 0x147ab
incl %r9d
addq $0x4, %rdi
cmpl %r9d, %esi
jne 0x14795
jmp 0x147b3
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
xorl %edx, %edx
movl $0x0, %r15d
cmpl %r13d, %r10d
jg 0x147df
leal 0x1(%r13), %esi
leaq (%r12,%rax,4), %rdi
movl %r10d, %r15d
cmpl $0x0, (%rdi)
jg 0x147df
incl %r15d
addq $0x4, %rdi
cmpl %r15d, %esi
jne 0x147cb
xorl %r15d, %r15d
cmpl %r10d, %r13d
jl 0x14802
movslq %r13d, %rsi
incq %rsi
cmpl $0x0, -0x4(%r12,%rsi,4)
jg 0x147ff
decl %r13d
decq %rsi
cmpq %rax, %rsi
jg 0x147ea
jmp 0x14802
movl %r13d, %edx
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax,%r14,8)
incq %r14
movl %edx, %r13d
cmpq 0x88(%rsp), %r14
jne 0x1460d
jmp 0x14826
xorl %r12d, %r12d
testq %r12, %r12
je 0x14839
movq 0x68(%rsp), %rax
leaq (%r12,%rax,4), %rdi
callq 0x2220
cmpb $0x0, 0x74(%rsp)
movq 0x78(%rsp), %r12
movq 0x8e0(%rsp), %r13
leaq 0xc0(%rsp), %r15
movl 0x24(%rsp), %ebp
je 0x148c7
movq %r15, %rdi
leaq 0x19399(%rip), %rsi     # 0x2dbfc
movq 0x8e8(%rsp), %rdx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2080
cmpb $0x1, 0x25952(%rip)     # 0x3a1cd
je 0x1506e
movq 0x50(%rsp), %rdi
movl 0xc(%rsp), %ebp
movl %ebp, %esi
callq 0x1d255
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
movq %r15, %rdx
callq 0x1d6be
testq %r14, %r14
je 0x148ae
movq %r14, %rdi
callq 0x2220
cmpb $0x1, 0x25918(%rip)     # 0x3a1cd
movq 0x8e0(%rsp), %r13
je 0x1508e
movl 0x24(%rsp), %ebp
cmpb $0x0, 0x5c(%rsp)
je 0x14fd0
cmpb $0x1, 0x258f4(%rip)     # 0x3a1cd
je 0x15098
movl $0x18, %edi
callq 0x2180
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
xorl %r14d, %r14d
movq %r14, 0x10(%rax)
movl $0x18, %edi
callq 0x2180
movq %rax, %r13
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %r14, 0x10(%rax)
movq 0x90(%rsp), %rdi
callq 0x2040
movq %rax, %r14
movq %rax, %rdi
xorl %esi, %esi
movq 0x98(%rsp), %rdx
callq 0x20f0
movq 0x50(%rsp), %rdi
movl 0xc(%rsp), %esi
movq %r15, 0x18(%rsp)
movq %r15, %rdx
movq %r13, %rcx
movq %r14, 0x68(%rsp)
movq %r14, %r8
xorl %r9d, %r9d
callq 0x24787
movq (%r13), %r12
movq %r13, 0x28(%rsp)
movq 0x8(%r13), %r15
cmpq %r15, %r12
je 0x14b2b
movq %r15, %r14
subq %r12, %r14
movq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
leaq 0xfde5(%rip), %rcx      # 0x2477c
callq 0x10dc5
leaq 0x8(%r12), %r13
cmpq $0x81, %r14
jl 0x14a9e
movq %r15, 0x10(%rsp)
movl $0x8, %ebp
movq %r13, 0x38(%rsp)
movq %r12, %rax
movq %rax, 0x40(%rsp)
leaq (%r12,%rbp), %r14
movq (%r12,%rbp), %rdi
movq (%r12), %rsi
callq 0x2477c
movq (%r12,%rbp), %r15
testb %al, %al
movq %r14, 0x48(%rsp)
je 0x149f8
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x22b0
movq %r12, %r14
jmp 0x14a2d
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2477c
testb %al, %al
je 0x14a2d
movq %r13, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14a0f
movq %r15, (%r14)
addq $0x8, %rbp
addq $0x8, %r13
cmpq $0x80, %rbp
movq 0x48(%rsp), %rax
jne 0x149c0
subq $-0x80, %r12
movq 0x10(%rsp), %r13
cmpq %r13, %r12
je 0x14b2b
movq -0x8(%r12), %rsi
movq (%r12), %r15
movq %r15, %rdi
callq 0x2477c
movq %r12, %r14
testb %al, %al
je 0x14a95
movq %r12, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14a77
movq %r15, (%r14)
addq $0x8, %r12
jmp 0x14a53
cmpq %r15, %r13
je 0x14b2b
movq %r12, %rbp
movq %r15, 0x10(%rsp)
movq %rbp, %r15
movq %r13, %rbp
movq (%r13), %rdi
movq (%r12), %rsi
callq 0x2477c
movq (%r13), %r13
testb %al, %al
je 0x14ae7
movq %rbp, %rdx
subq %r12, %rdx
subq %rdx, %r15
addq $0x10, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x22b0
movq %r12, %r14
jmp 0x14b1a
movq (%r15), %rsi
movq %r13, %rdi
callq 0x2477c
movq %rbp, %r14
testb %al, %al
je 0x14b1a
movq %rbp, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r13, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14afc
movq %r13, (%r14)
leaq 0x8(%rbp), %r13
movq 0x10(%rsp), %r15
cmpq %r15, %r13
jne 0x14aaf
movq 0x18(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %r15
cmpq %r15, %r12
je 0x14cfb
movq %r15, %r14
subq %r12, %r14
movq %r14, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
leaq 0xfc15(%rip), %rcx      # 0x2477c
callq 0x10dc5
leaq 0x8(%r12), %r13
cmpq $0x81, %r14
jl 0x14c6e
movq %r15, 0x10(%rsp)
movl $0x8, %ebp
movq %r13, 0x38(%rsp)
movq %r12, %rax
movq %rax, 0x40(%rsp)
leaq (%r12,%rbp), %r14
movq (%r12,%rbp), %rdi
movq (%r12), %rsi
callq 0x2477c
movq (%r12,%rbp), %r15
testb %al, %al
movq %r14, 0x48(%rsp)
je 0x14bc8
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x22b0
movq %r12, %r14
jmp 0x14bfd
movq 0x40(%rsp), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x2477c
testb %al, %al
je 0x14bfd
movq %r13, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14bdf
movq %r15, (%r14)
addq $0x8, %rbp
addq $0x8, %r13
cmpq $0x80, %rbp
movq 0x48(%rsp), %rax
jne 0x14b90
subq $-0x80, %r12
movq 0x10(%rsp), %r13
cmpq %r13, %r12
je 0x14cfb
movq -0x8(%r12), %rsi
movq (%r12), %r15
movq %r15, %rdi
callq 0x2477c
movq %r12, %r14
testb %al, %al
je 0x14c65
movq %r12, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14c47
movq %r15, (%r14)
addq $0x8, %r12
jmp 0x14c23
cmpq %r15, %r13
je 0x14cfb
movq %r12, %rbp
movq %r15, 0x10(%rsp)
movq %rbp, %r15
movq %r13, %rbp
movq (%r13), %rdi
movq (%r12), %rsi
callq 0x2477c
movq (%r13), %r13
testb %al, %al
je 0x14cb7
movq %rbp, %rdx
subq %r12, %rdx
subq %rdx, %r15
addq $0x10, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x22b0
movq %r12, %r14
jmp 0x14cea
movq (%r15), %rsi
movq %r13, %rdi
callq 0x2477c
movq %rbp, %r14
testb %al, %al
je 0x14cea
movq %rbp, %rcx
leaq -0x8(%rcx), %r14
movq -0x10(%rcx), %rsi
movq -0x8(%rcx), %rax
movq %rax, (%rcx)
movq %r13, %rdi
callq 0x2477c
movq %r14, %rcx
testb %al, %al
jne 0x14ccc
movq %r13, (%r14)
leaq 0x8(%rbp), %r13
movq 0x10(%rsp), %r15
cmpq %r15, %r13
jne 0x14c7f
cmpb $0x0, 0x70(%rsp)
movq 0x8e0(%rsp), %r13
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
leaq 0xc0(%rsp), %r15
jne 0x150a2
cmpq $0x0, 0x8d8(%rsp)
movq 0x78(%rsp), %r12
je 0x14e6f
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq 0x28(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x3, %rax
cmpl $0x2, %eax
jl 0x14e33
movl $0x1, %r14d
leaq -0x1(%r14), %r15
callq 0x15990
movq %rax, 0x4b0(%rsp)
leaq 0x1996d(%rip), %rdi     # 0x2e6fa
callq 0x273e0
movq 0x28(%rsp), %r8
movq 0x4b0(%rsp), %rcx
movq %rax, (%rcx)
movq (%r8), %rax
movq 0x8(%r8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x152d5
movq -0x8(%rax,%r14,8), %rcx
movl (%rcx), %esi
movq 0x4b0(%rsp), %rcx
movl %esi, 0xc(%rcx)
cmpq %r14, %rdx
jbe 0x152e1
movq (%rax,%r14,8), %rax
movl (%rax), %eax
incl %eax
movl %eax, 0x20(%rcx)
movb $0x2b, 0x8(%rcx)
movq 0xc0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x14dff
movq %rcx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x14e11
leaq 0x4b0(%rsp), %rdx
callq 0xb976
movq 0x28(%rsp), %r8
movq 0x8(%r8), %rax
subq (%r8), %rax
shlq $0x1d, %rax
addq %rbp, %rax
sarq $0x20, %rax
leaq 0x1(%r14), %rcx
cmpq %rax, %r14
movq %rcx, %r14
jl 0x14d75
movq 0x8d8(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x14e5f
movq 0xc0(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
leaq 0xc0(%rsp), %r15
jmp 0x14e6f
leaq 0xc0(%rsp), %r15
movq %r15, %rdx
callq 0x10c8a
testq %r13, %r13
je 0x14fae
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movq %rax, 0xc0(%rsp)
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
shrq $0x3, %rax
cmpl $0x2, %eax
jl 0x14f77
movl $0x1, %r14d
leaq -0x1(%r14), %r15
callq 0x15990
movq %rax, 0x4b0(%rsp)
leaq 0x19829(%rip), %rdi     # 0x2e6fa
callq 0x273e0
movq 0x18(%rsp), %r8
movq 0x4b0(%rsp), %rcx
movq %rax, (%rcx)
movq (%r8), %rax
movq 0x8(%r8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x152d5
movq -0x8(%rax,%r14,8), %rcx
movl (%rcx), %esi
movq 0x4b0(%rsp), %rcx
movl %esi, 0xc(%rcx)
cmpq %r14, %rdx
jbe 0x152e1
movq (%rax,%r14,8), %rax
movl (%rax), %eax
incl %eax
movl %eax, 0x20(%rcx)
movb $0x2b, 0x8(%rcx)
movq 0xc0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x14f43
movq %rcx, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x14f55
leaq 0x4b0(%rsp), %rdx
callq 0xb976
movq 0x18(%rsp), %r8
movq 0x8(%r8), %rax
subq (%r8), %rax
shlq $0x1d, %rax
addq %rbp, %rax
sarq $0x20, %rax
leaq 0x1(%r14), %rcx
cmpq %rax, %r14
movq %rcx, %r14
jl 0x14eb9
movq 0x8(%r13), %rsi
cmpq 0x10(%r13), %rsi
je 0x14f9b
movq 0xc0(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%r13)
leaq 0xc0(%rsp), %r15
jmp 0x14fae
movq %r13, %rdi
leaq 0xc0(%rsp), %r15
movq %r15, %rdx
callq 0x10c8a
movq 0x28(%rsp), %rdi
callq 0x25358
movq 0x18(%rsp), %rdi
callq 0x25358
movq 0x68(%rsp), %rdi
callq 0x2220
movl 0x24(%rsp), %ebp
cmpb $0x0, 0x8d0(%rsp)
je 0x14ff8
movq 0x60(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x15009
movq 0x50(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x8(%rdi)
jmp 0x15013
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x15013
callq 0x2220
jmp 0x15013
leaq 0x50(%rsp), %rdx
callq 0x15774
movsd 0x30(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd 0xb0(%rsp), %xmm2
cmpnltpd %xmm2, %xmm1
cmpnlepd %xmm0, %xmm2
orpd %xmm1, %xmm2
movq %xmm2, %rax
subl %eax, %ebp
testb $0x1, %al
jne 0x1441c
jmp 0x1522a
movq 0x24f91(%rip), %rax     # 0x39fe0
movq (%rax), %rdi
leaq 0x196a4(%rip), %rsi     # 0x2e6fd
movapd 0xb0(%rsp), %xmm1
movb $0x2, %al
callq 0x2250
jmp 0x14516
movq 0x24f6b(%rip), %rax     # 0x39fe0
movq (%rax), %rdi
leaq 0x195f0(%rip), %rsi     # 0x2e66f
movq %r15, %rdx
xorl %eax, %eax
callq 0x2250
jmp 0x14881
callq 0x499c
jmp 0x148c3
callq 0x49be
jmp 0x148df
movq %r15, %rdi
leaq 0x195fb(%rip), %rsi     # 0x2e6a7
movq 0x8e8(%rsp), %rdx
movl 0x24(%rsp), %r14d
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2080
leaq 0x4b0(%rsp), %r12
movq %r12, %rdi
leaq 0x195e7(%rip), %rsi     # 0x2e6bc
movq 0x8e8(%rsp), %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x2080
movq 0x24ef2(%rip), %rax     # 0x39fe0
movq (%rax), %rcx
movl $0x1d, %esi
movl $0x1, %edx
leaq 0x195d0(%rip), %rdi     # 0x2e6d2
callq 0x2340
movq %r12, %rdi
leaq 0x1699d(%rip), %rsi     # 0x2baae
callq 0x26387
movq %rax, %r14
movq 0x18(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpl $0x2, %edx
jl 0x15180
xorl %r12d, %r12d
cmpq %r12, %rdx
jbe 0x152f2
movq (%rax,%r12,8), %rax
movl (%rax), %edx
leal 0x1(%rdx), %ecx
movq %r14, %rdi
leaq 0x195a0(%rip), %rsi     # 0x2e6f0
xorl %eax, %eax
callq 0x2250
incq %r12
movq 0x18(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shlq $0x1d, %rcx
addq %rbp, %rcx
sarq $0x20, %rcx
cmpq %rcx, %r12
jl 0x15134
movq %r14, %rdi
callq 0x2170
movq %r15, %rdi
leaq 0x1691c(%rip), %rsi     # 0x2baae
callq 0x26387
movq %rax, %r14
movq 0x28(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpl $0x2, %edx
jl 0x1521d
movl $0x1, %r12d
leaq -0x1(%r12), %rsi
cmpq %rsi, %rdx
jbe 0x152fe
cmpq %r12, %rdx
jbe 0x152f2
movq -0x8(%rax,%r12,8), %rcx
movq (%rax,%r12,8), %rax
movl (%rcx), %edx
movl (%rax), %ecx
incl %ecx
movq %r14, %rdi
leaq 0x19508(%rip), %rsi     # 0x2e6f0
xorl %eax, %eax
callq 0x2250
movq 0x28(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shlq $0x1d, %rcx
addq %rbp, %rcx
sarq $0x20, %rcx
leaq 0x1(%r12), %rsi
cmpq %rcx, %r12
movq %rsi, %r12
jl 0x151b8
movq %r14, %rdi
callq 0x2170
jmp 0x14d20
movq 0x60(%rsp), %rax
addq $0x898, %rsp            # imm = 0x898
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x24d98(%rip), %rax     # 0x39fe0
movq (%rax), %rdi
leaq 0x194c9(%rip), %rsi     # 0x2e71b
movl %ebp, %edx
movl %ecx, %r14d
movl %r15d, %r8d
movl %r13d, %r9d
xorl %eax, %eax
pushq %r11
pushq %r10
callq 0x2250
addq $0x10, %rsp
cmpl %r13d, %r15d
jg 0x1527f
movl %r15d, %edi
movl %r13d, %esi
movq %r12, %rdx
callq 0x4951
leaq 0x1a4d6(%rip), %rdi     # 0x2f75c
leaq 0x16821(%rip), %rsi     # 0x2baae
callq 0x26387
movq %rax, %r15
cmpl %ebp, %r14d
jl 0x152c6
movslq %ebp, %r12
movslq %r14d, %r13
decq %r12
leaq 0x194a3(%rip), %r14     # 0x2e74d
movsd 0x8(%rbx,%r12,8), %xmm0
movq %r15, %rdi
movq %r14, %rsi
movb $0x1, %al
callq 0x2250
incq %r12
cmpq %r13, %r12
jl 0x152aa
movq %r15, %rdi
callq 0x2170
xorl %edi, %edi
callq 0x21e0
leaq 0x185fa(%rip), %rdi     # 0x2d8d6
movq %r15, %rsi
jmp 0x152eb
leaq 0x185ee(%rip), %rdi     # 0x2d8d6
movq %r14, %rsi
xorl %eax, %eax
callq 0x2270
leaq 0x185dd(%rip), %rdi     # 0x2d8d6
movq %r12, %rsi
jmp 0x152eb
leaq 0x185d1(%rip), %rdi     # 0x2d8d6
jmp 0x152eb