// File: /workspace/github_c_makefile_star2_O1/xiongxu[P]bam2bedGraph2/samtools-0.1.19/kprobaln.c
// Function: kpa_glocal
int kpa_glocal(const uint8_t *_ref, int l_ref, const uint8_t *_query, int l_query, const uint8_t *iqual,
			   const kpa_par_t *c, int *state, uint8_t *q)
{
	double **f, **b = 0, *s, m[9], sI, sM, bI, bM, pb;
	float *qual, *_qual;
	const uint8_t *ref, *query;
	int bw, bw2, i, k, is_diff = 0, is_backward = 1, Pr;

    if ( l_ref<=0 || l_query<=0 ) return 0; // FIXME: this may not be an ideal fix, just prevents sefgault

	/*** initialization ***/
	is_backward = state && q? 1 : 0;
	ref = _ref - 1; query = _query - 1; // change to 1-based coordinate
	bw = l_ref > l_query? l_ref : l_query;
	if (bw > c->bw) bw = c->bw;
	if (bw < abs(l_ref - l_query)) bw = abs(l_ref - l_query);
	bw2 = bw * 2 + 1;
	// allocate the forward and backward matrices f[][] and b[][] and the scaling array s[]
	f = calloc(l_query+1, sizeof(void*));
	if (is_backward) b = calloc(l_query+1, sizeof(void*));
	for (i = 0; i <= l_query; ++i) {    // FIXME: this will lead in segfault for l_query==0
		f[i] = calloc(bw2 * 3 + 6, sizeof(double)); // FIXME: this is over-allocated for very short seqs
		if (is_backward) b[i] = calloc(bw2 * 3 + 6, sizeof(double));
	}
	s = calloc(l_query+2, sizeof(double)); // s[] is the scaling factor to avoid underflow
	// initialize qual
	_qual = calloc(l_query, sizeof(float));
	if (g_qual2prob[0] == 0)
		for (i = 0; i < 256; ++i)
			g_qual2prob[i] = pow(10, -i/10.);
	for (i = 0; i < l_query; ++i) _qual[i] = g_qual2prob[iqual? iqual[i] : 30];
	qual = _qual - 1;
	// initialize transition probability
	sM = sI = 1. / (2 * l_query + 2); // the value here seems not to affect results; FIXME: need proof
	m[0*3+0] = (1 - c->d - c->d) * (1 - sM); m[0*3+1] = m[0*3+2] = c->d * (1 - sM);
	m[1*3+0] = (1 - c->e) * (1 - sI); m[1*3+1] = c->e * (1 - sI); m[1*3+2] = 0.;
	m[2*3+0] = 1 - c->e; m[2*3+1] = 0.; m[2*3+2] = c->e;
	bM = (1 - c->d) / l_ref; bI = c->d / l_ref; // (bM+bI)*l_ref==1
	/*** forward ***/
	// f[0]
	set_u(k, bw, 0, 0);
	f[0][k] = s[0] = 1.;
	{ // f[1]
		double *fi = f[1], sum;
		int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1, _beg, _end;
		for (k = beg, sum = 0.; k <= end; ++k) {
			int u;
			double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM;
			set_u(u, bw, 1, k);
			fi[u+0] = e * bM; fi[u+1] = EI * bI;
			sum += fi[u] + fi[u+1];
		}
		// rescale
		s[1] = sum;
		set_u(_beg, bw, 1, beg); set_u(_end, bw, 1, end); _end += 2;
		for (k = _beg; k <= _end; ++k) fi[k] /= sum;
	}
	// f[2..l_query]
	for (i = 2; i <= l_query; ++i) {
		double *fi = f[i], *fi1 = f[i-1], sum, qli = qual[i];
		int beg = 1, end = l_ref, x, _beg, _end;
		uint8_t qyi = query[i];
		x = i - bw; beg = beg > x? beg : x; // band start
		x = i + bw; end = end < x? end : x; // band end
		for (k = beg, sum = 0.; k <= end; ++k) {
			int u, v11, v01, v10;
			double e;
			e = (ref[k] > 3 || qyi > 3)? 1. : ref[k] == qyi? 1. - qli : qli * EM;
			set_u(u, bw, i, k); set_u(v11, bw, i-1, k-1); set_u(v10, bw, i-1, k); set_u(v01, bw, i, k-1);
			fi[u+0] = e * (m[0] * fi1[v11+0] + m[3] * fi1[v11+1] + m[6] * fi1[v11+2]);
			fi[u+1] = EI * (m[1] * fi1[v10+0] + m[4] * fi1[v10+1]);
			fi[u+2] = m[2] * fi[v01+0] + m[8] * fi[v01+2];
			sum += fi[u] + fi[u+1] + fi[u+2];
//			fprintf(stderr, "F (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, fi[u], fi[u+1], fi[u+2]); // DEBUG
		}
		// rescale
		s[i] = sum;
		set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2;
		for (k = _beg, sum = 1./sum; k <= _end; ++k) fi[k] *= sum;
	}
	{ // f[l_query+1]
		double sum;
		for (k = 1, sum = 0.; k <= l_ref; ++k) {
			int u;
			set_u(u, bw, l_query, k);
			if (u < 3 || u >= bw2*3+3) continue;
		    sum += f[l_query][u+0] * sM + f[l_query][u+1] * sI;
		}
		s[l_query+1] = sum; // the last scaling factor
	}
	{ // compute likelihood
		double p = 1., Pr1 = 0.;
		for (i = 0; i <= l_query + 1; ++i) {
			p *= s[i];
			if (p < 1e-100) Pr1 += -4.343 * log(p), p = 1.;
		}
		Pr1 += -4.343 * log(p * l_ref * l_query);
		Pr = (int)(Pr1 + .499);
		if (!is_backward) { // skip backward and MAP
			for (i = 0; i <= l_query; ++i) free(f[i]);
			free(f); free(s); free(_qual);
			return Pr;
		}
	}
	/*** backward ***/
	// b[l_query] (b[l_query+1][0]=1 and thus \tilde{b}[][]=1/s[l_query+1]; this is where s[l_query+1] comes from)
	for (k = 1; k <= l_ref; ++k) {
		int u;
		double *bi = b[l_query];
		set_u(u, bw, l_query, k);
		if (u < 3 || u >= bw2*3+3) continue;
		bi[u+0] = sM / s[l_query] / s[l_query+1]; bi[u+1] = sI / s[l_query] / s[l_query+1];
	}
	// b[l_query-1..1]
	for (i = l_query - 1; i >= 1; --i) {
		int beg = 1, end = l_ref, x, _beg, _end;
		double *bi = b[i], *bi1 = b[i+1], y = (i > 1), qli1 = qual[i+1];
		uint8_t qyi1 = query[i+1];
		x = i - bw; beg = beg > x? beg : x;
		x = i + bw; end = end < x? end : x;
		for (k = end; k >= beg; --k) {
			int u, v11, v01, v10;
			double e;
			set_u(u, bw, i, k); set_u(v11, bw, i+1, k+1); set_u(v10, bw, i+1, k); set_u(v01, bw, i, k+1);
			e = (k >= l_ref? 0 : (ref[k+1] > 3 || qyi1 > 3)? 1. : ref[k+1] == qyi1? 1. - qli1 : qli1 * EM) * bi1[v11];
			bi[u+0] = e * m[0] + EI * m[1] * bi1[v10+1] + m[2] * bi[v01+2]; // bi1[v11] has been foled into e.
			bi[u+1] = e * m[3] + EI * m[4] * bi1[v10+1];
			bi[u+2] = (e * m[6] + m[8] * bi[v01+2]) * y;
//			fprintf(stderr, "B (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, bi[u], bi[u+1], bi[u+2]); // DEBUG
		}
		// rescale
		set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2;
		for (k = _beg, y = 1./s[i]; k <= _end; ++k) bi[k] *= y;
	}
	{ // b[0]
		int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1;
		double sum = 0.;
		for (k = end; k >= beg; --k) {
			int u;
			double e = (ref[k] > 3 || query[1] > 3)? 1. : ref[k] == query[1]? 1. - qual[1] : qual[1] * EM;
			set_u(u, bw, 1, k);
			if (u < 3 || u >= bw2*3+3) continue;
		    sum += e * b[1][u+0] * bM + EI * b[1][u+1] * bI;
		}
		set_u(k, bw, 0, 0);
		pb = b[0][k] = sum / s[0]; // if everything works as is expected, pb == 1.0
	}
	is_diff = fabs(pb - 1.) > 1e-7? 1 : 0;
	/*** MAP ***/
	for (i = 1; i <= l_query; ++i) {
		double sum = 0., *fi = f[i], *bi = b[i], max = 0.;
		int beg = 1, end = l_ref, x, max_k = -1;
		x = i - bw; beg = beg > x? beg : x;
		x = i + bw; end = end < x? end : x;
		for (k = beg; k <= end; ++k) {
			int u;
			double z;
			set_u(u, bw, i, k);
			z = fi[u+0] * bi[u+0]; if (z > max) max = z, max_k = (k-1)<<2 | 0; sum += z;
			z = fi[u+1] * bi[u+1]; if (z > max) max = z, max_k = (k-1)<<2 | 1; sum += z;
		}
		max /= sum; sum *= s[i]; // if everything works as is expected, sum == 1.0
		if (state) state[i-1] = max_k;
		if (q) k = (int)(-4.343 * log(1. - max) + .499), q[i-1] = k > 100? 99 : k;
#ifdef _MAIN
		fprintf(stderr, "(%.10lg,%.10lg) (%d,%d:%c,%c:%d) %lg\n", pb, sum, i-1, max_k>>2,
				"ACGT"[query[i]], "ACGT"[ref[(max_k>>2)+1]], max_k&3, max); // DEBUG
#endif
	}
	/*** free ***/
	for (i = 0; i <= l_query; ++i) {
		free(f[i]); free(b[i]);
	}
	free(f); free(b); free(s); free(_qual);
	return Pr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %ecx, %r15d
movq %rdx, 0x98(%rsp)
movq %rdi, 0xa0(%rsp)
testl %esi, %esi
setle %dl
testl %ecx, %ecx
setle %cl
xorl %eax, %eax
orb %dl, %cl
jne 0x389af
movq %r8, %r13
movl %esi, %ebx
cmpq $0x0, 0x140(%rsp)
setne %al
cmpq $0x0, 0x148(%rsp)
setne %r12b
andb %al, %r12b
movl %esi, %ecx
subl %r15d, %ecx
movl %r15d, %edx
cmovgl %esi, %edx
movq %r9, 0x18(%rsp)
movl 0x8(%r9), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
movl %ecx, %eax
negl %eax
movl %ecx, 0x28(%rsp)
cmovsl %ecx, %eax
cmpl %eax, %edx
movl %edx, 0x24(%rsp)
cmovgl %edx, %eax
movq %rax, 0x8(%rsp)
leal 0x1(%rax,%rax), %eax
movq %rax, 0x80(%rsp)
leal 0x1(%r15), %ebp
movl $0x8, %esi
movq %rbp, %rdi
callq 0x3610
movq %rax, %r14
movb %r12b, 0x50(%rsp)
cmpb $0x1, %r12b
jne 0x37afe
movl $0x8, %esi
movq %rbp, %rdi
callq 0x3610
movq %rax, 0x38(%rsp)
jmp 0x37b07
movq $0x0, 0x38(%rsp)
movl %ebx, 0x4c(%rsp)
movq 0x80(%rsp), %rax
leal (%rax,%rax,2), %r12d
addl $0x6, %r12d
xorl %ebx, %ebx
movl $0x8, %esi
movq %r12, %rdi
callq 0x3610
movq %rax, (%r14,%rbx,8)
cmpb $0x0, 0x50(%rsp)
je 0x37b4b
movl $0x8, %esi
movq %r12, %rdi
callq 0x3610
movq 0x38(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %rbp
jne 0x37b1d
movq %r14, 0x40(%rsp)
leal 0x2(%r15), %edi
movl $0x8, %esi
movq %rdi, 0x90(%rsp)
callq 0x3610
movq %rax, 0x10(%rsp)
movq %r15, (%rsp)
movl %r15d, %edi
movl $0x4, %esi
movq %rdi, 0x68(%rsp)
callq 0x3610
movq %rax, %r12
movss 0x187ec(%rip), %xmm0    # 0x50380
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
leaq 0x187df(%rip), %rbx     # 0x50380
jne 0x37bdd
jp 0x37bdd
xorl %r14d, %r14d
movq %rbx, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x9175(%rip), %xmm0     # 0x40d30
divsd %xmm0, %xmm1
callq 0x3790
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
decq %r14
addq $0x4, %r15
cmpq $-0x100, %r14
jne 0x37bab
cmpl $0x0, (%rsp)
movl 0x4c(%rsp), %r15d
movq 0x68(%rsp), %rdx
movq 0x18(%rsp), %rdi
jle 0x37c19
xorl %eax, %eax
testq %r13, %r13
je 0x37c01
movzbl (%r13,%rax), %ecx
jmp 0x37c06
movl $0x1e, %ecx
movss (%rbx,%rcx,4), %xmm0
movss %xmm0, (%r12,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x37bf4
movq (%rsp), %rsi
leal 0x2(,%rsi,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x8d84(%rip), %xmm10    # 0x409b8
movapd %xmm10, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movss (%rdi), %xmm1
movss 0x4(%rdi), %xmm0
movss 0xcdf4(%rip), %xmm2     # 0x44a48
movaps %xmm2, %xmm4
subss %xmm1, %xmm4
movaps %xmm4, %xmm3
subss %xmm1, %xmm3
cvtsi2ss %r15d, %xmm5
subss %xmm0, %xmm2
divss %xmm5, %xmm4
cvtss2sd %xmm4, %xmm4
movsd %xmm4, 0xb8(%rsp)
movaps %xmm1, %xmm4
divss %xmm5, %xmm4
cvtss2sd %xmm4, %xmm4
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x40(%rsp), %rdx
movq (%rdx), %rcx
movq %rax, 0x18(%rcx)
movq 0x8(%rdx), %rax
movq 0x8(%rsp), %rcx
incl %ecx
cmpl %r15d, %ecx
cmovgel %r15d, %ecx
testl %r15d, %r15d
movsd %xmm4, 0xf0(%rsp)
jle 0x37d9b
movsd 0xcd57(%rip), %xmm5     # 0x44a28
subl %r15d, %esi
movl 0x24(%rsp), %edx
cmpl %esi, %edx
cmovgl %edx, %esi
mulsd %xmm4, %xmm5
movl 0x28(%rsp), %edx
cmpl %edx, %esi
cmovlel %edx, %esi
movl %ecx, %edx
movl $0x1, %edi
subl %esi, %edi
xorl %esi, %esi
testl %edi, %edi
cmovlel %esi, %edi
leal (%rdi,%rdi,2), %r8d
movl $0x7, %edi
subl %r8d, %edi
xorpd %xmm4, %xmm4
movsd 0xcd1e(%rip), %xmm6     # 0x44a30
movq 0xa0(%rsp), %r8
movb (%r8,%rsi), %r8b
movapd %xmm10, %xmm7
cmpb $0x3, %r8b
ja 0x37d64
movq 0x98(%rsp), %r9
movb (%r9), %r9b
movapd %xmm10, %xmm7
cmpb $0x3, %r9b
ja 0x37d64
xorps %xmm8, %xmm8
cvtss2sd (%r12), %xmm8
cmpb %r9b, %r8b
jne 0x37d5a
movapd %xmm10, %xmm7
subsd %xmm8, %xmm7
jmp 0x37d64
mulsd %xmm6, %xmm8
movapd %xmm8, %xmm7
leal -0x1(%rdi), %r8d
mulsd 0xb8(%rsp), %xmm7
movslq %r8d, %r8
movsd %xmm7, (%rax,%r8,8)
movslq %edi, %rdi
movsd %xmm5, (%rax,%rdi,8)
addsd %xmm5, %xmm7
addsd %xmm7, %xmm4
incq %rsi
addl $0x3, %edi
cmpq %rdx, %rsi
jb 0x37d12
jmp 0x37d9f
xorpd %xmm4, %xmm4
cvtss2sd %xmm3, %xmm11
subsd 0x60(%rsp), %xmm10
cvtss2sd %xmm1, %xmm12
cvtss2sd %xmm2, %xmm13
cvtss2sd %xmm0, %xmm14
movq 0x10(%rsp), %rdx
movsd %xmm4, 0x8(%rdx)
movl $0x1, %edx
movq 0x8(%rsp), %rsi
subl %esi, %edx
xorl %r8d, %r8d
testl %edx, %edx
movl %edx, 0x7c(%rsp)
cmovgl %edx, %r8d
movl $0x1, %edx
testl %esi, %esi
cmovlel %esi, %edx
leal (%rdx,%rdx,2), %esi
addl $0x3, %esi
movq %r8, 0xc0(%rsp)
subl %r8d, %ecx
leal (%rcx,%rcx,2), %ecx
addl $0x5, %ecx
cmpl %ecx, %esi
jg 0x37e24
leal (%rdx,%rdx,2), %edx
movl %esi, %esi
addl $0x2, %edx
leaq (%rax,%rsi,8), %rax
movsd (%rax), %xmm0
divsd %xmm4, %xmm0
movsd %xmm0, (%rax)
incl %edx
addq $0x8, %rax
cmpl %edx, %ecx
jg 0x37e0e
movq %r12, 0x58(%rsp)
mulsd %xmm10, %xmm11
mulsd %xmm10, %xmm12
movapd %xmm10, %xmm15
mulsd %xmm13, %xmm15
mulsd %xmm14, %xmm10
cmpl $0x2, (%rsp)
movq %rbp, 0xb0(%rsp)
jl 0x3811c
movq (%rsp), %rax
movl %eax, %ecx
subl %r15d, %ecx
movl 0x24(%rsp), %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl 0x28(%rsp), %eax
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl $0x2, %eax
subl %ecx, %eax
movl 0x8(%rsp), %ecx
movq %rcx, 0xa8(%rsp)
movl $0x2, %edx
movsd 0x8b29(%rip), %xmm0     # 0x409b8
movsd 0xcb99(%rip), %xmm1     # 0x44a30
movsd 0xcb89(%rip), %xmm2     # 0x44a28
movl 0x7c(%rsp), %esi
cmpl $0x2, %eax
movl $0x1, %r11d
cmovgel %eax, %r11d
leal (%r11,%r11,2), %r9d
testl %eax, %eax
movl $0x0, %ecx
movl %eax, 0x30(%rsp)
cmovgl %eax, %ecx
leal (%rcx,%rcx,2), %eax
movl %eax, 0x2c(%rsp)
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0x70(%rsp)
cmovgl %esi, %ecx
movq 0x40(%rsp), %rax
movq (%rax,%rdx,8), %r8
movq %rdx, %rbx
subq 0xa8(%rsp), %rbx
cmpl $0x2, %ebx
movl $0x1, %esi
cmovgel %ebx, %esi
movq 0x8(%rsp), %rax
addl %edx, %eax
cmpl %r15d, %eax
cmovgel %r15d, %eax
xorps %xmm3, %xmm3
movq %rsi, 0x88(%rsp)
movq %rax, 0x18(%rsp)
cmpl %eax, %esi
jg 0x3808e
leal (%rcx,%rcx,2), %r15d
negl %r15d
movl 0x2c(%rsp), %eax
movl %eax, %r12d
negl %r12d
decq %r11
movq 0x40(%rsp), %rax
movq -0x8(%rax,%rdx,8), %r13
movq 0x98(%rsp), %rax
movb -0x1(%rax,%rdx), %bpl
movq 0x58(%rsp), %rax
xorps %xmm4, %xmm4
cvtss2sd -0x4(%rax,%rdx,4), %xmm4
movapd %xmm0, %xmm5
subsd %xmm4, %xmm5
mulsd %xmm1, %xmm4
movslq 0x18(%rsp), %rcx
movq 0xa0(%rsp), %rax
movb (%rax,%r11), %r10b
movapd %xmm5, %xmm6
cmpb %bpl, %r10b
je 0x37f7f
movapd %xmm4, %xmm6
movapd %xmm0, %xmm8
cmpb $0x4, %bpl
jae 0x37f8f
movapd %xmm6, %xmm8
movapd %xmm0, %xmm7
cmpb $0x4, %r10b
jae 0x37f9e
movapd %xmm8, %xmm7
leal (%r9,%r12), %r10d
leal (%r9,%r12), %edi
addl $0x3, %edi
leal (%r9,%r15), %eax
leal 0x3(%r9,%r15), %r14d
cltq
leal 0x1(%r9,%r15), %esi
movslq %esi, %rsi
movsd (%r13,%rsi,8), %xmm6
mulsd %xmm15, %xmm6
movsd (%r13,%rax,8), %xmm8
mulsd %xmm11, %xmm8
addsd %xmm6, %xmm8
leal 0x2(%r9,%r15), %eax
cltq
movsd (%r13,%rax,8), %xmm6
mulsd %xmm13, %xmm6
addsd %xmm8, %xmm6
mulsd %xmm7, %xmm6
movslq %edi, %rax
movsd %xmm6, (%r8,%rax,8)
movslq %r14d, %rax
leal 0x4(%r9,%r15), %esi
movslq %esi, %rsi
movsd (%r13,%rsi,8), %xmm7
mulsd %xmm10, %xmm7
movsd (%r13,%rax,8), %xmm8
mulsd %xmm12, %xmm8
addsd %xmm7, %xmm8
mulsd %xmm2, %xmm8
leal 0x4(%r9,%r12), %eax
cltq
movsd %xmm8, (%r8,%rax,8)
movslq %r10d, %rax
leal 0x2(%r9,%r12), %esi
movslq %esi, %rsi
movsd (%r8,%rsi,8), %xmm7
mulsd %xmm14, %xmm7
movsd (%r8,%rax,8), %xmm9
mulsd %xmm12, %xmm9
addsd %xmm7, %xmm9
leal 0x5(%r9,%r12), %eax
cltq
movsd %xmm9, (%r8,%rax,8)
addsd %xmm6, %xmm8
addsd %xmm9, %xmm8
addsd %xmm8, %xmm3
addl $0x3, %r15d
addl $0x3, %r12d
incq %r11
cmpq %rcx, %r11
jl 0x37f66
movq 0x10(%rsp), %rax
movsd %xmm3, (%rax,%rdx,8)
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
movq 0x88(%rsp), %rax
subl %ebx, %eax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
movq 0x18(%rsp), %rcx
subl %ebx, %ecx
leal (%rcx,%rcx,2), %esi
addl $0x5, %esi
cmpl %esi, %eax
jg 0x380f7
subl 0x2c(%rsp), %r9d
addl $0x3, %r9d
movslq %r9d, %rcx
decq %rcx
movapd %xmm0, %xmm4
divsd %xmm3, %xmm4
movslq %esi, %rsi
movsd 0x8(%r8,%rcx,8), %xmm3
mulsd %xmm4, %xmm3
movsd %xmm3, 0x8(%r8,%rcx,8)
incq %rcx
cmpq %rsi, %rcx
jl 0x380dd
incq %rdx
movl 0x30(%rsp), %eax
incl %eax
movl 0x70(%rsp), %esi
incl %esi
movq 0xb0(%rsp), %rbp
cmpq %rbp, %rdx
movl 0x4c(%rsp), %r15d
jne 0x37ea3
xorps %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movl %r15d, %eax
movq %rax, 0x18(%rsp)
testl %r15d, %r15d
movq 0x148(%rsp), %r13
movq 0x38(%rsp), %r12
movq 0x68(%rsp), %r9
jle 0x381b6
movq (%rsp), %rax
subl 0x8(%rsp), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
movq 0x80(%rsp), %rax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
leal (%rcx,%rcx,2), %edx
movl $0x3, %ecx
subl %edx, %ecx
movq 0x18(%rsp), %rdx
movsd 0x60(%rsp), %xmm3
movl %ecx, %esi
leal 0x3(%rsi), %ecx
cmpl $0x7ffffffc, %esi       # imm = 0x7FFFFFFC
ja 0x381b1
cmpl %eax, %ecx
jge 0x381b1
movq 0x40(%rsp), %rdi
movq (%rdi,%r9,8), %rdi
movl %ecx, %r8d
addl $0x4, %esi
movsd (%rdi,%rsi,8), %xmm1
mulsd %xmm3, %xmm1
movsd (%rdi,%r8,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
addsd %xmm2, %xmm0
decq %rdx
jne 0x38176
movq 0x10(%rsp), %rax
movsd %xmm0, (%rax,%rbp,8)
movsd 0x87f0(%rip), %xmm0     # 0x409b8
xorl %ebx, %ebx
movsd 0xc866(%rip), %xmm1     # 0x44a38
movsd %xmm10, 0x70(%rsp)
movsd %xmm11, 0xe8(%rsp)
movsd %xmm12, 0xe0(%rsp)
movsd %xmm13, 0xd8(%rsp)
movsd %xmm14, 0xd0(%rsp)
movsd %xmm15, 0xc8(%rsp)
movq 0x10(%rsp), %rax
mulsd (%rax,%rbx,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x38248
callq 0x3330
mulsd 0x8810(%rip), %xmm0     # 0x40a38
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0xc7f8(%rip), %xmm1     # 0x44a38
movsd 0x8770(%rip), %xmm0     # 0x409b8
incq %rbx
cmpq %rbx, 0x90(%rsp)
jne 0x3820b
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
mulsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x3330
mulsd 0x87ba(%rip), %xmm0     # 0x40a38
addsd 0x30(%rsp), %xmm0
addsd 0x5d94(%rip), %xmm0     # 0x3e020
cvttsd2si %xmm0, %eax
movl %eax, 0x78(%rsp)
cmpb $0x0, 0x50(%rsp)
jne 0x382da
xorl %ebx, %ebx
movq 0x40(%rsp), %r14
movq (%r14,%rbx,8), %rdi
callq 0x3350
incq %rbx
cmpq %rbx, %rbp
jne 0x382a2
movq %r14, %rdi
callq 0x3350
movq 0x10(%rsp), %rdi
callq 0x3350
movq 0x58(%rsp), %rdi
callq 0x3350
cmpb $0x0, 0x50(%rsp)
je 0x389ab
testl %r15d, %r15d
movq 0x68(%rsp), %r10
movsd 0x70(%rsp), %xmm9
movsd 0xe8(%rsp), %xmm10
movsd 0xe0(%rsp), %xmm11
movsd 0xd8(%rsp), %xmm12
movsd 0xd0(%rsp), %xmm13
movsd 0xc8(%rsp), %xmm14
jle 0x3838b
movq (%r12,%r10,8), %rax
movq (%rsp), %rcx
subl 0x8(%rsp), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovgl %ecx, %edx
movq 0x80(%rsp), %rcx
leal (%rcx,%rcx,2), %ecx
addl $0x3, %ecx
leal (%rdx,%rdx,2), %edx
movl $0x3, %esi
subl %edx, %esi
movq 0x18(%rsp), %rdx
movl %esi, %edi
leal 0x3(%rdi), %esi
cmpl $0x7ffffffc, %edi       # imm = 0x7FFFFFFC
ja 0x38386
cmpl %ecx, %esi
jge 0x38386
movsd 0x60(%rsp), %xmm0
movq 0x10(%rsp), %r8
divsd (%r8,%r10,8), %xmm0
divsd (%r8,%rbp,8), %xmm0
movl %esi, %r8d
movsd %xmm0, (%rax,%r8,8)
addl $0x4, %edi
movsd %xmm0, (%rax,%rdi,8)
decq %rdx
jne 0x3834d
cmpl $0x2, (%rsp)
jl 0x386e0
movsd 0xc68b(%rip), %xmm1     # 0x44a28
movapd %xmm11, %xmm0
movq (%rsp), %rcx
movl %ecx, %esi
subl %r15d, %esi
movl 0x24(%rsp), %eax
cmpl %esi, %eax
cmovgl %eax, %esi
mulsd %xmm1, %xmm0
movl 0x28(%rsp), %eax
cmpl %eax, %esi
cmovlel %eax, %esi
mulsd %xmm1, %xmm9
leal (%rsi,%rcx), %eax
decl %eax
movslq %eax, %rdi
movl %ecx, %r8d
subl %esi, %r8d
notl %esi
addl %ecx, %esi
movl 0x8(%rsp), %eax
movsd 0x85d4(%rip), %xmm1     # 0x409b8
negq %rax
movq %rax, 0xf8(%rsp)
movsd 0xc639(%rip), %xmm2     # 0x44a30
cmpl $0x2, %esi
movl $0x1, %eax
cmovgel %esi, %eax
movq %rax, 0x100(%rsp)
testl %esi, %esi
movl $0x0, %edx
movq %rsi, 0x70(%rsp)
cmovgl %esi, %edx
movq 0x18(%rsp), %rax
cmpq %rax, %rdi
movq %rdi, 0x50(%rsp)
cmovlq %rdi, %rax
testl %r8d, %r8d
movl $0x0, %ecx
movl %r8d, 0x2c(%rsp)
cmovgl %r8d, %ecx
movapd %xmm1, %xmm3
cmpq $0x2, %r10
jne 0x38449
xorpd %xmm3, %xmm3
leal (%rdx,%rdx,2), %edx
movl %edx, 0x88(%rsp)
leaq -0x1(%r10), %rsi
movq -0x8(%r12,%r10,8), %r9
movq 0xf8(%rsp), %rdx
movq %r10, 0x30(%rsp)
addq %r10, %rdx
decq %rdx
cmpl $0x2, %edx
movl $0x1, %edi
movq %rdx, 0x60(%rsp)
cmovgel %edx, %edi
movq 0x8(%rsp), %rdx
movq %rsi, 0x68(%rsp)
addl %esi, %edx
cmpl %r15d, %edx
cmovgel %r15d, %edx
movq %rdi, 0x90(%rsp)
movq %rdx, 0xa8(%rsp)
cmpl %edi, %edx
jl 0x3862d
leal (%rax,%rax,2), %r12d
leal (%rcx,%rcx,2), %eax
movl $0x4, %r15d
subl %eax, %r15d
movl $0x5, %r13d
movl 0x88(%rsp), %ecx
subl %ecx, %r13d
movl $0x4, %r10d
subl %ecx, %r10d
movl $0x3, %r11d
subl %ecx, %r11d
movl $0x8, %ebp
subl %ecx, %ebp
movl $0x6, %edx
subl %eax, %edx
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %rsi
movq (%rax,%rsi,8), %r8
movq 0x98(%rsp), %rax
movb -0x1(%rax,%rsi), %cl
movq 0x18(%rsp), %rbx
movq 0x50(%rsp), %rax
cmpq %rbx, %rax
cmovlq %rax, %rbx
movq 0x58(%rsp), %rax
cvtss2sd -0x4(%rax,%rsi,4), %xmm4
movapd %xmm1, %xmm5
subsd %xmm4, %xmm5
mulsd %xmm2, %xmm4
movl 0x90(%rsp), %eax
xorpd %xmm6, %xmm6
cmpq 0x18(%rsp), %rbx
jge 0x3856a
movq 0xa0(%rsp), %rsi
movb (%rsi,%rbx), %sil
movapd %xmm1, %xmm6
cmpb $0x3, %sil
ja 0x3856a
movapd %xmm1, %xmm6
cmpb $0x3, %cl
ja 0x3856a
movapd %xmm5, %xmm6
cmpb %cl, %sil
je 0x3856a
movapd %xmm4, %xmm6
leal (%r12,%rdx), %esi
movslq %esi, %rsi
mulsd (%r8,%rsi,8), %xmm6
leal (%r12,%r11), %esi
leal (%r12,%r15), %edi
movslq %edi, %rdi
movsd (%r8,%rdi,8), %xmm7
mulsd %xmm0, %xmm7
movapd %xmm6, %xmm8
mulsd %xmm10, %xmm8
addsd %xmm7, %xmm8
leal (%r12,%rbp), %r14d
movslq %r14d, %r14
movsd (%r9,%r14,8), %xmm7
mulsd %xmm11, %xmm7
addsd %xmm8, %xmm7
movslq %esi, %rsi
movsd %xmm7, (%r9,%rsi,8)
movsd (%r8,%rdi,8), %xmm7
mulsd %xmm9, %xmm7
movapd %xmm6, %xmm8
mulsd %xmm14, %xmm8
addsd %xmm7, %xmm8
leal (%r12,%r10), %esi
movslq %esi, %rsi
movsd %xmm8, (%r9,%rsi,8)
movsd (%r9,%r14,8), %xmm7
mulsd %xmm13, %xmm7
mulsd %xmm12, %xmm6
addsd %xmm7, %xmm6
mulsd %xmm3, %xmm6
leal (%r12,%r13), %esi
movslq %esi, %rsi
movsd %xmm6, (%r9,%rsi,8)
leaq -0x1(%rbx), %rsi
addl $-0x3, %r15d
addl $-0x3, %r13d
addl $-0x3, %r10d
addl $-0x3, %r11d
addl $-0x3, %ebp
addl $-0x3, %edx
cmpq %rax, %rbx
movq %rsi, %rbx
jg 0x38533
movq 0x60(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq 0x90(%rsp), %rax
subl %ecx, %eax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
movq 0xa8(%rsp), %rdx
subl %ecx, %edx
leal (%rdx,%rdx,2), %ecx
addl $0x5, %ecx
cmpl %ecx, %eax
movq 0x68(%rsp), %r10
movq 0x70(%rsp), %rsi
jg 0x386b0
movq 0x100(%rsp), %rax
leal (%rax,%rax,2), %eax
subl 0x88(%rsp), %eax
addl $0x3, %eax
cltq
decq %rax
movapd %xmm1, %xmm3
movq 0x10(%rsp), %rdx
divsd (%rdx,%r10,8), %xmm3
movslq %ecx, %rcx
movsd 0x8(%r9,%rax,8), %xmm4
mulsd %xmm3, %xmm4
movsd %xmm4, 0x8(%r9,%rax,8)
incq %rax
cmpq %rcx, %rax
jl 0x38696
movq 0x50(%rsp), %rdi
decq %rdi
decl %esi
movl 0x2c(%rsp), %r8d
decl %r8d
cmpq $0x2, 0x30(%rsp)
movl 0x4c(%rsp), %r15d
movq 0x148(%rsp), %r13
movq 0x38(%rsp), %r12
jg 0x383f7
testl %r15d, %r15d
jle 0x387e9
movq (%rsp), %rsi
subl %r15d, %esi
movl 0x24(%rsp), %eax
cmpl %esi, %eax
cmovgl %eax, %esi
movl 0x28(%rsp), %eax
cmpl %eax, %esi
cmovlel %eax, %esi
incl %esi
cmpl %esi, %r15d
cmovll %r15d, %esi
movq 0x80(%rsp), %rax
leal 0x3(%rax,%rax,2), %eax
movq 0xa0(%rsp), %rcx
addq %rsi, %rcx
decq %rcx
leal (%rsi,%rsi,2), %edx
incl %esi
movq 0xc0(%rsp), %rdi
leal (%rdi,%rdi,2), %edi
subl %edi, %edx
addl $0x4, %edx
xorpd %xmm0, %xmm0
movsd 0x8272(%rip), %xmm1     # 0x409b8
movsd 0xc2da(%rip), %xmm2     # 0x44a28
movsd 0xc2da(%rip), %xmm3     # 0x44a30
movq 0x58(%rsp), %r9
movb (%rcx), %dil
movapd %xmm1, %xmm4
cmpb $0x3, %dil
ja 0x3879c
movq 0x98(%rsp), %r8
movb (%r8), %r8b
movapd %xmm1, %xmm4
cmpb $0x3, %r8b
ja 0x3879c
xorps %xmm5, %xmm5
cvtss2sd (%r9), %xmm5
cmpb %r8b, %dil
jne 0x38794
movapd %xmm1, %xmm4
subsd %xmm5, %xmm4
jmp 0x3879c
mulsd %xmm3, %xmm5
movapd %xmm5, %xmm4
leal -0x1(%rdx), %edi
cmpl %eax, %edi
jge 0x387d6
movq 0x8(%r12), %r8
movl %edi, %edi
mulsd (%r8,%rdi,8), %xmm4
movl %edx, %edi
movsd (%r8,%rdi,8), %xmm5
mulsd %xmm2, %xmm5
mulsd 0xf0(%rsp), %xmm5
mulsd 0xb8(%rsp), %xmm4
addsd %xmm5, %xmm4
addsd %xmm4, %xmm0
decl %esi
decq %rcx
addl $-0x3, %edx
cmpl $0x1, %esi
jg 0x3875b
jmp 0x387ed
xorpd %xmm0, %xmm0
movq 0x10(%rsp), %rax
divsd (%rax), %xmm0
movq (%r12), %rax
movsd %xmm0, 0x18(%rax)
cmpl $0x0, (%rsp)
movl 0x7c(%rsp), %eax
jle 0x38959
movl 0x8(%rsp), %ebx
movl $0x1, %r14d
movl $0x1, %ebp
cmpl $0x2, %eax
movl $0x1, %esi
cmovgel %eax, %esi
testl %eax, %eax
movl $0x0, %ecx
movl %eax, %r12d
cmovgl %eax, %ecx
movl %r14d, %eax
subl %ebx, %eax
cmpl $0x2, %eax
cmovll %ebp, %eax
movq 0x8(%rsp), %rdx
leal (%rdx,%r14), %r9d
cmpl %r15d, %r9d
cmovgel %r15d, %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movsd 0xc1e4(%rip), %xmm1     # 0x44a40
cmpl %r9d, %eax
jg 0x388f7
leal (%rsi,%rsi,2), %eax
leal (%rcx,%rcx,2), %ecx
subl %ecx, %eax
addl $0x4, %eax
movq %rsi, %rcx
decq %rcx
leal -0x4(,%rsi,4), %esi
movq 0x40(%rsp), %rdx
movq (%rdx,%r14,8), %rdi
movq 0x38(%rsp), %rdx
movq (%rdx,%r14,8), %r8
movslq %r9d, %r9
xorpd %xmm1, %xmm1
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
leal -0x1(%rax), %r10d
movslq %r10d, %r10
movsd (%rdi,%r10,8), %xmm2
mulsd (%r8,%r10,8), %xmm2
ucomisd %xmm1, %xmm2
movl %edx, %r10d
cmoval %esi, %r10d
addsd %xmm2, %xmm0
maxsd %xmm1, %xmm2
cltq
movsd (%rdi,%rax,8), %xmm1
mulsd (%r8,%rax,8), %xmm1
ucomisd %xmm2, %xmm1
leal 0x1(%rsi), %edx
cmovbel %r10d, %edx
addsd %xmm1, %xmm0
maxsd %xmm2, %xmm1
addl $0x3, %eax
incq %rcx
addl $0x4, %esi
cmpq %r9, %rcx
jl 0x3889f
divsd %xmm0, %xmm1
movq 0x140(%rsp), %rax
testq %rax, %rax
je 0x38909
movl %edx, -0x4(%rax,%r14,4)
testq %r13, %r13
je 0x38943
movsd 0x80a2(%rip), %xmm0     # 0x409b8
subsd %xmm1, %xmm0
callq 0x3330
mulsd 0x8111(%rip), %xmm0     # 0x40a38
addsd 0x56f1(%rip), %xmm0     # 0x3e020
cvttsd2si %xmm0, %eax
cmpl $0x65, %eax
movl $0x63, %ecx
cmovgel %ecx, %eax
movb %al, -0x1(%r13,%r14)
incq %r14
movl %r12d, %eax
incl %eax
cmpq 0xb0(%rsp), %r14
jne 0x3881c
xorl %ebx, %ebx
movq 0xb0(%rsp), %r14
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %r12
movq (%r15,%rbx,8), %rdi
callq 0x3350
movq (%r12,%rbx,8), %rdi
callq 0x3350
incq %rbx
cmpq %rbx, %r14
jne 0x3896d
movq %r15, %rdi
callq 0x3350
movq %r12, %rdi
callq 0x3350
movq 0x10(%rsp), %rdi
callq 0x3350
movq 0x58(%rsp), %rdi
callq 0x3350
movl 0x78(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)