// File: /workspace/github_cpp_makefile_star2_O3/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, 0x1b0(%rsp)
movq %rcx, 0x70(%rsp)
movl %edx, %ebp
movq %rsi, 0x1d0(%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, 0xd0(%rsp)
movl %ecx, 0x38(%rsp)
movslq %ecx, %r12
leaq 0x10(%rsp), %r14
movq $0x0, (%r14)
leaq 0x180(%rsp), %rdi
leaq 0x40(%rsp), %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0xb886
movabsq $-0x10000000000001, %rax # imm = 0xFFEFFFFFFFFFFFFF
movq %rax, (%r14)
leaq 0x220(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movq %r12, %rsi
callq 0xb886
leaq 0x40(%rsp), %rdx
movw $0x0, (%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x80(%rsp), %rcx
movq %r12, 0xd8(%rsp)
movq %r12, %rsi
callq 0xbb72
movq %r15, %rax
subq %r13, %rax
movq 0xd0(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, 0x60(%rsp)
shlq $0x20, %rcx
movabsq $-0x100000000, %r14     # imm = 0xFFFFFFFF00000000
movq %rcx, 0x1a8(%rsp)
addq %rcx, %r14
sarq $0x20, %r14
leaq 0x208(%rsp), %rdi
leaq 0x10(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
movq %r14, %rsi
callq 0xbeb2
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x8436
callq 0x5410
movq %r14, 0x1a0(%rsp)
movq %r15, 0x198(%rsp)
movsd 0x2fbca(%rip), %xmm0    # 0x38018
movq 0x70(%rsp), %r14
subsd 0x520(%r14), %xmm0
callq 0x5370
movsd %xmm0, 0x118(%rsp)
movsd 0x520(%r14), %xmm0
callq 0x5370
movsd 0x2fba0(%rip), %xmm1    # 0x38020
maxsd %xmm0, %xmm1
movsd %xmm1, 0x110(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x10(%rsp), %rdx
movq 0xd8(%rsp), %rsi
callq 0xba38
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movslq %ebp, %r14
subq %rax, %rdx
je 0x8546
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %rcx
movq 0x1f0(%rsp), %rdx
leaq (%r14,%r14,4), %rsi
leaq (%rax,%rsi,8), %rsi
movq 0x180(%rsp), %rdi
movl %r14d, %r8d
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %r9d, %r9d
leaq 0x110(%rsp), %r10
leaq 0x118(%rsp), %r11
xorl %r15d, %r15d
cmpq %r9, %r8
je 0x853a
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 0x852b
movq %r11, %r12
movsd (%r12), %xmm0
movsd %xmm0, (%rdi,%r15,8)
incl %r15d
incq %r9
addq $0x28, %rax
cmpq %r9, %rcx
jne 0x8505
callq 0x55e0
movq 0x70(%rsp), %rcx
movl 0x528(%rcx), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl $0x8, %eax
movl $0x8, %esi
cmovll %eax, %esi
leaq 0x40(%rsp), %rdi
movl %esi, 0x8(%rsp)
callq 0x37288
leaq 0x2fb82(%rip), %rcx     # 0x380fd
leaq 0x40(%rsp), %rdi
movl $0x6, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
leaq 0x20(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x85b6
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x85be
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x2fb23(%rip), %rsi     # 0x38104
callq 0x5870
leaq 0x298(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8616
movq %rdx, 0x288(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x298(%rsp)
jmp 0x861f
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 0x40e63(%rip), %rdi     # 0x494a8
callq 0x36e72
movq 0x288(%rsp), %rdi
cmpq %r15, %rdi
je 0x865c
callq 0x5410
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x8670
callq 0x5410
movq %r13, 0xc8(%rsp)
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x868b
callq 0x5410
leaq 0x1e0(%rsp), %rsi
xorl %edi, %edi
callq 0x53f0
movl $0x1, 0xc(%rsp)
cmpl $0x2, 0x60(%rsp)
jl 0x8ee5
movl 0x38(%rsp), %ecx
movl %ecx, %eax
cltd
idivl 0x8(%rsp)
movl %eax, %r13d
movl %edx, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0xe8(%rsp)
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorps %xmm0, %xmm0
cvtsi2sdl 0x60(%rsp), %xmm0
movsd %xmm0, 0x1b8(%rsp)
movl $0x1, %eax
movb $0x1, %dl
movl %edx, 0x3c(%rsp)
movsd 0x2f942(%rip), %xmm0    # 0x38040
movsd %xmm0, 0xe0(%rsp)
leaq (%r14,%r14,4), %rdx
movq %rdx, 0x1c8(%rsp)
addq $0x3f, %rcx
movq %rcx, 0x1c0(%rsp)
leaq 0x258(%rsp), %r15
leaq 0x10(%rsp), %rbp
movq %r15, %r12
movq (%rbx), %rcx
cltq
leal 0x3f(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x6, %edx
movslq %edx, %rdx
shlq $0x3, %rdx
movq 0x1c8(%rsp), %rsi
addq (%rcx,%rsi,8), %rdx
movq %rax, %rcx
andq 0x1c0(%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 0x7(%rsp)
movq 0x1d0(%rsp), %rcx
movq (%rcx), %rcx
movsd (%rcx,%rax,8), %xmm1
subsd -0x8(%rcx,%rax,8), %xmm1
divsd 0x2f88c(%rip), %xmm1    # 0x38028
movq 0x70(%rsp), %rax
movsd 0x4f0(%rax), %xmm0
mulsd 0x2f87f(%rip), %xmm0    # 0x38030
mulsd %xmm1, %xmm0
divsd 0xe8(%rsp), %xmm0
callq 0x57e0
movsd 0x2f84d(%rip), %xmm1    # 0x38018
subsd %xmm0, %xmm1
divsd 0xe8(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, 0xc0(%rsp)
movapd %xmm1, %xmm0
callq 0x5370
movsd %xmm0, 0x1d8(%rsp)
movsd 0xc0(%rsp), %xmm0
callq 0x5370
movsd %xmm0, 0xc0(%rsp)
movl $0x0, 0x6c(%rsp)
movl %r13d, 0x34(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x160(%rsp)
movq $0x0, 0x170(%rsp)
movl 0x8(%rsp), %ecx
movl %ecx, %r14d
movl %r13d, %eax
testl %ecx, %ecx
jle 0x8965
cmpl $0x1, %r14d
jne 0x8854
addl 0x68(%rsp), %eax
movl %eax, 0x34(%rsp)
leaq 0x180(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %rbx, 0x80(%rsp)
leaq 0x1f0(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x208(%rsp), %rax
movq %rax, 0x258(%rsp)
leaq 0x220(%rsp), %rax
movq %rax, 0xf0(%rsp)
subq $0x8, %rsp
movq %rbp, %rdi
leaq -0x1951(%rip), %rsi     # 0x6f56
leaq 0x48(%rsp), %rdx
leaq 0x1e0(%rsp), %rcx
leaq 0xc8(%rsp), %r8
leaq 0x88(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
pushq %r12
leaq 0x1f(%rsp), %rax
pushq %rax
leaq 0xc0(%rsp), %rax
pushq %rax
leaq 0x5c(%rsp), %rax
pushq %rax
leaq 0x9c(%rsp), %rax
pushq %rax
leaq 0x44(%rsp), %rax
pushq %rax
leaq 0x150(%rsp), %rax
pushq %rax
leaq 0x160(%rsp), %rax
pushq %rax
callq 0xbf42
addq $0x50, %rsp
leaq 0x160(%rsp), %rdi
movq %rbp, %rsi
callq 0xd8da
cmpq $0x0, 0x10(%rsp)
jne 0x9150
movl 0x34(%rsp), %eax
movl %eax, 0x6c(%rsp)
addl %r13d, %eax
movl %eax, 0x34(%rsp)
decl %r14d
jne 0x8846
movq 0x160(%rsp), %r14
movq 0x168(%rsp), %r15
cmpq %r15, %r14
je 0x8965
movq %r14, %rdi
callq 0x5780
addq $0x8, %r14
jmp 0x8952
leaq 0x180(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0xc06a
imull $0xc28f5c29, 0xc(%rsp), %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c28, %eax        # imm = 0x28F5C28
movq %r12, %r15
ja 0x8ec4
xorl %edi, %edi
leaq 0x278(%rsp), %rsi
callq 0x53f0
movq 0x280(%rsp), %rax
subq 0x1e8(%rsp), %rax
movq 0x1e0(%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 0x2f61e(%rip), %xmm0    # 0x38010
movsd %xmm0, 0x78(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rsp), %xmm0
divsd 0x1b8(%rsp), %xmm0
mulsd 0x2f616(%rip), %xmm0    # 0x38028
movq %r15, %rdi
movl $0x3, %esi
callq 0x373a0
movq %r15, %rdi
leaq 0x2f6e5(%rip), %rsi     # 0x3810e
callq 0x5870
leaq 0xb0(%rsp), %rsi
movq %rsi, 0xa0(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8a62
movq %rdx, 0xa0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xb0(%rsp)
jmp 0x8a6a
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0xa8(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xf0(%rsp), %rdi
movl 0x8(%rsp), %esi
callq 0x37288
movq 0xa0(%rsp), %rcx
movl $0xf, %edi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rcx
je 0x8ab8
movq 0xb0(%rsp), %rdi
movq 0xa8(%rsp), %r8
movq 0xf0(%rsp), %rsi
movq 0xf8(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x8af8
movl $0xf, %edi
leaq 0x100(%rsp), %r9
cmpq %r9, %rsi
je 0x8af3
movq 0x100(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x8b07
leaq 0xa0(%rsp), %rdi
callq 0x50f0
jmp 0x8b18
leaq 0xf0(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
leaq 0x90(%rsp), %rsi
movq %rsi, 0x80(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x8b49
movq %rdx, 0x80(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x90(%rsp)
jmp 0x8b51
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x88(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x80(%rsp), %rdi
leaq 0x2f591(%rip), %rsi     # 0x38111
callq 0x5870
leaq 0x50(%rsp), %rsi
movq %rsi, 0x40(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movsd 0x78(%rsp), %xmm0
je 0x8bb3
movq %rdx, 0x40(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x50(%rsp)
jmp 0x8bbb
movupd (%rcx), %xmm1
movupd %xmm1, (%rsi)
xorps %xmm1, %xmm1
cvtsi2sd %r14, %xmm1
addsd %xmm1, %xmm0
movq 0x8(%rax), %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x120(%rsp), %rdi
movsd %xmm0, 0x78(%rsp)
movl $0x3, %esi
callq 0x373a0
movq 0x40(%rsp), %rcx
movl $0xf, %edi
leaq 0x50(%rsp), %rax
cmpq %rax, %rcx
leaq 0x20(%rsp), %r14
je 0x8c15
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %r8
movq 0x120(%rsp), %rsi
movq 0x128(%rsp), %rdx
leaq (%rdx,%r8), %rax
cmpq %rdi, %rax
jbe 0x8c52
movl $0xf, %edi
leaq 0x130(%rsp), %r9
cmpq %r9, %rsi
je 0x8c4d
movq 0x130(%rsp), %rdi
cmpq %rdi, %rax
jbe 0x8c5e
leaq 0x40(%rsp), %rdi
callq 0x50f0
jmp 0x8c6f
leaq 0x120(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
movq %r14, 0x10(%rsp)
movq (%rax), %rdx
leaq 0x10(%rax), %rcx
cmpq %rcx, %rdx
je 0x8c8f
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8c98
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq %rbp, %rdi
leaq 0x2f45c(%rip), %rsi     # 0x3811b
callq 0x5870
leaq 0x150(%rsp), %rsi
movq %rsi, 0x140(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8cf8
movq %rdx, 0x140(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x150(%rsp)
jmp 0x8d00
movupd (%rcx), %xmm0
movupd %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x148(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40786(%rip), %rdi     # 0x494a8
leaq 0x140(%rsp), %rsi
callq 0x36e72
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x8d49
callq 0x5410
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x8d58
callq 0x5410
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
leaq 0xb0(%rsp), %r14
je 0x8d7a
callq 0x5410
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x8d8e
callq 0x5410
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x8da8
callq 0x5410
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x8dc2
callq 0x5410
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x8dd4
callq 0x5410
movq 0x258(%rsp), %rdi
leaq 0x268(%rsp), %rax
cmpq %rax, %rdi
movq %r12, %r15
je 0x8df1
callq 0x5410
movl 0x3c(%rsp), %edx
movl %edx, %eax
andb $0x1, %al
movsd 0xe0(%rsp), %xmm0
movsd 0x78(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x8e3e
testb %al, %al
jne 0x8e3e
movl 0x8(%rsp), %r14d
incl %r14d
callq 0x55e0
movq 0x70(%rsp), %rcx
movl 0x528(%rcx), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl %r14d, %eax
cmovll %eax, %r14d
movb $0x1, %al
movl %eax, 0x3c(%rsp)
jmp 0x8e8f
ucomisd %xmm1, %xmm0
jbe 0x8e49
testb $0x1, %dl
jne 0x8e12
ucomisd %xmm0, %xmm1
jbe 0x8e67
ucomisd %xmm1, %xmm0
seta %al
testb $0x1, %dl
sete %cl
testb $0x1, %dl
jne 0x8e71
andb %cl, %al
je 0x8ea6
jmp 0x8e71
ucomisd %xmm1, %xmm0
jbe 0x8ea6
testb %al, %al
jne 0x8ea6
movl 0x8(%rsp), %r14d
cmpl $0x4, %r14d
movl $0x3, %eax
cmovll %eax, %r14d
addl $-0x2, %r14d
movl $0x0, 0x3c(%rsp)
movl 0x38(%rsp), %eax
cltd
movl %r14d, 0x8(%rsp)
idivl %r14d
movl %edx, 0x68(%rsp)
movl %eax, %r13d
movq %r12, %r15
xorl %edi, %edi
leaq 0x1e0(%rsp), %rsi
callq 0x53f0
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0xe0(%rsp)
leaq 0x160(%rsp), %rdi
callq 0xc146
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl 0x60(%rsp), %eax
jl 0x872c
cmpl $0x0, 0x38(%rsp)
jle 0x8f3b
movq 0x180(%rsp), %rax
movsd 0x2f13c(%rip), %xmm1    # 0x38038
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq 0xc8(%rsp), %r15
movq 0x60(%rsp), %r12
movq 0xd8(%rsp), %rdx
leaq 0x20(%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 0x8f1d
jmp 0x8f5a
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movsd 0x2f0f0(%rip), %xmm0    # 0x38038
movq 0xc8(%rsp), %r15
movq 0x60(%rsp), %r12
leaq 0x20(%rsp), %r14
leaq 0x40(%rsp), %rdi
movl $0x6, %esi
callq 0x373a0
leaq 0x2f1b5(%rip), %rcx     # 0x38125
leaq 0x40(%rsp), %rdi
movl $0x10, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x54d0
movq %r14, 0x10(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x8fa7
movq %rdx, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x8fb0
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x10(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x2f183(%rip), %rsi     # 0x38156
callq 0x5870
leaq 0x248(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x9008
movq %rdx, 0x238(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x248(%rsp)
jmp 0x9011
movupd (%rcx), %xmm0
movupd %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x238(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x40471(%rip), %rdi     # 0x494a8
callq 0x36e72
movq 0x238(%rsp), %rdi
cmpq %r14, %rdi
je 0x904e
callq 0x5410
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
movq 0x1b0(%rsp), %r14
je 0x906a
callq 0x5410
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x907e
callq 0x5410
movq 0x1a8(%rsp), %rsi
sarq $0x20, %rsi
movq %r14, %rdi
callq 0xc17a
movslq %ebx, %rax
movq 0x1f0(%rsp), %rdi
movl (%rdi,%rax,4), %eax
movq (%r14), %rcx
movq 0x1a0(%rsp), %rdx
movl %eax, (%rcx,%rdx,4)
cmpl $0x2, %r12d
jl 0x9108
addl $-0x2, %r12d
movq 0x198(%rsp), %rax
movq 0xd0(%rsp), %rdx
leal (%rdx,%rax,8), %eax
shll $0x3, %r15d
notl %r15d
addl %eax, %r15d
leaq (%r12,%r12,2), %rax
shlq $0x3, %rax
addq 0x208(%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 0x90e9
callq 0x5410
leaq 0x208(%rsp), %rdi
callq 0xc1ac
movq 0x220(%rsp), %rdi
testq %rdi, %rdi
je 0x912c
callq 0x5410
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x913e
callq 0x5410
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x50d0
jmp 0x91f3
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r14, %rdi
je 0x9174
callq 0x5410
jmp 0x9174
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x918d
callq 0x5410
jmp 0x918d
movq %rax, %rbx
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x9349
jmp 0x91e9
jmp 0x91f3
movq %rax, %rbx
movq 0x288(%rsp), %rdi
cmpq %r15, %rdi
je 0x91be
callq 0x5410
jmp 0x91be
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x91d7
callq 0x5410
jmp 0x91d7
movq %rax, %rbx
leaq 0x50(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9349
callq 0x5410
jmp 0x9349
movq %rax, %rbx
jmp 0x9349
movq %rax, %rbx
jmp 0x935b
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9368
callq 0x5410
jmp 0x9368
movq %rax, %rbx
jmp 0x9368
movq %rax, %rbx
jmp 0x937a
movq %rax, %rbx
jmp 0x92c1
jmp 0x9339
movq %rax, %rbx
jmp 0x927f
movq %rax, %rbx
jmp 0x92db
movq %rax, %rbx
jmp 0x9293
movq %rax, %rbx
jmp 0x92f5
movq %rax, %rbx
jmp 0x92ad
movq %rax, %rbx
jmp 0x930f
movq %rax, %rbx
movq 0x140(%rsp), %rdi
leaq 0x150(%rsp), %rax
cmpq %rax, %rdi
je 0x927f
callq 0x5410
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x9293
callq 0x5410
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x92ad
callq 0x5410
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x92c1
callq 0x5410
movq 0x80(%rsp), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0x92db
callq 0x5410
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x92f5
callq 0x5410
movq 0xa0(%rsp), %rdi
leaq 0xb0(%rsp), %rax
cmpq %rax, %rdi
je 0x930f
callq 0x5410
movq 0x258(%rsp), %rdi
leaq 0x268(%rsp), %rax
cmpq %rax, %rdi
je 0x933c
callq 0x5410
jmp 0x933c
jmp 0x9339
jmp 0x9339
jmp 0x9339
cmpq $0x0, 0x10(%rsp)
jne 0x9394
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0xc146
movq 0x1f0(%rsp), %rdi
testq %rdi, %rdi
je 0x935b
callq 0x5410
leaq 0x208(%rsp), %rdi
callq 0xc1ac
movq 0x220(%rsp), %rdi
testq %rdi, %rdi
je 0x937a
callq 0x5410
movq 0x180(%rsp), %rdi
testq %rdi, %rdi
je 0x938c
callq 0x5410
movq %rbx, %rdi
callq 0x57d0
callq 0x50d0