// File: gersteinlab[P]MUSIC/src/ms_signal_enrichment_utils.cpp
// Function: prune_region_ends_per_p_value_minimization_buffered_binomial_p_vals(std::vector<t_annot_region*, std::allocator<t_annot_region*>>*, double*, int, double*, int, int)
vector<t_annot_region*>* prune_region_ends_per_p_value_minimization_buffered_binomial_p_vals(vector<t_annot_region*>* regions, 
																							double* signal_profile, int l_profile, 
																							double* control_profile, int l_control,
																							int l_fragment)
{	
	// List of pruned regions.
	vector<t_annot_region*>* pruned_regions = new vector<t_annot_region*>();

	double max_grand_total_int = 0.0;
	for(int i_reg = 0; i_reg < (int)regions->size(); i_reg++)
	{
		// Get the extrema signal values.
		double current_grand_total = 0.0;
		for(int i = regions->at(i_reg)->start; i <= regions->at(i_reg)->end; i++)
		{
			if(i < l_profile)
			{
				current_grand_total += signal_profile[i];
			}

			if(i < l_control)
			{
				current_grand_total += control_profile[i];
			}
		} // i loop.

		if(max_grand_total_int < current_grand_total)
		{
			max_grand_total_int = (int)(floor(current_grand_total));
		} 
	} // i_reg loop.

if(__DUMP_SIGNAL_ENRICHMENT_MSGS__)
{
	fprintf(stderr, "Setting up the log factorials with maximum grand total of %lf\n", max_grand_total_int);
}

	double* log_factorials = buffer_log_factorials((int)(max_grand_total_int+20));

	int buffered_binomial_bin_size = 500;
	double** buffered_binomial_p_vals = buffer_binomial_pvalues((max_grand_total_int / l_fragment) + 100, log_factorials, buffered_binomial_bin_size);

if(__DUMP_SIGNAL_ENRICHMENT_MSGS__)
{
	fprintf(stderr, "Pruning region ends for %d regions via p-value minimization.\n", (int)regions->size());
}

	// Go over all the regions.
	vector<double>* p_values_per_threshold = new vector<double>();
	vector<double>* pruned_starts_per_thresholds = new vector<double>();
	vector<double>* pruned_ends_per_thresholds = new vector<double>();
	for(int i_reg = 0; i_reg < (int)regions->size(); i_reg++)
	{
		//if(i_reg % 1000 == 0)
		//{
		//	fprintf(stderr, "Processing %d.(%d) region: %d-%d\n", i_reg, (int)regions->size(), regions->at(i_reg)->start, regions->at(i_reg)->end);
		//}

		// Skip the region if the signal is out of the control signal range.
		if(regions->at(i_reg)->end > l_control)
		{
			fprintf(stderr, "Skipping pruning %d-%d\n", regions->at(i_reg)->start, regions->at(i_reg)->end);
			continue;
		}

		// Get the extrema signal values.
		int max_sig = 0;
		int min_sig = 1000*1000;
		double total_signal = 0;
		for(int i = regions->at(i_reg)->start; i <= regions->at(i_reg)->end; i++)
		{
			int cur_floorized_val = (int)(floor(signal_profile[i]));
			if(max_sig < cur_floorized_val)
			{
				max_sig = cur_floorized_val;
			}

			if(min_sig > cur_floorized_val)
			{
				min_sig = cur_floorized_val;
			}

			total_signal += signal_profile[i];
		} // i loop.

		// Limit the maximum at 500.
		max_sig = (max_sig > 500)?(500):(max_sig);

		// Start thresholding over all possible thresholds.			
		for(int sig_thresh = min_sig; sig_thresh <= max_sig; sig_thresh++)
		{
			// Threshold the ends.
			int pruned_start = regions->at(i_reg)->start;
			int pruned_end = regions->at(i_reg)->end;

			//bool passed_threshold = false;
			for(int i_pr = pruned_start; i_pr <= pruned_end; i_pr++)
			{
				if(signal_profile[i_pr] > sig_thresh)
				{
					//passed_threshold = true;
					pruned_start = i_pr;
					break;
				}
			} // i_pr loop.

			for(int i_pr = pruned_end; i_pr >= pruned_start; i_pr--)
			{
				if(signal_profile[i_pr] > sig_thresh)
				{
					pruned_end = i_pr;
					break;
				}
			} // i_pr loop.

			// Get the binomial p-value for current region.
			//double test_cur_pruned_pvalue = get_binomial_pvalue_per_region(signal_profile, control_profile, pruned_start, pruned_end, log_factorials, l_fragment, false, 0);

			// Get the p-value for the current region.
			double total_profile_signal = 0;
			double total_control_signal = 0;
			for(int i = pruned_start; i <= pruned_end; i++)
			{
				total_profile_signal += floor(signal_profile[i]);
				total_control_signal += (control_profile[i]);
			} // i loop.

			total_profile_signal /= l_fragment;
			total_control_signal /= l_fragment;
	
			int grand_total_int = (int)(total_profile_signal + total_control_signal);

			double log_flip = log(.5);

			int buffered_base_val = ((int)(total_control_signal / buffered_binomial_bin_size)) * buffered_binomial_bin_size;
			double cur_pruned_pvalue = buffered_binomial_p_vals[grand_total_int][buffered_base_val];
			for(int i = buffered_base_val+1; i <= total_control_signal; i++)
			{
				double log_cur_half_pow = log_flip * grand_total_int;
				double log_cur_perm = 0.0; // = xlog(1.0).

				// Compute the current permutation.
				log_cur_perm = xlog_div(log_factorials[grand_total_int], xlog_mul(log_factorials[i], log_factorials[grand_total_int-i]));
				cur_pruned_pvalue = xlog_sum(cur_pruned_pvalue, xlog_mul(log_cur_perm, log_cur_half_pow));
			} // i loop.

			//fprintf(stderr, "p-vals: %lf, %lf\n", test_cur_pruned_pvalue, cur_pruned_pvalue);

			// Add the current p-value.
			p_values_per_threshold->push_back(cur_pruned_pvalue);
			pruned_starts_per_thresholds->push_back(pruned_start);
			pruned_ends_per_thresholds->push_back(pruned_end);

			double total_pruned_sig = 0;
			for(int i_sig = pruned_start; i_sig <= pruned_end; i_sig++)
			{
				total_pruned_sig += signal_profile[i_sig];
			} // i_sig.

			// If we are below 50% of the total probability, stop since most of the signal is lost already.
			if(total_pruned_sig/total_signal <= 0.5)
			{
				break;
			}
		} // sig thresh loop.

		// If the condition is satisfied, we are done.
		if(p_values_per_threshold->size() > 0)
		{
			double min_p_val = p_values_per_threshold->at(0);
			int min_p_val_i = 0;
			for(int i_th = 0; i_th < (int)p_values_per_threshold->size(); i_th++)
			{
				if(min_p_val > p_values_per_threshold->at(i_th))
				{
					min_p_val = p_values_per_threshold->at(i_th);
					min_p_val_i = i_th;
				}
			} // total mass fraction check.

			t_annot_region* pruned_peak = duplicate_region(regions->at(i_reg));
			pruned_peak->start = (int)(pruned_starts_per_thresholds->at(min_p_val_i));
			pruned_peak->end = (int)(pruned_ends_per_thresholds->at(min_p_val_i));

			pruned_regions->push_back(pruned_peak);
		}
		else
		{
			t_annot_region* pruned_peak = duplicate_region(regions->at(i_reg));
			pruned_regions->push_back(pruned_peak);
		}

		// Clear the values.
		p_values_per_threshold->clear();
		pruned_starts_per_thresholds->clear();
		pruned_ends_per_thresholds->clear();
	} // i_reg loop.

	// Free buffered value memory.
	delete [] log_factorials;
	delete_buffered_binomial_pvalues(buffered_binomial_p_vals, max_grand_total_int, buffered_binomial_bin_size);

	// Dump the bed file.
	//dump_BED(op_bed_fp, pruned_regions);

	return(pruned_regions);
}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdi, 0x1b0(%rsp)
movq %rsi, 0x1a8(%rsp)
movl %edx, 0x1a4(%rsp)
movq %rcx, 0x198(%rsp)
movl %r8d, 0x194(%rsp)
movl %r9d, 0x190(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x70(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x70(%rsp), %rdi
callq 0xc670
movq 0x70(%rsp), %rax
movq %rax, 0x188(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x180(%rsp)
movl $0x0, 0x17c(%rsp)
movl 0x17c(%rsp), %eax
movl %eax, 0x6c(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x6c(%rsp), %eax
cmpl %ecx, %eax
jge 0x399ef
xorps %xmm0, %xmm0
movsd %xmm0, 0x170(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x17c(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x16c(%rsp)
movl 0x16c(%rsp), %eax
movl %eax, 0x68(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x17c(%rsp), %rsi
callq 0xc800
movq %rax, %rcx
movl 0x68(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x20(%rcx), %eax
jg 0x399a0
movl 0x16c(%rsp), %eax
cmpl 0x1a4(%rsp), %eax
jge 0x39951
movq 0x1a8(%rsp), %rax
movslq 0x16c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x170(%rsp), %xmm0
movsd %xmm0, 0x170(%rsp)
movl 0x16c(%rsp), %eax
cmpl 0x194(%rsp), %eax
jge 0x39988
movq 0x198(%rsp), %rax
movslq 0x16c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x170(%rsp), %xmm0
movsd %xmm0, 0x170(%rsp)
jmp 0x3998a
movl 0x16c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x16c(%rsp)
jmp 0x398e7
movsd 0x180(%rsp), %xmm1
movsd 0x170(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x399d7
movsd 0x170(%rsp), %xmm0
callq 0x22e0
cvttsd2si %xmm0, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x180(%rsp)
jmp 0x399d9
movl 0x17c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x17c(%rsp)
jmp 0x39892
testb $0x1, 0x2b7ea(%rip)     # 0x651e0
je 0x39a19
movq 0x2b5e1(%rip), %rax     # 0x64fe0
movq (%rax), %rdi
movsd 0x180(%rsp), %xmm0
leaq 0x1cba8(%rip), %rsi     # 0x565ba
movb $0x1, %al
callq 0x2250
movsd 0x1b337(%rip), %xmm0    # 0x54d58
addsd 0x180(%rsp), %xmm0
cvttsd2si %xmm0, %edi
callq 0x3f420
movq %rax, 0x160(%rsp)
movl $0x1f4, 0x15c(%rsp) # imm = 0x1F4
movsd 0x180(%rsp), %xmm0
cvtsi2sdl 0x190(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x185c4(%rip), %xmm1    # 0x52028
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %edi
movq 0x160(%rsp), %rsi
movl 0x15c(%rsp), %edx
callq 0x3f1c0
movq %rax, 0x150(%rsp)
testb $0x1, 0x2b751(%rip)     # 0x651e0
je 0x39ac2
movq 0x2b548(%rip), %rax     # 0x64fe0
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0xc680
movq 0x60(%rsp), %rdi
movl %eax, %edx
leaq 0x1cb3e(%rip), %rsi     # 0x565f9
movb $0x0, %al
callq 0x2250
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x48(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x48(%rsp), %rdi
callq 0xc840
movq 0x48(%rsp), %rax
movq %rax, 0x148(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x50(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x50(%rsp), %rdi
callq 0xc840
movq 0x50(%rsp), %rax
movq %rax, 0x140(%rsp)
movl $0x18, %edi
callq 0x2190
movq %rax, %rdi
movq %rdi, 0x58(%rsp)
xorl %esi, %esi
movl $0x18, %edx
callq 0x2110
movq 0x58(%rsp), %rdi
callq 0xc840
movq 0x58(%rsp), %rax
movq %rax, 0x138(%rsp)
movl $0x0, 0x134(%rsp)
movl 0x134(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x1b0(%rsp), %rdi
callq 0xc680
movq %rax, %rcx
movl 0x44(%rsp), %eax
cmpl %ecx, %eax
jge 0x3a3e4
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
cmpl 0x194(%rsp), %eax
jle 0x39c1c
movq 0x2b422(%rip), %rax     # 0x64fe0
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x40(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq 0x38(%rsp), %rdi
movl 0x40(%rsp), %edx
movq (%rax), %rax
movl 0x20(%rax), %ecx
leaq 0x1ca27(%rip), %rsi     # 0x56637
movb $0x0, %al
callq 0x2250
jmp 0x3a3ce
movl $0x0, 0x130(%rsp)
movl $0xf4240, 0x12c(%rsp) # imm = 0xF4240
xorps %xmm0, %xmm0
movsd %xmm0, 0x120(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x11c(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq %rax, %rcx
movl 0x34(%rsp), %eax
movq (%rcx), %rcx
cmpl 0x20(%rcx), %eax
jg 0x39d31
movq 0x1a8(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x22e0
cvttsd2si %xmm0, %eax
movl %eax, 0x118(%rsp)
movl 0x130(%rsp), %eax
cmpl 0x118(%rsp), %eax
jge 0x39cd6
movl 0x118(%rsp), %eax
movl %eax, 0x130(%rsp)
movl 0x12c(%rsp), %eax
cmpl 0x118(%rsp), %eax
jle 0x39cf4
movl 0x118(%rsp), %eax
movl %eax, 0x12c(%rsp)
movq 0x1a8(%rsp), %rax
movslq 0x11c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0x120(%rsp), %xmm0
movsd %xmm0, 0x120(%rsp)
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x39c60
cmpl $0x1f4, 0x130(%rsp) # imm = 0x1F4
jle 0x39d49
movl $0x1f4, %eax            # imm = 0x1F4
movl %eax, 0x30(%rsp)
jmp 0x39d54
movl 0x130(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x130(%rsp)
movl 0x12c(%rsp), %eax
movl %eax, 0x114(%rsp)
movl 0x114(%rsp), %eax
cmpl 0x130(%rsp), %eax
jg 0x3a209
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0xc(%rax), %eax
movl %eax, 0x110(%rsp)
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rax
movl 0x20(%rax), %eax
movl %eax, 0x10c(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x108(%rsp)
movl 0x108(%rsp), %eax
cmpl 0x10c(%rsp), %eax
jg 0x39e2c
movq 0x1a8(%rsp), %rax
movslq 0x108(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl 0x114(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x39e17
movl 0x108(%rsp), %eax
movl %eax, 0x110(%rsp)
jmp 0x39e2c
jmp 0x39e19
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x39dd3
movl 0x10c(%rsp), %eax
movl %eax, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x110(%rsp), %eax
jl 0x39e93
movq 0x1a8(%rsp), %rax
movslq 0x104(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
cvtsi2sdl 0x114(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x39e7e
movl 0x104(%rsp), %eax
movl %eax, 0x10c(%rsp)
jmp 0x39e93
jmp 0x39e80
movl 0x104(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x39e3a
xorps %xmm0, %xmm0
movsd %xmm0, 0xf8(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0xec(%rsp)
movl 0xec(%rsp), %eax
cmpl 0x10c(%rsp), %eax
jg 0x39f2f
movq 0x1a8(%rsp), %rax
movslq 0xec(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x22e0
addsd 0xf8(%rsp), %xmm0
movsd %xmm0, 0xf8(%rsp)
movq 0x198(%rsp), %rax
movslq 0xec(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x39eb9
cvtsi2sdl 0x190(%rsp), %xmm1
movsd 0xf8(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xf8(%rsp)
cvtsi2sdl 0x190(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xf0(%rsp)
movsd 0xf8(%rsp), %xmm0
addsd 0xf0(%rsp), %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0xe8(%rsp)
movsd 0x180a6(%rip), %xmm0    # 0x52038
callq 0x2140
movsd %xmm0, 0xe0(%rsp)
movsd 0xf0(%rsp), %xmm0
cvtsi2sdl 0x15c(%rsp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
imull 0x15c(%rsp), %eax
movl %eax, 0xdc(%rsp)
movq 0x150(%rsp), %rax
movslq 0xe8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movslq 0xdc(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0xd0(%rsp)
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
cvtsi2sdl 0xcc(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x3a108
movsd 0xe0(%rsp), %xmm0
cvtsi2sdl 0xe8(%rsp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xb8(%rsp)
movq 0x160(%rsp), %rax
movslq 0xe8(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x160(%rsp), %rax
movslq 0xcc(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x160(%rsp), %rax
movl 0xe8(%rsp), %ecx
subl 0xcc(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
callq 0x44510
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x445a0
movsd %xmm0, 0xb8(%rsp)
movsd 0xd0(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
callq 0x44510
movaps %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
callq 0x44310
movsd %xmm0, 0xd0(%rsp)
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x3a004
movq 0x148(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xc850
movq 0x140(%rsp), %rdi
cvtsi2sdl 0x110(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
leaq 0xb0(%rsp), %rsi
callq 0x3ae20
movq 0x138(%rsp), %rdi
cvtsi2sdl 0x10c(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
leaq 0xa8(%rsp), %rsi
callq 0x3ae20
xorps %xmm0, %xmm0
movsd %xmm0, 0xa0(%rsp)
movl 0x110(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0x10c(%rsp), %eax
jg 0x3a1cf
movq 0x1a8(%rsp), %rax
movslq 0x9c(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
addsd 0xa0(%rsp), %xmm0
movsd %xmm0, 0xa0(%rsp)
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x3a185
movsd 0xa0(%rsp), %xmm1
divsd 0x120(%rsp), %xmm1
movsd 0x17e4f(%rip), %xmm0    # 0x52038
ucomisd %xmm1, %xmm0
jb 0x3a1f1
jmp 0x3a209
jmp 0x3a1f3
movl 0x114(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x114(%rsp)
jmp 0x39d6d
movq 0x148(%rsp), %rdi
callq 0x11c40
cmpq $0x0, %rax
jbe 0x3a373
movq 0x148(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc930
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movl $0x0, 0x8c(%rsp)
movl $0x0, 0x88(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x1c(%rsp)
movq 0x148(%rsp), %rdi
callq 0x11c40
movq %rax, %rcx
movl 0x1c(%rsp), %eax
cmpl %ecx, %eax
jge 0x3a2ef
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x148(%rsp), %rdi
movslq 0x88(%rsp), %rsi
callq 0xc930
movsd 0x10(%rsp), %xmm0
ucomisd (%rax), %xmm0
jbe 0x3a2d7
movq 0x148(%rsp), %rdi
movslq 0x88(%rsp), %rsi
callq 0xc930
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
movl 0x88(%rsp), %eax
movl %eax, 0x8c(%rsp)
jmp 0x3a2d9
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x3a254
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rdi
callq 0x2a410
movq %rax, 0x80(%rsp)
movq 0x140(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xc930
cvttsd2si (%rax), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0xc(%rax)
movq 0x138(%rsp), %rdi
movslq 0x8c(%rsp), %rsi
callq 0xc930
cvttsd2si (%rax), %ecx
movq 0x80(%rsp), %rax
movl %ecx, 0x20(%rax)
movq 0x188(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xc8c0
jmp 0x3a3a7
movq 0x1b0(%rsp), %rdi
movslq 0x134(%rsp), %rsi
callq 0xc800
movq (%rax), %rdi
callq 0x2a410
movq %rax, 0x78(%rsp)
movq 0x188(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xc8c0
movq 0x148(%rsp), %rdi
callq 0x3ae00
movq 0x140(%rsp), %rdi
callq 0x3ae00
movq 0x138(%rsp), %rdi
callq 0x3ae00
movl 0x134(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x134(%rsp)
jmp 0x39b6c
movq 0x160(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x3a401
movq 0x8(%rsp), %rdi
callq 0x2220
movq 0x150(%rsp), %rdi
cvttsd2si 0x180(%rsp), %esi
movl 0x15c(%rsp), %edx
callq 0x3f3a0
movq 0x188(%rsp), %rax
addq $0x1b8, %rsp            # imm = 0x1B8
retq
nop