// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/samtools-0.1.18/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) 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
movq %r8, %r14
movq %rdx, 0x90(%rsp)
movq %rdi, 0x98(%rsp)
cmpq $0x0, 0x140(%rsp)
setne %al
cmpq $0x0, 0x148(%rsp)
setne %bpl
andb %al, %bpl
movl %esi, %edx
subl %ecx, %edx
movl %ecx, %edi
movl %esi, 0xc(%rsp)
cmovgl %esi, %edi
movq %r9, 0x48(%rsp)
movl 0x8(%r9), %eax
cmpl %eax, %edi
cmovgel %eax, %edi
movl %edx, %eax
negl %eax
movl %edx, 0x28(%rsp)
cmovsl %edx, %eax
cmpl %eax, %edi
movl %edi, 0x70(%rsp)
cmovgl %edi, %eax
movq %rax, 0x68(%rsp)
movq %rcx, 0x10(%rsp)
leal 0x1(%rcx), %eax
movslq %eax, %rbx
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x31f40
movq %rax, %r13
movb %bpl, 0x24(%rsp)
cmpb $0x1, %bpl
movq %rbx, 0x50(%rsp)
jne 0x2a5ef5
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x31f40
movq %rax, %rbp
jmp 0x2a5ef7
xorl %ebp, %ebp
imull $0x6, 0x68(%rsp), %eax
movq %rax, 0x58(%rsp)
leal 0x9(%rax), %r12d
movslq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
xorl %ebx, %ebx
pushq $0x8
popq %r15
cmpq 0x30(%rsp), %rbx
jg 0x2a5f48
movq %r12, %rdi
movq %r15, %rsi
callq 0x31f40
movq %rax, (%r13,%rbx,8)
cmpb $0x0, 0x24(%rsp)
je 0x2a5f43
movq %r12, %rdi
movq %r15, %rsi
callq 0x31f40
movq %rax, (%rbp,%rbx,8)
incq %rbx
jmp 0x2a5f15
movq 0x10(%rsp), %rax
addl $0x2, %eax
movslq %eax, %rdi
pushq $0x8
popq %rsi
callq 0x31f40
movq %rax, 0x18(%rsp)
pushq $0x4
popq %rsi
movq 0x30(%rsp), %rdi
callq 0x31f40
movq %rax, 0x38(%rsp)
movss 0x16f416(%rip), %xmm0   # 0x415390
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
leaq 0x16f409(%rip), %rbx    # 0x415390
jne 0x2a5fc3
jp 0x2a5fc3
xorl %r15d, %r15d
movq %rbx, %r12
cmpq $-0x100, %r15
je 0x2a5fc3
cvtsi2sd %r15d, %xmm1
movsd 0x33911(%rip), %xmm0    # 0x2d98b8
divsd %xmm0, %xmm1
callq 0x32340
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r12)
decq %r15
addq $0x4, %r12
jmp 0x2a5f91
xorl %eax, %eax
movq 0x10(%rsp), %rdx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movq %rcx, 0x88(%rsp)
pushq $0x1e
popq %rcx
cmpq %rax, 0x88(%rsp)
je 0x2a600a
movq %rcx, %rdx
testq %r14, %r14
je 0x2a5ff6
movzbl (%r14,%rax), %edx
movss (%rbx,%rdx,4), %xmm0
movq 0x38(%rsp), %rdx
movss %xmm0, (%rdx,%rax,4)
incq %rax
jmp 0x2a5fdf
movq 0x10(%rsp), %r9
leal 0x2(,%r9,2), %eax
cvtsi2sd %eax, %xmm1
movsd 0x33835(%rip), %xmm0    # 0x2d9858
movapd %xmm0, %xmm6
divsd %xmm1, %xmm6
movq 0x48(%rsp), %rax
movss (%rax), %xmm2
movss 0x4(%rax), %xmm3
movss 0xb686f(%rip), %xmm4    # 0x35c8b0
movaps %xmm4, %xmm5
subss %xmm2, %xmm5
movaps %xmm5, %xmm1
subss %xmm2, %xmm1
movapd %xmm0, %xmm10
movsd %xmm6, 0x80(%rsp)
subsd %xmm6, %xmm10
cvtss2sd %xmm2, %xmm11
subss %xmm3, %xmm4
movl 0xc(%rsp), %edi
cvtsi2ss %edi, %xmm6
cvtss2sd %xmm4, %xmm12
cvtss2sd %xmm3, %xmm13
divss %xmm6, %xmm5
cvtss2sd %xmm5, %xmm8
divss %xmm6, %xmm2
cvtss2sd %xmm2, %xmm2
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq (%r13), %rcx
movq %rax, 0x18(%rcx)
movq 0x68(%rsp), %rax
leal 0x1(%rax), %r8d
cmpl %edi, %r8d
cmovgel %edi, %r8d
pushq $0x1
popq %r15
movl %r15d, %esi
subl %eax, %esi
xorl %edx, %edx
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0xa8(%rsp)
cmovgl %esi, %ecx
testl %r8d, %r8d
movl $0x0, %esi
movq %r8, 0xb0(%rsp)
cmovgl %r8d, %esi
movl %r9d, %eax
subl %edi, %eax
movl 0x70(%rsp), %r14d
cmpl %eax, %r14d
movq %rax, %r11
cmovgl %r14d, %eax
movl 0x28(%rsp), %ebx
cmpl %ebx, %eax
cmovlel %ebx, %eax
movl %r15d, %edi
subl %eax, %edi
testl %edi, %edi
cmovlel %edx, %edi
leal (%rdi,%rdi,2), %eax
pushq $0x7
popq %rdi
subl %eax, %edi
movq 0x8(%r13), %rax
movsd 0x564fd(%rip), %xmm3    # 0x2fc620
movsd %xmm2, 0xe8(%rsp)
mulsd %xmm2, %xmm3
xorpd %xmm2, %xmm2
movsd 0xb676b(%rip), %xmm9    # 0x35c8a8
movq 0x38(%rsp), %r10
cmpq %rdx, %rsi
je 0x2a61b9
movq 0x98(%rsp), %r8
movb (%r8,%rdx), %r8b
movapd %xmm0, %xmm4
cmpb $0x3, %r8b
ja 0x2a618f
movq 0x90(%rsp), %r9
movb (%r9), %r9b
movapd %xmm0, %xmm4
cmpb $0x3, %r9b
ja 0x2a618f
cvtss2sd (%r10), %xmm5
cmpb %r9b, %r8b
jne 0x2a6186
movapd %xmm0, %xmm4
subsd %xmm5, %xmm4
jmp 0x2a618f
mulsd %xmm9, %xmm5
movapd %xmm5, %xmm4
leal -0x1(%rdi), %r8d
mulsd %xmm8, %xmm4
movslq %r8d, %r8
movsd %xmm4, (%rax,%r8,8)
movslq %edi, %rdi
movsd %xmm3, (%rax,%rdi,8)
addsd %xmm3, %xmm4
addsd %xmm4, %xmm2
addl $0x3, %edi
incq %rdx
jmp 0x2a6142
cvtss2sd %xmm1, %xmm14
mulsd %xmm10, %xmm14
movapd %xmm10, %xmm15
mulsd %xmm12, %xmm15
movq 0x18(%rsp), %rdx
movsd %xmm2, 0x8(%rdx)
movq 0xb0(%rsp), %rdx
subl %ecx, %edx
leal (%rdx,%rdx,2), %ecx
addl $0x5, %ecx
cmpl %r11d, %r14d
cmovgl %r14d, %r11d
cmpl %ebx, %r11d
cmovlel %ebx, %r11d
testl %r11d, %r11d
movl %r15d, %edx
movq %r11, 0x78(%rsp)
cmovlel %r11d, %edx
leal (%rdx,%rdx,2), %edx
addl $0x3, %edx
cmpl %edx, %ecx
jl 0x2a6221
movsd (%rax,%rdx,8), %xmm0
divsd %xmm2, %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
jmp 0x2a620a
mulsd %xmm10, %xmm11
mulsd %xmm13, %xmm10
pushq $0x2
popq %rdx
movq 0x78(%rsp), %rax
subl %eax, %edx
movl %r15d, %r8d
subl %eax, %r8d
pushq $0x2
popq %r14
movsd 0x33611(%rip), %xmm0    # 0x2d9858
movq %r13, 0xa0(%rsp)
movq %rbp, 0x40(%rsp)
cmpl $0x2, %edx
movl %r15d, %ecx
cmovgel %edx, %ecx
testl %r8d, %r8d
movl $0x0, %esi
cmovgl %r8d, %esi
testl %edx, %edx
movl $0x0, %edi
cmovgl %edx, %edi
cmpq 0x30(%rsp), %r14
jg 0x2a648a
movl %r8d, 0x70(%rsp)
movl %edx, 0x28(%rsp)
leal (%rcx,%rcx,2), %r9d
imull $-0x3, %esi, %r10d
imull $-0x3, %edi, %r11d
leal (%r11,%r9), %esi
addl $0x3, %esi
movslq %esi, %rdi
movl %ecx, %ebx
movq %r14, %rdx
movq -0x8(%r13,%r14,8), %r14
movq 0x38(%rsp), %rax
cvtss2sd -0x4(%rax,%rdx,4), %xmm1
movq (%r13,%rdx,8), %r8
movq 0x90(%rsp), %rax
movb -0x1(%rax,%rdx), %bpl
movq 0x68(%rsp), %rcx
leal (%rcx,%rdx), %r15d
movl 0xc(%rsp), %eax
cmpl %eax, %r15d
cmovgel %eax, %r15d
movapd %xmm0, %xmm2
subsd %xmm1, %xmm2
mulsd %xmm9, %xmm1
movq %rdx, 0x48(%rsp)
subl %ecx, %edx
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
movl %edx, 0x60(%rsp)
movslq %r15d, %rsi
xorpd %xmm3, %xmm3
cmpq %rsi, %rbx
jg 0x2a6422
movq 0x98(%rsp), %rax
movb -0x1(%rax,%rbx), %cl
movapd %xmm2, %xmm4
cmpb %bpl, %cl
je 0x2a6323
movapd %xmm1, %xmm4
movapd %xmm0, %xmm6
cmpb $0x4, %bpl
jae 0x2a6331
movapd %xmm4, %xmm6
movapd %xmm0, %xmm5
cmpb $0x4, %cl
jae 0x2a633e
movapd %xmm6, %xmm5
leal (%r9,%r11), %ecx
leal (%r9,%r11), %r13d
addl $0x3, %r13d
leal (%r9,%r10), %eax
leal 0x3(%r9,%r10), %edx
cltq
leal 0x1(%r9,%r10), %r12d
movslq %r12d, %r12
movsd (%r14,%r12,8), %xmm4
mulsd %xmm15, %xmm4
movsd (%r14,%rax,8), %xmm6
mulsd %xmm14, %xmm6
addsd %xmm4, %xmm6
leal 0x2(%r9,%r10), %eax
cltq
movsd (%r14,%rax,8), %xmm4
mulsd %xmm12, %xmm4
addsd %xmm6, %xmm4
mulsd %xmm5, %xmm4
movslq %r13d, %rax
movsd %xmm4, (%r8,%rax,8)
movslq %edx, %rax
leal 0x4(%r9,%r10), %edx
movslq %edx, %rdx
movsd (%r14,%rdx,8), %xmm5
mulsd %xmm10, %xmm5
movsd (%r14,%rax,8), %xmm6
mulsd %xmm11, %xmm6
addsd %xmm5, %xmm6
mulsd 0x56259(%rip), %xmm6    # 0x2fc620
leal 0x4(%r9,%r11), %eax
cltq
movsd %xmm6, (%r8,%rax,8)
movslq %ecx, %rax
leal 0x2(%r9,%r11), %ecx
movslq %ecx, %rcx
movsd (%r8,%rcx,8), %xmm5
mulsd %xmm13, %xmm5
movsd (%r8,%rax,8), %xmm7
mulsd %xmm11, %xmm7
addsd %xmm5, %xmm7
leal 0x5(%r9,%r11), %eax
cltq
movsd %xmm7, (%r8,%rax,8)
addsd %xmm4, %xmm6
addsd %xmm7, %xmm6
addsd %xmm6, %xmm3
incq %rbx
addl $0x3, %r10d
addl $0x3, %r11d
jmp 0x2a6301
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %r14
movsd %xmm3, (%rax,%r14,8)
subl 0x60(%rsp), %r15d
leal (%r15,%r15,2), %eax
addl $0x5, %eax
movapd %xmm0, %xmm1
divsd %xmm3, %xmm1
movslq %eax, %rcx
movq 0xa0(%rsp), %r13
movq 0x40(%rsp), %rbp
pushq $0x1
popq %r15
cmpq %rcx, %rdi
jg 0x2a6474
movsd (%r8,%rdi,8), %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, (%r8,%rdi,8)
incq %rdi
jmp 0x2a645a
incq %r14
movl 0x28(%rsp), %edx
incl %edx
movl 0x70(%rsp), %r8d
incl %r8d
jmp 0x2a6254
movq 0x58(%rsp), %rax
addl $0x6, %eax
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
movl $0x0, %ebx
cmovgl %ecx, %ebx
movq 0x10(%rsp), %rcx
movl %ecx, %r12d
subl 0x78(%rsp), %r12d
testl %r12d, %r12d
cmovgl %r12d, %eax
leal (%rax,%rax,2), %eax
pushq $0x3
popq %rcx
movl %ecx, %edx
subl %eax, %edx
xorpd %xmm0, %xmm0
movq %rbx, %rax
movsd 0x80(%rsp), %xmm3
subq $0x1, %rax
jb 0x2a6519
leal 0x3(%rdx), %ecx
cmpl $0x7ffffffc, %edx       # imm = 0x7FFFFFFC
ja 0x2a6515
cmpl 0x58(%rsp), %ecx
jge 0x2a6515
movq 0x30(%rsp), %rsi
movq (%r13,%rsi,8), %rsi
movl %ecx, %edi
movl %edx, %edx
movsd 0x20(%rsi,%rdx,8), %xmm1
mulsd %xmm3, %xmm1
movsd (%rsi,%rdi,8), %xmm2
mulsd %xmm3, %xmm2
addsd %xmm1, %xmm2
addsd %xmm2, %xmm0
movl %ecx, %edx
jmp 0x2a64d5
movq 0x18(%rsp), %rax
movq 0x50(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x33328(%rip), %xmm1    # 0x2d9858
xorpd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
xorl %r14d, %r14d
movsd 0x48153(%rip), %xmm2    # 0x2ee698
movapd %xmm1, %xmm0
movsd %xmm8, 0xd8(%rsp)
movsd %xmm10, 0x28(%rsp)
movsd %xmm11, 0xd0(%rsp)
movsd %xmm12, 0xc8(%rsp)
movsd %xmm13, 0xc0(%rsp)
movsd %xmm14, 0xb8(%rsp)
movsd %xmm15, 0x70(%rsp)
cmpq %rcx, %r14
jg 0x2a65d6
movq 0x18(%rsp), %rax
mulsd (%rax,%r14,8), %xmm0
ucomisd %xmm0, %xmm2
jbe 0x2a65d1
callq 0x30520
movsd 0x480ec(%rip), %xmm2    # 0x2ee698
movq 0x50(%rsp), %rcx
mulsd 0xb51bf(%rip), %xmm0    # 0x35b778
movsd 0x60(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
movsd 0x33287(%rip), %xmm0    # 0x2d9858
incq %r14
jmp 0x2a6589
cvtsi2sdl 0xc(%rsp), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x30520
movsd %xmm0, 0xe0(%rsp)
cmpb $0x0, 0x24(%rsp)
je 0x2a66b3
xorl %eax, %eax
testl %r12d, %r12d
cmovgl %r12d, %eax
leal (%rax,%rax,2), %ecx
pushq $0x3
popq %rax
subl %ecx, %eax
movsd 0xd8(%rsp), %xmm8
movsd 0xb627d(%rip), %xmm9    # 0x35c8a8
movsd 0x28(%rsp), %xmm10
movsd 0xd0(%rsp), %xmm11
movsd 0xc8(%rsp), %xmm12
movsd 0xc0(%rsp), %xmm13
movsd 0x55fc7(%rip), %xmm14   # 0x2fc620
movsd 0xb8(%rsp), %xmm15
movq 0x18(%rsp), %rdi
subq $0x1, %rbx
jb 0x2a66cf
leal 0x3(%rax), %ecx
cmpl $0x7ffffffc, %eax       # imm = 0x7FFFFFFC
ja 0x2a66af
cmpl 0x58(%rsp), %ecx
jge 0x2a66af
movq 0x30(%rsp), %rsi
movq (%rbp,%rsi,8), %rdx
movsd 0x80(%rsp), %xmm0
divsd (%rdi,%rsi,8), %xmm0
movq 0x50(%rsp), %rsi
divsd (%rdi,%rsi,8), %xmm0
movl %ecx, %esi
movsd %xmm0, (%rdx,%rsi,8)
movl %eax, %eax
movsd %xmm0, 0x20(%rdx,%rax,8)
movl %ecx, %eax
jmp 0x2a6668
xorl %ebx, %ebx
cmpq 0x30(%rsp), %rbx
jg 0x2a6c0b
movq (%r13,%rbx,8), %rdi
callq 0x33058
incq %rbx
jmp 0x2a66b5
movapd %xmm11, %xmm0
mulsd %xmm14, %xmm0
mulsd %xmm14, %xmm10
movslq 0xc(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x78(%rsp), %rax
movq 0x10(%rsp), %rcx
leal (%rax,%rcx), %edi
movl %eax, %r10d
notl %r10d
addl %ecx, %r10d
movl %ecx, %edx
leal (%rax,%rcx), %r11d
decl %r11d
movsd 0x33149(%rip), %xmm1    # 0x2d9858
movslq %r11d, %r8
movq 0x28(%rsp), %rax
cmpq %r8, %rax
cmovlq %rax, %r8
testl %r12d, %r12d
movl $0x0, %r9d
cmovgl %r12d, %r9d
testl %r10d, %r10d
movl $0x0, %ecx
cmovgl %r10d, %ecx
cmpl $0x2, %r10d
movl %r15d, %esi
cmovgel %r10d, %esi
cmpl $0x1, %edx
jle 0x2a69bc
movl %r11d, 0x10(%rsp)
movl %r10d, 0x80(%rsp)
movl %r12d, 0x24(%rsp)
decl %edi
movl 0xc(%rsp), %eax
cmpl %edi, %eax
movl %edi, 0x50(%rsp)
cmovll %eax, %edi
movapd %xmm1, %xmm2
cmpq $0x2, %rdx
jne 0x2a677a
xorpd %xmm2, %xmm2
leal (%r8,%r8,2), %r10d
leal (%r9,%r9,2), %r9d
pushq $0x4
popq %rax
movl %eax, %r11d
subl %r9d, %r11d
leal (%rcx,%rcx,2), %ebp
pushq $0x5
popq %r8
subl %ebp, %r8d
movl %eax, %r12d
subl %ebp, %r12d
pushq $0x3
popq %rax
movl %eax, %ebx
subl %ebp, %ebx
pushq $0x8
popq %rax
movl %eax, %r14d
subl %ebp, %r14d
pushq $0x6
popq %rax
movl %eax, %ebp
subl %r9d, %ebp
leal (%rsi,%rsi,2), %esi
imull $-0x3, %ecx, %ecx
addl %esi, %ecx
addl $0x3, %ecx
movslq %ecx, %r9
leaq -0x1(%rdx), %r13
movslq %edi, %r15
movq 0x38(%rsp), %rax
cvtss2sd -0x4(%rax,%rdx,4), %xmm3
movq 0x40(%rsp), %rax
movq (%rax,%rdx,8), %rcx
movq 0x90(%rsp), %rax
movb -0x1(%rax,%rdx), %al
movb %al, 0x48(%rsp)
movl %r13d, %esi
movq 0x68(%rsp), %rax
subl %eax, %esi
cmpl $0x2, %esi
pushq $0x1
popq %rdx
movl %edx, %edi
cmovgel %esi, %edi
leal (%rax,%r13), %edx
movl 0xc(%rsp), %eax
cmpl %eax, %edx
cmovgel %eax, %edx
movq %rdx, 0xf8(%rsp)
testl %esi, %esi
movl $0x0, %eax
cmovlel %eax, %esi
movl %esi, 0xac(%rsp)
movapd %xmm1, %xmm4
subsd %xmm3, %xmm4
mulsd %xmm9, %xmm3
movq %r13, 0x100(%rsp)
movl %r13d, %eax
movq %rax, 0xf0(%rsp)
movq 0x40(%rsp), %rdx
movq (%rdx,%rax,8), %rsi
cmpq %rdi, %r15
jl 0x2a693f
xorps %xmm5, %xmm5
cmpq 0x28(%rsp), %r15
jge 0x2a6893
movq 0x98(%rsp), %rax
movb (%rax,%r15), %r13b
movapd %xmm1, %xmm5
cmpb $0x3, %r13b
ja 0x2a6893
movapd %xmm1, %xmm5
cmpb $0x3, 0x48(%rsp)
ja 0x2a6893
movapd %xmm4, %xmm5
cmpb 0x48(%rsp), %r13b
je 0x2a6893
movapd %xmm3, %xmm5
leal (%r10,%rbx), %r13d
leal (%r10,%rbp), %eax
cltq
mulsd (%rcx,%rax,8), %xmm5
leal (%r10,%r11), %eax
cltq
movsd (%rcx,%rax,8), %xmm6
mulsd %xmm0, %xmm6
movapd %xmm5, %xmm7
mulsd %xmm15, %xmm7
addsd %xmm6, %xmm7
leal (%r10,%r14), %edx
movslq %edx, %rdx
movsd (%rsi,%rdx,8), %xmm6
mulsd %xmm11, %xmm6
addsd %xmm7, %xmm6
movslq %r13d, %r13
movsd %xmm6, (%rsi,%r13,8)
movsd (%rcx,%rax,8), %xmm6
mulsd %xmm10, %xmm6
movapd %xmm5, %xmm7
mulsd 0x70(%rsp), %xmm7
addsd %xmm6, %xmm7
leal (%r10,%r12), %eax
cltq
movsd %xmm7, (%rsi,%rax,8)
movsd (%rsi,%rdx,8), %xmm6
mulsd %xmm13, %xmm6
mulsd %xmm12, %xmm5
addsd %xmm6, %xmm5
mulsd %xmm2, %xmm5
leal (%r10,%r8), %eax
cltq
movsd %xmm5, (%rsi,%rax,8)
decq %r15
addl $-0x3, %r11d
addl $-0x3, %r8d
addl $-0x3, %r12d
addl $-0x3, %ebx
addl $-0x3, %r14d
addl $-0x3, %ebp
jmp 0x2a6850
movq 0xf8(%rsp), %rax
subl 0xac(%rsp), %eax
leal (%rax,%rax,2), %eax
addl $0x5, %eax
movapd %xmm1, %xmm2
movq 0x18(%rsp), %rcx
movq 0xf0(%rsp), %rdx
divsd (%rcx,%rdx,8), %xmm2
movslq %eax, %rcx
movq 0x40(%rsp), %rbp
pushq $0x1
popq %r15
movl 0x24(%rsp), %r12d
movl 0x50(%rsp), %edi
movl 0x80(%rsp), %r10d
movl 0x10(%rsp), %r11d
cmpq %rcx, %r9
jg 0x2a69a6
movsd (%rsi,%r9,8), %xmm3
mulsd %xmm2, %xmm3
movsd %xmm3, (%rsi,%r9,8)
incq %r9
jmp 0x2a698c
decl %r10d
decl %r11d
decl %r12d
movq 0x100(%rsp), %rdx
jmp 0x2a670f
movq 0xb0(%rsp), %rcx
movl %ecx, %eax
leal (%rcx,%rcx,2), %ecx
movl %r15d, %edx
subl 0x78(%rsp), %edx
xorl %esi, %esi
testl %edx, %edx
cmovgl %edx, %esi
leal (%rsi,%rsi,2), %edx
subl %edx, %ecx
addl $0x4, %ecx
xorpd %xmm0, %xmm0
movsd 0x32e6d(%rip), %xmm1    # 0x2d9858
movq 0x38(%rsp), %rdi
testl %eax, %eax
jle 0x2a6a7f
movq 0x98(%rsp), %rdx
movb -0x1(%rdx,%rax), %dl
movapd %xmm1, %xmm2
cmpb $0x3, %dl
ja 0x2a6a3e
movq 0x90(%rsp), %rsi
movb (%rsi), %sil
movapd %xmm1, %xmm2
cmpb $0x3, %sil
ja 0x2a6a3e
cvtss2sd (%rdi), %xmm3
cmpb %sil, %dl
jne 0x2a6a35
movapd %xmm1, %xmm2
subsd %xmm3, %xmm2
jmp 0x2a6a3e
mulsd %xmm9, %xmm3
movapd %xmm3, %xmm2
leal -0x1(%rcx), %edx
cmpl 0x58(%rsp), %edx
jge 0x2a6a74
movq 0x8(%rbp), %rsi
movl %edx, %edx
mulsd (%rsi,%rdx,8), %xmm2
movl %ecx, %edx
movsd (%rsi,%rdx,8), %xmm3
mulsd %xmm14, %xmm3
mulsd 0xe8(%rsp), %xmm3
mulsd %xmm8, %xmm2
addsd %xmm3, %xmm2
addsd %xmm2, %xmm0
decq %rax
addl $-0x3, %ecx
jmp 0x2a69f0
movq 0x18(%rsp), %rax
divsd (%rax), %xmm0
movq (%rbp), %rax
movsd %xmm0, 0x18(%rax)
movq 0x88(%rsp), %rax
incl %eax
movq %rax, 0x88(%rsp)
pushq $0x1
popq %rbx
pushq $-0x1
popq %rbp
pushq $0x63
popq %r14
movl 0xa8(%rsp), %r12d
cmpl $0x2, %r12d
movl %r15d, %ecx
cmovgel %r12d, %ecx
testl %r12d, %r12d
movl $0x0, %edx
cmovgl %r12d, %edx
cmpq 0x88(%rsp), %rbx
je 0x2a6bd5
leal (%rcx,%rcx,2), %eax
leal (%rdx,%rdx,2), %edx
subl %edx, %eax
addl $0x4, %eax
leal -0x4(,%rcx,4), %ecx
cmpl $0x2, %r12d
movl %r15d, %edx
cmovgel %r12d, %edx
movq 0xa0(%rsp), %rsi
movq (%rsi,%rbx,8), %rsi
movq 0x40(%rsp), %rdi
movq (%rdi,%rbx,8), %rdi
movq 0x68(%rsp), %r8
addl %ebx, %r8d
movl 0xc(%rsp), %r9d
cmpl %r9d, %r8d
cmovgel %r9d, %r8d
movslq %r8d, %r8
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movl %ebp, %r9d
cmpq %r8, %rdx
jg 0x2a6b81
leal -0x1(%rax), %r10d
movslq %r10d, %r10
movsd (%rsi,%r10,8), %xmm2
mulsd (%rdi,%r10,8), %xmm2
ucomisd %xmm1, %xmm2
cmoval %ecx, %r9d
addsd %xmm2, %xmm0
maxsd %xmm1, %xmm2
cltq
movsd (%rsi,%rax,8), %xmm1
mulsd (%rdi,%rax,8), %xmm1
leal 0x1(%rcx), %r10d
ucomisd %xmm2, %xmm1
cmoval %r10d, %r9d
addsd %xmm1, %xmm0
maxsd %xmm2, %xmm1
incq %rdx
addl $0x3, %eax
addl $0x4, %ecx
jmp 0x2a6b2e
divsd %xmm0, %xmm1
movsd 0x32ccb(%rip), %xmm0    # 0x2d9858
subsd %xmm1, %xmm0
movq 0x140(%rsp), %rax
movl %r9d, -0x4(%rax,%rbx,4)
callq 0x30520
mulsd 0xb4bcd(%rip), %xmm0    # 0x35b778
addsd 0xb4bcd(%rip), %xmm0    # 0x35b780
cvttsd2si %xmm0, %eax
cmpl $0x65, %eax
cmovgel %r14d, %eax
movq 0x148(%rsp), %rcx
movb %al, -0x1(%rcx,%rbx)
incq %rbx
incl %r12d
jmp 0x2a6ab5
xorl %ebx, %ebx
movq 0xa0(%rsp), %r14
movq 0x40(%rsp), %r13
cmpq 0x30(%rsp), %rbx
jg 0x2a6c03
movq (%r14,%rbx,8), %rdi
callq 0x33058
movq (%r13,%rbx,8), %rdi
callq 0x33058
incq %rbx
jmp 0x2a6be4
movq %r14, %rdi
callq 0x33058
movq %r13, %rdi
callq 0x33058
movq 0x18(%rsp), %rdi
callq 0x33058
movq 0x38(%rsp), %rdi
callq 0x33058
movsd 0xe0(%rsp), %xmm0
mulsd 0xb4b40(%rip), %xmm0    # 0x35b778
addsd 0x60(%rsp), %xmm0
addsd 0xb4b3a(%rip), %xmm0    # 0x35b780
cvttsd2si %xmm0, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq