// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %r9d, 0x20(%rsp)
movl %r8d, %ebx
movq %rcx, 0xa8(%rsp)
movl %edx, %ebp
movq %rsi, 0x30(%rsp)
movq %rdi, %r14
movl $0x18, %edi
callq 0x2180
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rax, 0x68(%rsp)
movq $0x0, 0x10(%rax)
movq (%r14), %r15
movq %r14, 0x10(%rsp)
movq 0x8(%r14), %r12
movq %r12, %rax
subq %r15, %rax
sarq $0x3, %rax
testl %eax, %eax
movl %ebx, 0x9c(%rsp)
jle 0x20c28
movslq %ebp, %r13
movslq %ebx, %rbp
movq %rax, 0xd0(%rsp)
movq %rax, %r14
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
xorl %ebx, %ebx
cmpq %r15, %r12
je 0x21410
movq (%r15,%rbx,8), %rcx
movslq 0xc(%rcx), %rax
movl 0x20(%rcx), %ecx
xorpd %xmm0, %xmm0
cmpl %ecx, %eax
jg 0x20c03
subl %eax, %ecx
incl %ecx
cmpq %r13, %rax
jge 0x20bea
movq 0x30(%rsp), %rdx
addsd (%rdx,%rax,8), %xmm0
cmpq %rbp, %rax
jge 0x20bfc
movq 0xa8(%rsp), %rdx
addsd (%rdx,%rax,8), %xmm0
incq %rax
decl %ecx
jne 0x20bdb
ucomisd 0x50(%rsp), %xmm0
jbe 0x20c1e
callq 0x22c0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
incq %rbx
cmpq %r14, %rbx
jne 0x20bbb
jmp 0x20c32
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
cmpb $0x0, 0x19597(%rip)     # 0x3a1d0
jne 0x213b6
movsd 0xcd71(%rip), %xmm0     # 0x2d9b8
addsd 0x50(%rsp), %xmm0
cvttsd2si %xmm0, %edi
callq 0x23bc5
cvtsi2sdl 0x20(%rsp), %xmm1
movapd 0x50(%rsp), %xmm0
movapd %xmm1, 0xc0(%rsp)
divsd %xmm1, %xmm0
addsd 0xa3a9(%rip), %xmm0     # 0x2b020
cvttsd2si %xmm0, %edi
movq %rax, 0x70(%rsp)
movq %rax, %rsi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x23a30
movq %rax, 0xa0(%rsp)
cmpb $0x1, 0x19534(%rip)     # 0x3a1d0
movq 0x30(%rsp), %r13
je 0x213d9
movl $0x18, %edi
callq 0x2180
movq %rax, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
xorl %ebx, %ebx
movq %rbx, 0x10(%rax)
movl $0x18, %edi
callq 0x2180
movq %rax, %r15
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rbx, 0x10(%rax)
movl $0x18, %edi
callq 0x2180
movq %rax, %rbp
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rbx, 0x10(%rax)
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
testl %edx, %edx
movq 0x68(%rsp), %rbx
jle 0x2137a
movapd 0xc0(%rsp), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0xc0(%rsp)
movq 0x70(%rsp), %rcx
leaq 0x8(%rcx), %rsi
movq %rsi, 0xe8(%rsp)
addq $-0x8, %rcx
movq %rcx, 0xe0(%rsp)
xorl %r12d, %r12d
movq %r14, 0xb0(%rsp)
movq %r15, 0x80(%rsp)
movq %rbp, 0x78(%rsp)
cmpq %r12, %rdx
jbe 0x21404
movq %r12, 0x18(%rsp)
movq (%rax,%r12,8), %rax
movl 0x20(%rax), %r12d
cmpl 0x9c(%rsp), %r12d
jg 0x21355
movslq 0xc(%rax), %rax
cmpl %r12d, %eax
jle 0x20d9a
xorpd %xmm0, %xmm0
movl $0xf4240, %r8d          # imm = 0xF4240
xorl %ebx, %ebx
jmp 0x20dfa
leaq (,%rax,8), %r14
addq %r13, %r14
subl %eax, %r12d
incl %r12d
xorl %r15d, %r15d
movl $0xf4240, %ebp          # imm = 0xF4240
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, 0x38(%rsp)
movsd (%r14,%r15,8), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0x22c0
cvttsd2si %xmm0, %r8d
movsd 0x38(%rsp), %xmm0
cmpl %r8d, %ebx
cmovlel %r8d, %ebx
cmpl %r8d, %ebp
cmovll %ebp, %r8d
addsd 0x20(%rsp), %xmm0
incq %r15
movl %r8d, %ebp
cmpl %r15d, %r12d
jne 0x20db9
movsd %xmm0, 0x38(%rsp)
movl $0x1f4, %eax            # imm = 0x1F4
cmpl %eax, %ebx
cmovgel %eax, %ebx
cmpl %ebx, %r8d
movq 0xb0(%rsp), %r14
movq 0x80(%rsp), %r15
movq 0x78(%rsp), %rbp
movl %ebx, 0x44(%rsp)
jg 0x211b4
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq 0x18(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x213f6
movq (%rax,%rsi,8), %rcx
movslq 0xc(%rcx), %rax
movl %eax, %r9d
movl 0x20(%rcx), %r12d
xorps %xmm0, %xmm0
cvtsi2sd %r8d, %xmm0
cmpl %r12d, %eax
jg 0x20e99
leaq (,%rax,8), %rcx
addq %r13, %rcx
movl %r12d, %edx
notl %edx
addq %r9, %rdx
xorl %esi, %esi
movsd (%rcx,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x20e94
incq %rsi
movl %edx, %edi
addl %esi, %edi
jne 0x20e7e
jmp 0x20e99
addl %esi, %eax
movl %eax, %r9d
movslq %r9d, %rdx
cmpl %r9d, %r12d
movq %r8, 0x88(%rsp)
movq %rdx, 0xb8(%rsp)
jl 0x20ed6
movslq %r12d, %rax
incq %rax
movl %r12d, %ecx
movsd -0x8(%r13,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
ja 0x20ed3
decl %ecx
decq %rax
cmpq %rdx, %rax
jg 0x20eba
jmp 0x20ed6
movl %ecx, %r12d
xorpd %xmm0, %xmm0
movq %r9, 0x48(%rsp)
cmpl %r12d, %r9d
jg 0x20f43
movq 0x30(%rsp), %rax
movq 0xb8(%rsp), %rcx
leaq (%rax,%rcx,8), %r14
movq 0xa8(%rsp), %rax
leaq (%rax,%rcx,8), %r15
movl %r12d, %r13d
subl 0x48(%rsp), %r13d
incl %r13d
xorl %ebp, %ebp
movapd %xmm0, 0x20(%rsp)
movsd (%r14,%rbp,8), %xmm0
callq 0x22c0
movhpd (%r15,%rbp,8), %xmm0    # xmm0 = xmm0[0],mem[0]
movapd 0x20(%rsp), %xmm1
addpd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movapd 0x20(%rsp), %xmm0
incq %rbp
cmpl %ebp, %r13d
jne 0x20f0e
divpd 0xc0(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movapd %xmm1, %xmm0
divsd 0xe180(%rip), %xmm0     # 0x2f0e8
cvttsd2si %xmm0, %ecx
imull $0x1f4, %ecx, %ecx      # imm = 0x1F4
movslq %eax, %r14
movq 0xa0(%rsp), %rax
movq (%rax,%r14,8), %rax
movslq %ecx, %r13
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x8(%rsp)
leal 0x1(%r13), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd %xmm0, %xmm1
movq 0x70(%rsp), %rbx
jb 0x21070
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
mulsd 0xe126(%rip), %xmm0     # 0x2f0e0
movsd %xmm0, 0xf0(%rsp)
leaq (,%r13,8), %rax
movq 0xe8(%rsp), %rcx
leaq (%rcx,%r13,8), %rbp
leaq (,%r14,8), %r15
subq %rax, %r15
addq 0xe0(%rsp), %r15
addl $0x2, %r13d
movapd %xmm1, 0xd0(%rsp)
movsd (%rbx,%r14,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd (%rbp), %xmm0
movsd (%r15), %xmm1
callq 0x259e1
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x25a1c
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x20(%rsp)
movsd 0xf0(%rsp), %xmm1
callq 0x259e1
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
callq 0x258cc
movapd 0xd0(%rsp), %xmm1
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
addq $0x8, %rbp
addq $-0x8, %r15
incl %r13d
ucomisd %xmm0, %xmm1
jae 0x20ff7
movq 0xb0(%rsp), %r14
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x21096
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%r14)
jmp 0x210a3
movq %r14, %rdi
leaq 0x8(%rsp), %rdx
callq 0xb836
movq 0x30(%rsp), %r13
movq 0x80(%rsp), %r15
movq 0x78(%rsp), %rbp
movl 0x44(%rsp), %ebx
movq 0x48(%rsp), %rcx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x90(%rsp)
movq 0x8(%r15), %rsi
cmpq 0x10(%r15), %rsi
movsd 0x38(%rsp), %xmm1
movq 0x88(%rsp), %rdx
je 0x210f4
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%r15)
jmp 0x21117
movq %r15, %rdi
leaq 0x90(%rsp), %rdx
callq 0x21e80
movq 0x48(%rsp), %rcx
movq 0x88(%rsp), %rdx
movsd 0x38(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x90(%rsp)
movq 0x8(%rbp), %rsi
cmpq 0x10(%rbp), %rsi
je 0x21140
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x8(%rbp)
jmp 0x21163
movq %rbp, %rdi
leaq 0x90(%rsp), %rdx
callq 0x21e80
movq 0x48(%rsp), %rcx
movq 0x88(%rsp), %rdx
movsd 0x38(%rsp), %xmm1
xorpd %xmm0, %xmm0
cmpl %r12d, %ecx
jg 0x21194
movq 0xb8(%rsp), %rax
leaq (,%rax,8), %rax
addq %r13, %rax
subl %ecx, %r12d
incl %r12d
xorl %ecx, %ecx
addsd (%rax,%rcx,8), %xmm0
incq %rcx
cmpl %ecx, %r12d
jne 0x21187
divsd %xmm1, %xmm0
movsd 0x9eb8(%rip), %xmm1     # 0x2b058
ucomisd %xmm0, %xmm1
jae 0x211b4
leal 0x1(%rdx), %eax
cmpl %ebx, %edx
movl %eax, %r8d
jl 0x20e2c
movq (%r14), %rax
movq 0x8(%r14), %rdx
subq %rax, %rdx
movq 0x18(%rsp), %r12
je 0x21210
sarq $0x3, %rdx
testl %edx, %edx
movq 0x68(%rsp), %rbx
jle 0x2125a
movsd (%rax), %xmm0
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %esi, %esi
xorl %edi, %edi
cmpq %rsi, %rdx
je 0x213ec
movsd (%rax,%rsi,8), %xmm1
ucomisd %xmm1, %xmm0
cmoval %esi, %edi
minsd %xmm0, %xmm1
incq %rsi
movapd %xmm1, %xmm0
cmpq %rsi, %rcx
jne 0x211e6
movslq %edi, %r12
jmp 0x2125d
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
movq 0x68(%rsp), %rbx
jbe 0x21404
movq (%rax,%r12,8), %rdi
callq 0x172ac
movq %rax, 0x8(%rsp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x21346
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x212f3
xorl %r12d, %r12d
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq 0x18(%rsp), %rsi
cmpq %rsi, %rdx
jbe 0x213f6
movq (%rax,%rsi,8), %rdi
callq 0x172ac
movq %rax, 0x8(%rsp)
movq (%r15), %rcx
movq 0x8(%r15), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x21404
cvttsd2si (%rcx,%r12,8), %ecx
movl %ecx, 0xc(%rax)
movq (%rbp), %rcx
movq 0x8(%rbp), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r12, %rdx
jbe 0x21404
cvttsd2si (%rcx,%r12,8), %ecx
movl %ecx, 0x20(%rax)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x212e1
movq %rax, (%rsi)
addq $0x8, 0x8(%rbx)
jmp 0x212ee
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0xb976
movq 0x18(%rsp), %r12
movq (%r14), %rax
cmpq %rax, 0x8(%r14)
je 0x21300
movq %rax, 0x8(%r14)
movq (%r15), %rax
cmpq %rax, 0x8(%r15)
je 0x2130d
movq %rax, 0x8(%r15)
movq (%rbp), %rax
cmpq %rax, 0x8(%rbp)
je 0x2131b
movq %rax, 0x8(%rbp)
incq %r12
movq 0x10(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
movq %rcx, %rdx
sarq $0x3, %rdx
shrq $0x3, %rcx
movslq %ecx, %rcx
cmpq %rcx, %r12
jl 0x20d5f
jmp 0x2137a
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0xb976
jmp 0x212f3
movq 0x18c84(%rip), %rcx     # 0x39fe0
movq (%rcx), %rdi
movl 0xc(%rax), %edx
leaq 0xdf22(%rip), %rsi      # 0x2f28b
movl %r12d, %ecx
xorl %eax, %eax
callq 0x2250
movq 0x18(%rsp), %r12
jmp 0x2131b
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x21389
callq 0x2220
cvttsd2si 0x50(%rsp), %esi
movq 0xa0(%rsp), %rdi
movl $0x1f4, %edx            # imm = 0x1F4
callq 0x23b82
movq %rbx, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18c23(%rip), %rax     # 0x39fe0
movq (%rax), %rdi
leaq 0xde47(%rip), %rsi      # 0x2f20e
movapd 0x50(%rsp), %xmm0
movb $0x1, %al
callq 0x2250
jmp 0x20c3f
movq 0x10(%rsp), %rsi
leaq 0x8(%rsi), %rdi
callq 0x52ca
jmp 0x20ca7
leal -0x1(%rdx), %esi
cmpq %rsi, %rdx
cmovbq %rdx, %rsi
leaq 0xc4d9(%rip), %rdi      # 0x2d8d6
xorl %eax, %eax
callq 0x2270
leaq 0xc4cb(%rip), %rdi      # 0x2d8d6
movq %r12, %rsi
jmp 0x213fd
leaq 0xc4bf(%rip), %rdi      # 0x2d8d6
movq 0xd0(%rsp), %rdx
movq %rdx, %rsi
jmp 0x213fd