// File: /workspace/github_cpp_makefile_star2_O1/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/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;

	/*** 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) {
		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) Pr += -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 $0x118, %rsp            # imm = 0x118
movq %r8, %r13
movl %ecx, %ebp
movq %rdx, 0xa8(%rsp)
movq %rdi, 0xb0(%rsp)
cmpq $0x0, 0x150(%rsp)
setne %al
cmpq $0x0, 0x158(%rsp)
setne %r15b
andb %al, %r15b
movl %esi, %ecx
subl %ebp, %ecx
movl %ebp, %edx
movl %esi, 0x1c(%rsp)
cmovgl %esi, %edx
movq %r9, 0x60(%rsp)
movl 0x8(%r9), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
movl %ecx, %eax
negl %eax
movl %ecx, 0x18(%rsp)
cmovsl %ecx, %eax
cmpl %eax, %edx
movl %edx, 0x14(%rsp)
cmovgl %edx, %eax
movq %rax, (%rsp)
leal 0x1(%rbp), %r14d
movslq %r14d, %rbx
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3530
movq %rax, 0x30(%rsp)
cmpb $0x1, %r15b
movq %rbx, 0x40(%rsp)
jne 0x210f9
movl $0x8, %esi
movq %rbx, %rdi
callq 0x3530
movq %rax, 0x20(%rsp)
jmp 0x21102
movq $0x0, 0x20(%rsp)
movq (%rsp), %rax
leal 0x1(,%rax,2), %eax
movq %rax, 0x70(%rsp)
testl %ebp, %ebp
js 0x2115e
movq 0x70(%rsp), %rax
leal (%rax,%rax,2), %r12d
addl $0x6, %r12d
xorl %ebx, %ebx
movl $0x8, %esi
movq %r12, %rdi
callq 0x3530
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
testb %r15b, %r15b
je 0x21156
movl $0x8, %esi
movq %r12, %rdi
callq 0x3530
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
cmpq %rbx, %r14
jne 0x21125
movb %r15b, 0x88(%rsp)
movq %r14, 0x58(%rsp)
leal 0x2(%rbp), %eax
movq %rax, 0xb8(%rsp)
movslq %eax, %rdi
movl $0x8, %esi
callq 0x3530
movq %rax, 0x8(%rsp)
movslq %ebp, %rdi
movl $0x4, %esi
movq %rdi, 0x78(%rsp)
callq 0x3530
movq %rax, 0x28(%rsp)
movss 0xf189(%rip), %xmm0     # 0x30330
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
leaq 0xf17c(%rip), %rbx      # 0x30330
jne 0x211f0
jp 0x211f0
xorl %r14d, %r14d
movq %rbx, %r15
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x32aa(%rip), %xmm0     # 0x24478
divsd %xmm0, %xmm1
callq 0x3650
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r15)
decq %r14
addq $0x4, %r15
cmpq $-0x100, %r14
jne 0x211be
movl %ebp, %edx
testl %ebp, %ebp
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r10
jle 0x21227
xorl %eax, %eax
testq %r13, %r13
je 0x2120f
movzbl (%r13,%rax), %ecx
jmp 0x21214
movl $0x1e, %ecx
movss (%rbx,%rcx,4), %xmm0
movss %xmm0, (%r10,%rax,4)
incq %rax
cmpq %rax, %rdx
jne 0x21202
movq %rdx, 0xc0(%rsp)
leal 0x2(,%rbp,2), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x322a(%rip), %xmm12    # 0x24470
movapd %xmm12, %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movq 0x60(%rsp), %rax
movss (%rax), %xmm1
movss 0x4(%rax), %xmm0
movss 0x325d(%rip), %xmm2     # 0x244c8
movaps %xmm2, %xmm4
subss %xmm1, %xmm4
movaps %xmm4, %xmm3
subss %xmm1, %xmm3
movl 0x1c(%rsp), %edx
cvtsi2ss %edx, %xmm5
subss %xmm0, %xmm2
divss %xmm5, %xmm4
cvtss2sd %xmm4, %xmm10
movaps %xmm1, %xmm4
divss %xmm5, %xmm4
cvtss2sd %xmm4, %xmm11
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
movq (%r12), %rcx
movq %rax, 0x18(%rcx)
movq 0x8(%r12), %rax
movq (%rsp), %rcx
incl %ecx
cmpl %edx, %ecx
cmovgel %edx, %ecx
testl %edx, %edx
jle 0x2139b
movsd 0x6c0c(%rip), %xmm5     # 0x27ee0
movl %ebp, %esi
subl %edx, %esi
movl 0x14(%rsp), %edx
cmpl %esi, %edx
cmovgl %edx, %esi
mulsd %xmm11, %xmm5
movl 0x18(%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
xorps %xmm4, %xmm4
movsd 0x6bd2(%rip), %xmm6     # 0x27ee8
movq 0x58(%rsp), %r14
movq 0xb0(%rsp), %r8
movb (%r8,%rsi), %r8b
movapd %xmm12, %xmm7
cmpb $0x3, %r8b
ja 0x2136c
movq 0xa8(%rsp), %r9
movb (%r9), %r9b
movapd %xmm12, %xmm7
cmpb $0x3, %r9b
ja 0x2136c
xorps %xmm8, %xmm8
cvtss2sd (%r10), %xmm8
cmpb %r9b, %r8b
jne 0x21362
movapd %xmm12, %xmm7
subsd %xmm8, %xmm7
jmp 0x2136c
mulsd %xmm6, %xmm8
movapd %xmm8, %xmm7
leal -0x1(%rdi), %r8d
mulsd %xmm10, %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 0x2131b
jmp 0x213a3
xorps %xmm4, %xmm4
movq 0x58(%rsp), %r14
cvtss2sd %xmm3, %xmm13
subsd 0x48(%rsp), %xmm12
cvtss2sd %xmm1, %xmm14
cvtss2sd %xmm2, %xmm15
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
movq 0x8(%rsp), %rdx
movsd %xmm4, 0x8(%rdx)
movl $0x1, %edi
movq (%rsp), %rsi
subl %esi, %edi
xorl %r8d, %r8d
testl %edi, %edi
movl %edi, 0x6c(%rsp)
cmovgl %edi, %r8d
movl $0x1, %edx
testl %esi, %esi
cmovlel %esi, %edx
leal (%rdx,%rdx,2), %esi
addl $0x3, %esi
movq %r8, 0xd8(%rsp)
subl %r8d, %ecx
leal (%rcx,%rcx,2), %ecx
addl $0x5, %ecx
cmpl %ecx, %esi
jg 0x2142c
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 0x21416
mulsd %xmm12, %xmm13
mulsd %xmm12, %xmm14
movapd %xmm12, %xmm0
mulsd %xmm15, %xmm0
movsd %xmm0, 0xd0(%rsp)
mulsd 0x60(%rsp), %xmm12
movq %rbp, 0x80(%rsp)
cmpl $0x2, %ebp
movl 0x1c(%rsp), %ebp
jl 0x2173c
movq 0x80(%rsp), %rax
movl %eax, %ecx
subl %ebp, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
movl 0x18(%rsp), %eax
cmpl %eax, %ecx
cmovlel %eax, %ecx
movl $0x2, %eax
subl %ecx, %eax
movl (%rsp), %ecx
movq %rcx, 0x90(%rsp)
movl $0x2, %edx
movsd 0x2fce(%rip), %xmm0     # 0x24470
movsd 0x6a3e(%rip), %xmm1     # 0x27ee8
movsd 0x6a2e(%rip), %xmm2     # 0x27ee0
movl 0x6c(%rsp), %esi
cmpl $0x2, %eax
movl $0x1, %r11d
cmovgel %eax, %r11d
leal (%r11,%r11,2), %r9d
testl %eax, %eax
movl $0x0, %ecx
movl %eax, 0xa0(%rsp)
cmovgl %eax, %ecx
leal (%rcx,%rcx,2), %eax
movl %eax, 0x50(%rsp)
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0x98(%rsp)
cmovgl %esi, %ecx
movq (%r12,%rdx,8), %r8
movq %rdx, %r14
subq 0x90(%rsp), %r14
cmpl $0x2, %r14d
movl $0x1, %esi
cmovgel %r14d, %esi
movq (%rsp), %rax
addl %edx, %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
xorps %xmm3, %xmm3
movq %rsi, 0xc8(%rsp)
movq %rax, 0x38(%rsp)
cmpl %eax, %esi
jg 0x216a3
leal (%rcx,%rcx,2), %ebx
negl %ebx
movl 0x50(%rsp), %eax
movl %eax, %r12d
negl %r12d
decq %r11
movq 0x30(%rsp), %rax
movq -0x8(%rax,%rdx,8), %r13
movq 0xa8(%rsp), %rax
movb -0x1(%rax,%rdx), %bpl
movq 0x28(%rsp), %rax
xorps %xmm4, %xmm4
cvtss2sd -0x4(%rax,%rdx,4), %xmm4
movapd %xmm0, %xmm5
subsd %xmm4, %xmm5
mulsd %xmm1, %xmm4
movslq 0x38(%rsp), %rcx
movq 0xb0(%rsp), %rax
movb (%rax,%r11), %r10b
movapd %xmm5, %xmm6
cmpb %bpl, %r10b
je 0x21590
movapd %xmm4, %xmm6
movapd %xmm0, %xmm8
cmpb $0x4, %bpl
jae 0x215a0
movapd %xmm6, %xmm8
movapd %xmm0, %xmm7
cmpb $0x4, %r10b
jae 0x215af
movapd %xmm8, %xmm7
leal (%r9,%r12), %r10d
leal (%r9,%r12), %edi
addl $0x3, %edi
leal (%r9,%rbx), %eax
leal 0x3(%r9,%rbx), %r15d
cltq
leal 0x1(%r9,%rbx), %esi
movslq %esi, %rsi
movsd (%r13,%rsi,8), %xmm6
mulsd 0xd0(%rsp), %xmm6
movsd (%r13,%rax,8), %xmm8
mulsd %xmm13, %xmm8
addsd %xmm6, %xmm8
leal 0x2(%r9,%rbx), %eax
cltq
movsd (%r13,%rax,8), %xmm6
mulsd %xmm15, %xmm6
addsd %xmm8, %xmm6
mulsd %xmm7, %xmm6
movslq %edi, %rax
movsd %xmm6, (%r8,%rax,8)
movslq %r15d, %rax
leal 0x4(%r9,%rbx), %esi
movslq %esi, %rsi
movsd (%r13,%rsi,8), %xmm7
mulsd %xmm12, %xmm7
movsd (%r13,%rax,8), %xmm8
mulsd %xmm14, %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 0x60(%rsp), %xmm7
movsd (%r8,%rax,8), %xmm9
mulsd %xmm14, %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, %ebx
addl $0x3, %r12d
incq %r11
cmpq %rcx, %r11
jl 0x21577
movq 0x8(%rsp), %rax
movsd %xmm3, (%rax,%rdx,8)
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
movq 0xc8(%rsp), %rax
subl %r14d, %eax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
movq 0x38(%rsp), %rcx
subl %r14d, %ecx
leal (%rcx,%rcx,2), %esi
addl $0x5, %esi
cmpl %esi, %eax
jg 0x21710
subl 0x50(%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 0x216f6
incq %rdx
movl 0xa0(%rsp), %eax
incl %eax
movl 0x98(%rsp), %esi
incl %esi
movq 0x58(%rsp), %r14
cmpq %r14, %rdx
movl 0x1c(%rsp), %ebp
movq 0x30(%rsp), %r12
jne 0x214b6
movl %ebp, %r15d
testl %ebp, %ebp
jle 0x217c1
movq 0x80(%rsp), %r13
movl %r13d, %eax
subl (%rsp), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovgl %eax, %ecx
movq 0x70(%rsp), %rax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
leal (%rcx,%rcx,2), %edx
movl $0x3, %ecx
subl %edx, %ecx
xorpd %xmm0, %xmm0
movq %r15, %rdx
movq 0x40(%rsp), %r9
movq 0x78(%rsp), %r10
movsd 0x48(%rsp), %xmm3
movl %ecx, %esi
leal 0x3(%rsi), %ecx
cmpl $0x7ffffffc, %esi       # imm = 0x7FFFFFFC
ja 0x217ba
cmpl %eax, %ecx
jge 0x217ba
movq (%r12,%r10,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 0x21784
jmp 0x217d2
xorpd %xmm0, %xmm0
movq 0x80(%rsp), %r13
movq 0x40(%rsp), %r9
movq 0x8(%rsp), %rax
movsd %xmm0, (%rax,%r9,8)
cmpl $-0x1, %r13d
movsd %xmm13, 0xf0(%rsp)
movsd %xmm15, 0xe0(%rsp)
movsd %xmm10, 0x108(%rsp)
movsd %xmm11, 0x100(%rsp)
movsd %xmm12, 0xf8(%rsp)
movsd %xmm14, 0xe8(%rsp)
movsd 0x2c4b(%rip), %xmm0     # 0x24470
jl 0x21863
xorl %ebx, %ebx
movsd 0x66bf(%rip), %xmm1     # 0x27ef0
movq 0x8(%rsp), %rax
mulsd (%rax,%rbx,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x21856
callq 0x32a0
movsd 0x66a2(%rip), %xmm1     # 0x27ef0
movsd 0x2c1a(%rip), %xmm0     # 0x24470
incq %rbx
cmpq %rbx, 0xb8(%rsp)
jne 0x21831
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
mulsd %xmm1, %xmm0
callq 0x32a0
movsd %xmm0, 0x110(%rsp)
cmpb $0x0, 0x88(%rsp)
jne 0x218d4
testl %r13d, %r13d
js 0x218aa
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x32c0
incq %rbx
cmpq %rbx, %r14
jne 0x21899
movq %r12, %rdi
callq 0x32c0
movq 0x8(%rsp), %rdi
callq 0x32c0
movq 0x28(%rsp), %rdi
callq 0x32c0
cmpb $0x0, 0x88(%rsp)
je 0x21fcd
testl %ebp, %ebp
movq 0x20(%rsp), %r9
movsd 0x108(%rsp), %xmm9
movsd 0x100(%rsp), %xmm10
movsd 0xf8(%rsp), %xmm11
movsd 0xf0(%rsp), %xmm12
movsd 0xe8(%rsp), %xmm13
movsd 0xe0(%rsp), %xmm14
movq 0x40(%rsp), %r8
movq 0x78(%rsp), %r10
movsd 0x48(%rsp), %xmm1
jle 0x21989
movq (%r9,%r10,8), %rax
movl %r13d, %ecx
subl (%rsp), %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovgl %ecx, %edx
movq 0x70(%rsp), %rcx
leal (%rcx,%rcx,2), %ecx
addl $0x3, %ecx
leal (%rdx,%rdx,2), %esi
movl $0x3, %edx
subl %esi, %edx
movl %edx, %esi
leal 0x3(%rsi), %edx
cmpl $0x7ffffffc, %esi       # imm = 0x7FFFFFFC
ja 0x21984
cmpl %ecx, %edx
jge 0x21984
movapd %xmm1, %xmm0
movq 0x8(%rsp), %rdi
divsd (%rdi,%r10,8), %xmm0
divsd (%rdi,%r8,8), %xmm0
movl %edx, %edi
movsd %xmm0, (%rax,%rdi,8)
addl $0x4, %esi
movsd %xmm0, (%rax,%rsi,8)
decq %r15
jne 0x2194f
cmpl $0x2, %r13d
movq 0xc0(%rsp), %rsi
jl 0x21cfa
movsd 0x653d(%rip), %xmm1     # 0x27ee0
movapd %xmm13, %xmm0
mulsd %xmm1, %xmm0
movl %r13d, %ecx
subl %ebp, %ecx
movl 0x14(%rsp), %eax
cmpl %ecx, %eax
cmovgl %eax, %ecx
mulsd %xmm1, %xmm11
movl 0x18(%rsp), %eax
cmpl %eax, %ecx
cmovlel %eax, %ecx
leal -0x1(%rcx,%r13), %eax
movslq %eax, %rdi
movslq %ebp, %rax
movq %rax, 0x38(%rsp)
movl %r13d, %r8d
subl %ecx, %r8d
notl %ecx
addl %r13d, %ecx
movl (%rsp), %eax
movsd 0x2a82(%rip), %xmm1     # 0x24470
negq %rax
movq %rax, 0x78(%rsp)
movsd 0x64ea(%rip), %xmm2     # 0x27ee8
movq %rsi, %r11
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
movq %rax, 0x88(%rsp)
testl %ecx, %ecx
movl $0x0, %edx
movq %rcx, 0xc8(%rsp)
cmovgl %ecx, %edx
movq 0x38(%rsp), %rax
cmpq %rax, %rdi
movq %rdi, 0xa0(%rsp)
cmovlq %rdi, %rax
testl %r8d, %r8d
movl $0x0, %ecx
movl %r8d, 0xb8(%rsp)
cmovgl %r8d, %ecx
movapd %xmm1, %xmm3
cmpq $0x2, %rsi
jne 0x21a5c
xorpd %xmm3, %xmm3
leal (%rdx,%rdx,2), %edx
movl %edx, 0x90(%rsp)
leaq -0x1(%r11), %rsi
movq -0x8(%r9,%r11,8), %r10
movq 0x78(%rsp), %rdx
movq %r11, 0x98(%rsp)
addq %r11, %rdx
decq %rdx
cmpl $0x2, %edx
movl $0x1, %edi
movq %rdx, 0x48(%rsp)
cmovgel %edx, %edi
movq (%rsp), %rdx
movq %rsi, 0xc0(%rsp)
addl %esi, %edx
cmpl %ebp, %edx
cmovgel %ebp, %edx
movq %rdi, 0x50(%rsp)
movq %rdx, 0x40(%rsp)
cmpl %edi, %edx
jl 0x21c40
leal (%rax,%rax,2), %r12d
leal (%rcx,%rcx,2), %eax
movl $0x4, %ebp
subl %eax, %ebp
movl $0x5, %r13d
movl 0x90(%rsp), %ecx
subl %ecx, %r13d
movl $0x4, %r11d
subl %ecx, %r11d
movl $0x3, %r15d
subl %ecx, %r15d
movl $0x8, %ebx
subl %ecx, %ebx
movl $0x6, %esi
subl %eax, %esi
movq 0x20(%rsp), %rax
movq 0x98(%rsp), %rdi
movq (%rax,%rdi,8), %r9
movq 0xa8(%rsp), %rax
movb -0x1(%rax,%rdi), %cl
movq 0xa0(%rsp), %rax
movq 0x38(%rsp), %rdx
cmpq %rdx, %rax
cmovlq %rax, %rdx
movq 0x28(%rsp), %rax
cvtss2sd -0x4(%rax,%rdi,4), %xmm4
movapd %xmm1, %xmm5
subsd %xmm4, %xmm5
mulsd %xmm2, %xmm4
movl 0x50(%rsp), %eax
xorpd %xmm6, %xmm6
cmpq 0x38(%rsp), %rdx
jge 0x21b78
movq 0xb0(%rsp), %rdi
movb (%rdi,%rdx), %r8b
movapd %xmm1, %xmm6
cmpb $0x3, %r8b
ja 0x21b78
movapd %xmm1, %xmm6
cmpb $0x3, %cl
ja 0x21b78
movapd %xmm5, %xmm6
cmpb %cl, %r8b
je 0x21b78
movapd %xmm4, %xmm6
leal (%r12,%rsi), %r8d
movslq %r8d, %r8
mulsd (%r9,%r8,8), %xmm6
leal (%r12,%r15), %r8d
leal (%r12,%rbp), %r14d
movslq %r14d, %r14
movsd (%r9,%r14,8), %xmm7
mulsd %xmm0, %xmm7
movapd %xmm6, %xmm8
mulsd %xmm12, %xmm8
addsd %xmm7, %xmm8
leal (%r12,%rbx), %edi
movslq %edi, %rdi
movsd (%r10,%rdi,8), %xmm7
mulsd %xmm13, %xmm7
addsd %xmm8, %xmm7
movslq %r8d, %r8
movsd %xmm7, (%r10,%r8,8)
movsd (%r9,%r14,8), %xmm7
mulsd %xmm11, %xmm7
movapd %xmm6, %xmm8
mulsd 0xd0(%rsp), %xmm8
addsd %xmm7, %xmm8
leal (%r12,%r11), %r8d
movslq %r8d, %r8
movsd %xmm8, (%r10,%r8,8)
movsd (%r10,%rdi,8), %xmm7
mulsd 0x60(%rsp), %xmm7
mulsd %xmm14, %xmm6
addsd %xmm7, %xmm6
mulsd %xmm3, %xmm6
leal (%r12,%r13), %edi
movslq %edi, %rdi
movsd %xmm6, (%r10,%rdi,8)
leaq -0x1(%rdx), %rdi
addl $-0x3, %ebp
addl $-0x3, %r13d
addl $-0x3, %r11d
addl $-0x3, %r15d
addl $-0x3, %ebx
addl $-0x3, %esi
cmpq %rax, %rdx
movq %rdi, %rdx
jg 0x21b41
movq 0x48(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq 0x50(%rsp), %rax
subl %ecx, %eax
leal (%rax,%rax,2), %eax
addl $0x3, %eax
movq 0x40(%rsp), %rdx
subl %ecx, %edx
leal (%rdx,%rdx,2), %ecx
addl $0x5, %ecx
cmpl %ecx, %eax
movq 0xc0(%rsp), %rsi
jg 0x21cba
movq 0x88(%rsp), %rax
leal (%rax,%rax,2), %eax
subl 0x90(%rsp), %eax
addl $0x3, %eax
cltq
decq %rax
movapd %xmm1, %xmm3
movq 0x8(%rsp), %rdx
divsd (%rdx,%rsi,8), %xmm3
movslq %ecx, %rcx
movsd 0x8(%r10,%rax,8), %xmm4
mulsd %xmm3, %xmm4
movsd %xmm4, 0x8(%r10,%rax,8)
incq %rax
cmpq %rcx, %rax
jl 0x21ca0
movq 0xa0(%rsp), %rdi
decq %rdi
movq 0xc8(%rsp), %rcx
decl %ecx
movl 0xb8(%rsp), %r8d
decl %r8d
cmpq $0x2, 0x98(%rsp)
movq 0x80(%rsp), %r13
movl 0x1c(%rsp), %ebp
movq 0x20(%rsp), %r9
jg 0x219fe
testl %ebp, %ebp
jle 0x21df6
movl %r13d, %esi
subl %ebp, %esi
movl 0x14(%rsp), %eax
cmpl %esi, %eax
cmovgl %eax, %esi
movl 0x18(%rsp), %eax
cmpl %eax, %esi
cmovlel %eax, %esi
incl %esi
cmpl %esi, %ebp
cmovll %ebp, %esi
movq 0x70(%rsp), %rax
leal 0x3(%rax,%rax,2), %eax
movq 0xb0(%rsp), %rcx
addq %rsi, %rcx
decq %rcx
leal (%rsi,%rsi,2), %edx
incl %esi
movq 0xd8(%rsp), %rdi
leal (%rdi,%rdi,2), %edi
subl %edi, %edx
addl $0x4, %edx
xorpd %xmm0, %xmm0
movsd 0x2718(%rip), %xmm1     # 0x24470
movsd 0x6180(%rip), %xmm2     # 0x27ee0
movsd 0x6180(%rip), %xmm3     # 0x27ee8
movq 0x158(%rsp), %r10
movq 0x28(%rsp), %r11
movb (%rcx), %dil
movapd %xmm1, %xmm4
cmpb $0x3, %dil
ja 0x21db6
movq 0xa8(%rsp), %r8
movb (%r8), %r8b
movapd %xmm1, %xmm4
cmpb $0x3, %r8b
ja 0x21db6
xorps %xmm5, %xmm5
cvtss2sd (%r11), %xmm5
cmpb %r8b, %dil
jne 0x21dae
movapd %xmm1, %xmm4
subsd %xmm5, %xmm4
jmp 0x21db6
mulsd %xmm3, %xmm5
movapd %xmm5, %xmm4
leal -0x1(%rdx), %edi
cmpl %eax, %edi
jge 0x21de7
movq 0x8(%r9), %r8
movl %edi, %edi
mulsd (%r8,%rdi,8), %xmm4
movl %edx, %edi
movsd (%r8,%rdi,8), %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm10, %xmm5
mulsd %xmm9, %xmm4
addsd %xmm5, %xmm4
addsd %xmm4, %xmm0
decl %esi
decq %rcx
addl $-0x3, %edx
cmpl $0x1, %esi
jg 0x21d75
jmp 0x21e02
xorpd %xmm0, %xmm0
movq 0x158(%rsp), %r10
movq 0x8(%rsp), %rax
divsd (%rax), %xmm0
movq (%r9), %rax
movsd %xmm0, 0x18(%rax)
testl %r13d, %r13d
movl 0x6c(%rsp), %eax
jle 0x21f79
movl (%rsp), %ebx
movl $0x1, %r14d
movl $0x1, %r15d
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 %r15d, %eax
movq (%rsp), %rdx
leal (%rdx,%r14), %r9d
cmpl %ebp, %r9d
cmovgel %ebp, %r9d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movsd 0x6089(%rip), %xmm1     # 0x27ef8
cmpl %r9d, %eax
jg 0x21f12
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 0x30(%rsp), %rdx
movq (%rdx,%r14,8), %rdi
movq 0x20(%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 0x21eb2
divsd %xmm0, %xmm1
movq 0x158(%rsp), %r10
movq 0x150(%rsp), %rax
testq %rax, %rax
je 0x21f24
movl %edx, -0x4(%rax,%r14,4)
testq %r10, %r10
je 0x21f66
movsd 0x253f(%rip), %xmm0     # 0x24470
subsd %xmm1, %xmm0
callq 0x32a0
movq 0x158(%rsp), %r10
mulsd 0x253e(%rip), %xmm0     # 0x24488
addsd 0x254e(%rip), %xmm0     # 0x244a0
cvttsd2si %xmm0, %eax
cmpl $0x65, %eax
movl $0x63, %ecx
cmovgel %ecx, %eax
movb %al, -0x1(%r10,%r14)
incq %r14
movl %r12d, %eax
incl %eax
cmpq 0x58(%rsp), %r14
jne 0x21e2f
testl %r13d, %r13d
movq 0x58(%rsp), %r14
movq 0x30(%rsp), %r15
movq 0x20(%rsp), %r12
js 0x21fa9
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0x32c0
movq (%r12,%rbx,8), %rdi
callq 0x32c0
incq %rbx
cmpq %rbx, %r14
jne 0x21f8f
movq %r15, %rdi
callq 0x32c0
movq %r12, %rdi
callq 0x32c0
movq 0x8(%rsp), %rdi
callq 0x32c0
movq 0x28(%rsp), %rdi
callq 0x32c0
movsd 0x110(%rsp), %xmm1
mulsd 0x24aa(%rip), %xmm1     # 0x24488
xorpd %xmm0, %xmm0
addsd %xmm1, %xmm0
addsd 0x24b2(%rip), %xmm0     # 0x244a0
cvttsd2si %xmm0, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq