// File: /workspace/github_cpp_makefile_star2_O1/auton1[P]viterbi/viterbi.cpp
// Function: viterbi(std::vector<std::vector<bool, std::allocator<bool>>, std::allocator<std::vector<bool, std::allocator<bool>>>> const&, std::vector<double, std::allocator<double>> const&, int, parameters const&, std::vector<int, std::allocator<int>>&)
void viterbi(const vector<vector<bool> > &haps, const vector<double> &map, int indv_idx, const parameters &params, vector<int> &out_path)
{
	int N_hap = haps.size()-1;	// The minus 1 accounts for the current haplotype.
	int N_pos = haps[0].size();
	vector<double> v(N_hap, 0.0);
	//vector<double> va(N_hap, -numeric_limits<double>::max());
	vector<double> vb(N_hap, -numeric_limits<double>::max());
	vector<double>::iterator it;
	vector<vector<unsigned short> > ptr(N_pos-1, vector<unsigned short>(N_hap, 0));	// Lots of memory used here

	double em_match = log(1.0 - params.p_error);
	double em_mismatch = max(log(params.p_error), -9999.9);

	vector<int> v_idx_to_hap_idx(N_hap);
	int idx_i=0;
	for (int i=0; i<haps.size(); i++)
	{
		if (i == indv_idx)
			continue;
		v_idx_to_hap_idx[idx_i] = i;

		if (haps[indv_idx][0] == haps[i][0])
			v[idx_i] = em_match;
		else
			v[idx_i] = em_mismatch;

		idx_i++;
	}

	int numthreads = min(min((int)thread::hardware_concurrency(), params.max_threads), 8);
	LOG.printLOG("Using " + output_log::int2str(numthreads) + " threads\n");
	int rows = N_hap / numthreads;
	int extra = N_hap % numthreads;
	int output_count = 0;

	struct timespec start_time;
	struct timespec end_time;
	double prev_elapsed = numeric_limits<double>::max();
	bool increase = true;

	#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
		clock_serv_t cclock;
		mach_timespec_t mts;
		host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
		clock_get_time(cclock, &mts);
		mach_port_deallocate(mach_task_self(), cclock);
		start_time.tv_sec = mts.tv_sec;
		start_time.tv_nsec = mts.tv_nsec;
	#else
		clock_gettime(CLOCK_REALTIME, &start_time);
	#endif

	for (int i=1; i < N_pos; i++)
	{
		bool allele = haps[indv_idx][i];
		double rho = 4.0*params.Ne*((map[i] - map[i-1])/100.0);

		double tmp = exp(-rho / N_hap);
		double p_rec = (1.0-tmp) / N_hap;
		double p_no_rec = tmp + p_rec;

		p_rec = log(p_rec);
		p_no_rec = log(p_no_rec);

		/*
		for (int j=0; j < N_hap; j++)	// Could parallelize this loop?
		{	// Fast Version
			transform(v.begin(), v.end(), va.begin(), bind2nd(std::plus<double>(), p_rec));
			va[j] = v[j] + p_no_rec;
			it = max_element(va.begin(), va.end());
			ptr[i-1][j] = distance(va.begin(), it);

			if (haps[ v_idx_to_hap_idx[j] ][i] == allele)
			{	// Match
				vb[j] = em_match + *it;
			}
			else
			{	// Mismatch
				vb[j] = em_mismatch + *it;
			}
		}
		*/

		int start = 0; int end = rows;
		vector<std::thread> workers;

		for (int t=0; t<numthreads; t++)
		{
			if (t == (numthreads-1))
				end += extra;	// Last thread does extra work

			workers.push_back(std::thread(inner_loop_viterbi, ref(v), p_rec, p_no_rec, ref(haps),
					em_match, em_mismatch, i, start, end,
					ref(v_idx_to_hap_idx), allele, ref(ptr), ref(vb)));
			start = end;
			end = end + rows;
		}
		for (thread& t : workers)
			t.join();

		v = vb;	// Replace old state with new state.

		if ((i % 100) == 0)
		{
			// Adaptive threading
			#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
				host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
				clock_get_time(cclock, &mts);
				mach_port_deallocate(mach_task_self(), cclock);
				end_time.tv_sec = mts.tv_sec;
				end_time.tv_nsec = mts.tv_nsec;
			#else
				clock_gettime(CLOCK_REALTIME, &end_time);
			#endif

			double elapsed = diff(start_time, end_time);

			LOG.printLOG(output_log::dbl2str(double(i)/N_pos*100, 3) + "% " + output_log::int2str(numthreads) + " threads " + output_log::dbl2str(elapsed, 3) + " seconds\n");

			if (((elapsed > prev_elapsed) && (increase == false)) || ((elapsed < prev_elapsed) && (increase == true)))
			{	// Try increasing the number of threads
				numthreads++;
				numthreads = min(numthreads, min((int)thread::hardware_concurrency(), params.max_threads));
				rows = N_hap / numthreads;
				extra = N_hap % numthreads;
				increase = true;
			}
			else if (((elapsed > prev_elapsed) && (increase == true)) || ((elapsed < prev_elapsed) && (increase == false)))
			{	// Try decreasing the number of threads
				numthreads -= 2;
				numthreads = max(numthreads, 1);
				rows = N_hap / numthreads;
				extra = N_hap % numthreads;
				increase = false;
			}
			prev_elapsed = elapsed;

			#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time
				host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
				clock_get_time(cclock, &mts);
				mach_port_deallocate(mach_task_self(), cclock);
				start_time.tv_sec = mts.tv_sec;
				start_time.tv_nsec = mts.tv_nsec;
			#else
				clock_gettime(CLOCK_REALTIME, &start_time);
			#endif
		}
	}

	double max_v = -numeric_limits<double>::max();
	int max_v_idx = -1;
	for (int j=0; j<N_hap; j++)
	{
		if (v[j] > max_v)
		{
			max_v = v[j];
			max_v_idx = j;
		}
	}

	LOG.printLOG("Best Path Prob: " + output_log::dbl2str(max_v,6) + "\n");

	out_path.resize(N_pos);
	out_path[N_pos-1] = v_idx_to_hap_idx[max_v_idx];
	for (int i=N_pos-2; i >= 0; i--)
	{
		max_v_idx = ptr[i][max_v_idx];
		out_path[i] = v_idx_to_hap_idx[max_v_idx];
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %r8, 0x1d0(%rsp)
movq %rcx, 0x78(%rsp)
movl %edx, %ebp
movq %rsi, 0x1f0(%rsp)
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
imull $0xcccccccd, %ecx, %ecx # imm = 0xCCCCCCCD
decl %ecx
movq (%rax), %r13
movq 0x10(%rax), %r15
movl 0x18(%rax), %eax
movq %rax, 0xf8(%rsp)
movl %ecx, 0x40(%rsp)
movslq %ecx, %r12
leaq 0x18(%rsp), %r14
movq $0x0, (%r14)
leaq 0x188(%rsp), %rdi
leaq 0x48(%rsp), %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0xb8e8
movabsq $-0x10000000000001, %rax # imm = 0xFFEFFFFFFFFFFFFF
movq %rax, (%r14)
leaq 0x240(%rsp), %rdi
leaq 0x18(%rsp), %rdx
leaq 0x48(%rsp), %rcx
movq %r12, %rsi
callq 0xb8e8
leaq 0x48(%rsp), %rdx
movw $0x0, (%rdx)
leaq 0x18(%rsp), %rdi
leaq 0x88(%rsp), %rcx
movq %r12, 0x100(%rsp)
movq %r12, %rsi
callq 0xbbc2
movq %r15, %rax
subq %r13, %rax
movq 0xf8(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, 0x68(%rsp)
shlq $0x20, %rcx
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
movq %rcx, 0x1c8(%rsp)
addq %rcx, %r14
sarq $0x20, %r14
leaq 0x170(%rsp), %rdi
leaq 0x18(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r14, %rsi
callq 0xbef4
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x840d
callq 0x5410
movq %r14, 0x1c0(%rsp)
movq %r15, 0x1b8(%rsp)
movsd 0x30bf3(%rip), %xmm0    # 0x39018
movq 0x78(%rsp), %r14
subsd 0x520(%r14), %xmm0
callq 0x5370
movsd %xmm0, 0x128(%rsp)
movsd 0x520(%r14), %xmm0
callq 0x5370
movsd 0x30bc9(%rip), %xmm1    # 0x39020
maxsd %xmm0, %xmm1
movsd %xmm1, 0x120(%rsp)
leaq 0x228(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq 0x100(%rsp), %rsi
callq 0xba90
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movslq %ebp, %r14
subq %rax, %rdx
je 0x851d
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
movq 0x228(%rsp), %rdx
leaq (%r14,%r14,4), %rsi
leaq (%rax,%rsi,8), %rsi
movq 0x188(%rsp), %rdi
movl %r14d, %r8d
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %r9d, %r9d
leaq 0x120(%rsp), %r10
leaq 0x128(%rsp), %r11
xorl %r15d, %r15d
cmpq %r9, %r8
je 0x8511
movslq %r15d, %r15
movl %r9d, (%rdx,%r15,4)
movq (%rsi), %r12
movl (%r12), %ebp
movq (%rax), %r12
xorl (%r12), %ebp
movq %r10, %r12
testb $0x1, %bpl
jne 0x8502
movq %r11, %r12
movsd (%r12), %xmm0
movsd %xmm0, (%rdi,%r15,8)
incl %r15d
incq %r9
addq $0x28, %rax
cmpq %r9, %rcx
jne 0x84dc
callq 0x55e0
movq 0x78(%rsp), %rcx
movl 0x528(%rcx), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl $0x8, %eax
movl $0x8, %esi
cmovll %eax, %esi
leaq 0x48(%rsp), %rdi
movl %esi, 0x10(%rsp)
callq 0x375de
leaq 0x30bab(%rip), %rcx     # 0x390fd
leaq 0x48(%rsp), %rdi
movl $0x6, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
leaq 0x28(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x858d
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x8595
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x30b4c(%rip), %rsi     # 0x39104
callq 0x5870
leaq 0x298(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x85ed
movq %rdx, 0x288(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x298(%rsp)
jmp 0x85f6
movupd (%rcx), %xmm0
movupd %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x288(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x41e8c(%rip), %rdi     # 0x4a4a8
callq 0x371c8
movq 0x288(%rsp), %rdi
cmpq %r15, %rdi
je 0x8633
callq 0x5410
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
leaq 0x170(%rsp), %r15
je 0x864f
callq 0x5410
movq %r13, 0xf0(%rsp)
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x866a
callq 0x5410
leaq 0x1f8(%rsp), %rsi
xorl %edi, %edi
callq 0x53f0
movl $0x1, 0x14(%rsp)
cmpl $0x2, 0x68(%rsp)
jl 0x8ee6
movl 0x40(%rsp), %ecx
movl %ecx, %eax
cltd
idivl 0x10(%rsp)
movl %eax, %r13d
movl %edx, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x110(%rsp)
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorps %xmm0, %xmm0
cvtsi2sdl 0x68(%rsp), %xmm0
movsd %xmm0, 0x1d8(%rsp)
movl $0x1, %eax
movb $0x1, %dl
movl %edx, 0x44(%rsp)
movsd 0x30963(%rip), %xmm0    # 0x39040
movsd %xmm0, 0x108(%rsp)
leaq (%r14,%r14,4), %rdx
movq %rdx, 0x1e8(%rsp)
addq $0x3f, %rcx
movq %rcx, 0x1e0(%rsp)
leaq 0x18(%rsp), %rbp
leaq 0x1a0(%rsp), %r12
movq (%rbx), %rcx
cltq
leaq 0x3f(%rax), %rdx
testq %rax, %rax
cmovnsq %rax, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
movq 0x1e8(%rsp), %rsi
addq (%rcx,%rsi,8), %rdx
movq %rax, %rcx
andq 0x1e0(%rsp), %rcx
xorl %esi, %esi
movabsq $-0x8000000000000000, %rdi # imm = 0x8000000000000000
cmpq %rdi, %rcx
setbe %sil
movq -0x8(%rdx,%rsi,8), %rcx
btq %rax, %rcx
setb 0xf(%rsp)
movq 0x1f0(%rsp), %rcx
movq (%rcx), %rcx
movsd (%rcx,%rax,8), %xmm1
subsd -0x8(%rcx,%rax,8), %xmm1
divsd 0x308af(%rip), %xmm1    # 0x39028
movq 0x78(%rsp), %rax
movsd 0x4f0(%rax), %xmm0
mulsd 0x308a2(%rip), %xmm0    # 0x39030
mulsd %xmm1, %xmm0
divsd 0x110(%rsp), %xmm0
callq 0x57e0
movsd 0x30870(%rip), %xmm1    # 0x39018
subsd %xmm0, %xmm1
divsd 0x110(%rsp), %xmm1
movsd %xmm1, 0x118(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0xc8(%rsp)
movapd %xmm1, %xmm0
callq 0x5370
movsd %xmm0, 0x118(%rsp)
movsd 0xc8(%rsp), %xmm0
callq 0x5370
movsd %xmm0, 0xc8(%rsp)
movl $0x0, 0x74(%rsp)
movl %r13d, 0x3c(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x1a0(%rsp)
movq $0x0, 0x1b0(%rsp)
movl 0x10(%rsp), %eax
movl %eax, %r14d
testl %eax, %eax
jle 0x891f
cmpl $0x1, %r14d
jne 0x8837
movl 0x70(%rsp), %eax
addl %eax, 0x3c(%rsp)
leaq 0x188(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbx, 0x88(%rsp)
leaq 0x228(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq %r15, 0x208(%rsp)
leaq 0x240(%rsp), %rax
movq %rax, 0xd0(%rsp)
subq $0x8, %rsp
movq %rbp, %rdi
leaq -0x192c(%rip), %rsi     # 0x6f56
leaq 0x50(%rsp), %rdx
leaq 0x120(%rsp), %rcx
leaq 0xd0(%rsp), %r8
leaq 0x90(%rsp), %r9
leaq 0xd8(%rsp), %rax
pushq %rax
leaq 0x218(%rsp), %rax
pushq %rax
leaq 0x27(%rsp), %rax
pushq %rax
leaq 0xc8(%rsp), %rax
pushq %rax
leaq 0x64(%rsp), %rax
pushq %rax
leaq 0xa4(%rsp), %rax
pushq %rax
leaq 0x4c(%rsp), %rax
pushq %rax
leaq 0x160(%rsp), %rax
pushq %rax
leaq 0x170(%rsp), %rax
pushq %rax
callq 0xbf84
addq $0x50, %rsp
movq %r12, %rdi
movq %rbp, %rsi
callq 0xd8d6
cmpq $0x0, 0x18(%rsp)
jne 0x9156
movl 0x3c(%rsp), %eax
movl %eax, 0x74(%rsp)
addl %r13d, %eax
movl %eax, 0x3c(%rsp)
decl %r14d
jne 0x8829
movq 0x1a0(%rsp), %r14
movq 0x1a8(%rsp), %r15
cmpq %r15, %r14
je 0x8942
movq %r14, %rdi
callq 0x5780
addq $0x8, %r14
jmp 0x892f
leaq 0x188(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0xc0be
imull $0xc28f5c29, 0x14(%rsp), %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c28, %eax        # imm = 0x28F5C28
jbe 0x897b
leaq 0x170(%rsp), %r15
jmp 0x8eca
xorl %edi, %edi
leaq 0x278(%rsp), %rsi
callq 0x53f0
movq 0x280(%rsp), %rax
subq 0x200(%rsp), %rax
movq 0x1f8(%rsp), %r14
leaq 0x3b9aca00(%rax), %rcx
movq %r14, %rdx
negq %rdx
testq %rax, %rax
notq %r14
cmovnsq %rax, %rcx
cmovnsq %rdx, %r14
addq 0x278(%rsp), %r14
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
divsd 0x3063b(%rip), %xmm0    # 0x39010
movsd %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rsp), %xmm0
divsd 0x1d8(%rsp), %xmm0
mulsd 0x30630(%rip), %xmm0    # 0x39028
leaq 0x208(%rsp), %r15
movq %r15, %rdi
movl $0x3, %esi
callq 0x376f6
movq %r15, %rdi
leaq 0x306f7(%rip), %rsi     # 0x3910e
callq 0x5870
leaq 0xb8(%rsp), %rsi
movq %rsi, 0xa8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8a50
movq %rdx, 0xa8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb8(%rsp)
jmp 0x8a58
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0xb0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xd0(%rsp), %rdi
movl 0x10(%rsp), %esi
callq 0x375de
movq 0xa8(%rsp), %rcx
movl $0xf, %esi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rcx
je 0x8aa6
movq 0xb8(%rsp), %rsi
movq 0xb0(%rsp), %r8
movq 0xd8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x8ae3
movl $0xf, %esi
leaq 0xe0(%rsp), %rdi
cmpq %rdi, 0xd0(%rsp)
je 0x8ade
movq 0xe0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x8afa
movq 0xd0(%rsp), %rsi
leaq 0xa8(%rsp), %rdi
callq 0x50f0
jmp 0x8b0b
leaq 0xd0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
leaq 0x98(%rsp), %rsi
movq %rsi, 0x88(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x8b3c
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x8b44
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x90(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x88(%rsp), %rdi
leaq 0x3059e(%rip), %rsi     # 0x39111
callq 0x5870
leaq 0x58(%rsp), %rsi
movq %rsi, 0x48(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movsd 0x80(%rsp), %xmm0
je 0x8ba9
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x8bb1
movupd (%rcx), %xmm1
movupd %xmm1, (%rsi)
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
addsd %xmm1, %xmm0
movq 0x8(%rax), %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x130(%rsp), %rdi
movsd %xmm0, 0x80(%rsp)
movl $0x3, %esi
callq 0x376f6
movq 0x48(%rsp), %rcx
movl $0xf, %esi
leaq 0x58(%rsp), %rax
cmpq %rax, %rcx
leaq 0x28(%rsp), %r14
je 0x8c0e
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %r8
movq 0x138(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rsi, %rax
jbe 0x8c48
movl $0xf, %esi
leaq 0x140(%rsp), %rdi
cmpq %rdi, 0x130(%rsp)
je 0x8c43
movq 0x140(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x8c5c
movq 0x130(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x50f0
jmp 0x8c6d
leaq 0x130(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
movq %r14, 0x18(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x8c8d
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x8c96
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x20(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq %rbp, %rdi
leaq 0x3045e(%rip), %rsi     # 0x3911b
callq 0x5870
leaq 0x160(%rsp), %rsi
movq %rsi, 0x150(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8cf6
movq %rdx, 0x150(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x160(%rsp)
jmp 0x8cfe
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x158(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x41788(%rip), %rdi     # 0x4a4a8
leaq 0x150(%rsp), %rsi
callq 0x371c8
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x8d47
callq 0x5410
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0x8d56
callq 0x5410
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
leaq 0xb8(%rsp), %r14
je 0x8d78
callq 0x5410
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x8d8c
callq 0x5410
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
leaq 0x170(%rsp), %r15
je 0x8dae
callq 0x5410
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x8dc8
callq 0x5410
movq 0xa8(%rsp), %rdi
cmpq %r14, %rdi
je 0x8dda
callq 0x5410
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x8df4
callq 0x5410
movl 0x44(%rsp), %edx
movl %edx, %eax
andb $0x1, %al
movsd 0x108(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e44
testb %al, %al
jne 0x8e44
movl 0x10(%rsp), %r14d
incl %r14d
callq 0x55e0
movq 0x78(%rsp), %rcx
movl 0x528(%rcx), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl %r14d, %eax
cmovll %eax, %r14d
movb $0x1, %al
movl %eax, 0x44(%rsp)
jmp 0x8e95
ucomisd %xmm1, %xmm0
jbe 0x8e4f
testb $0x1, %dl
jne 0x8e18
ucomisd %xmm0, %xmm1
jbe 0x8e6d
ucomisd %xmm1, %xmm0
seta %al
testb $0x1, %dl
sete %cl
testb $0x1, %dl
jne 0x8e77
andb %cl, %al
je 0x8ea9
jmp 0x8e77
ucomisd %xmm1, %xmm0
jbe 0x8ea9
testb %al, %al
jne 0x8ea9
movl 0x10(%rsp), %r14d
cmpl $0x4, %r14d
movl $0x3, %eax
cmovll %eax, %r14d
addl $-0x2, %r14d
movl $0x0, 0x44(%rsp)
movl 0x40(%rsp), %eax
cltd
movl %r14d, 0x10(%rsp)
idivl %r14d
movl %edx, 0x70(%rsp)
movl %eax, %r13d
xorl %edi, %edi
leaq 0x1f8(%rsp), %rsi
callq 0x53f0
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x108(%rsp)
movq %r12, %rdi
callq 0xc18c
movl 0x14(%rsp), %eax
incl %eax
movl %eax, 0x14(%rsp)
cmpl 0x68(%rsp), %eax
jl 0x870b
cmpl $0x0, 0x40(%rsp)
jle 0x8f3c
movq 0x188(%rsp), %rax
movsd 0x3013b(%rip), %xmm1    # 0x39038
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq 0xf0(%rsp), %r15
movq 0x68(%rsp), %r12
movq 0x100(%rsp), %rdx
leaq 0x28(%rsp), %r14
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
cmoval %ecx, %ebx
maxsd %xmm1, %xmm0
incq %rcx
movapd %xmm0, %xmm1
cmpq %rcx, %rdx
jne 0x8f1e
jmp 0x8f5b
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movsd 0x300ef(%rip), %xmm0    # 0x39038
movq 0xf0(%rsp), %r15
movq 0x68(%rsp), %r12
leaq 0x28(%rsp), %r14
leaq 0x48(%rsp), %rdi
movl $0x6, %esi
callq 0x376f6
leaq 0x301b4(%rip), %rcx     # 0x39125
leaq 0x48(%rsp), %rdi
movl $0x10, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
movq %r14, 0x18(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8fa8
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0x8fb1
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x30182(%rip), %rsi     # 0x39156
callq 0x5870
leaq 0x268(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9009
movq %rdx, 0x258(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x268(%rsp)
jmp 0x9012
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x258(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x41470(%rip), %rdi     # 0x4a4a8
callq 0x371c8
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x904f
callq 0x5410
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
movq 0x1d0(%rsp), %r14
je 0x906b
callq 0x5410
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x907f
callq 0x5410
movq 0x1c8(%rsp), %rsi
sarq $0x20, %rsi
movq %r14, %rdi
callq 0xc1c0
movslq %ebx, %rax
movq 0x228(%rsp), %rdi
movl (%rdi,%rax,4), %eax
movq (%r14), %rcx
movq 0x1c0(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
cmpl $0x2, %r12d
jl 0x9109
addl $-0x2, %r12d
movq 0x1b8(%rsp), %rax
movq 0xf8(%rsp), %rdx
leal (%rdx,%rax,8), %eax
shll $0x3, %r15d
notl %r15d
addl %eax, %r15d
leaq (%r12,%r12,2), %rax
shlq $0x3, %rax
addq 0x170(%rsp), %rax
leaq (%rcx,%r12,4), %rcx
movslq %ebx, %rdx
movq (%rax), %rsi
movzwl (%rsi,%rdx,2), %ebx
movl (%rdi,%rbx,4), %edx
movl %edx, (%rcx)
decl %r15d
addq $-0x18, %rax
addq $-0x4, %rcx
testl %r15d, %r15d
jg 0x90ea
testq %rdi, %rdi
je 0x9113
callq 0x5410
leaq 0x170(%rsp), %rdi
callq 0xc1f2
movq 0x240(%rsp), %rdi
testq %rdi, %rdi
je 0x9132
callq 0x5410
movq 0x188(%rsp), %rdi
testq %rdi, %rdi
je 0x9144
callq 0x5410
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x50d0
jmp 0x91f9
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r14, %rdi
je 0x917a
callq 0x5410
jmp 0x917a
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9193
callq 0x5410
jmp 0x9193
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x934f
jmp 0x91ef
jmp 0x91f9
movq %rax, %rbx
movq 0x288(%rsp), %rdi
cmpq %r15, %rdi
je 0x91c4
callq 0x5410
jmp 0x91c4
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x91dd
callq 0x5410
jmp 0x91dd
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x934f
callq 0x5410
jmp 0x934f
movq %rax, %rbx
jmp 0x934f
movq %rax, %rbx
jmp 0x9361
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x936e
callq 0x5410
jmp 0x936e
movq %rax, %rbx
jmp 0x936e
movq %rax, %rbx
jmp 0x9380
jmp 0x933f
movq %rax, %rbx
jmp 0x927d
movq %rax, %rbx
jmp 0x92de
movq %rax, %rbx
jmp 0x9291
movq %rax, %rbx
jmp 0x92f8
movq %rax, %rbx
jmp 0x92ab
movq %rax, %rbx
jmp 0x9312
movq %rax, %rbx
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x927d
callq 0x5410
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x9291
callq 0x5410
movq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %rax
cmpq %rax, %rdi
je 0x92ab
callq 0x5410
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x92c4
callq 0x5410
jmp 0x92c4
movq %rax, %rbx
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x92de
callq 0x5410
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x92f8
callq 0x5410
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x9312
callq 0x5410
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x9342
callq 0x5410
jmp 0x9342
jmp 0x933f
jmp 0x933f
cmpq $0x0, 0x18(%rsp)
je 0x933f
callq 0x50d0
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0xc18c
movq 0x228(%rsp), %rdi
testq %rdi, %rdi
je 0x9361
callq 0x5410
leaq 0x170(%rsp), %rdi
callq 0xc1f2
movq 0x240(%rsp), %rdi
testq %rdi, %rdi
je 0x9380
callq 0x5410
movq 0x188(%rsp), %rdi
testq %rdi, %rdi
je 0x9392
callq 0x5410
movq %rbx, %rdi
callq 0x57d0