// File: /workspace/github_cpp_makefile_star2_O3/statgen[P]statgen/lib/samtools-0.1.7a-hybrid/bam_maqcns.c
// Function: bam_maqindel
bam_maqindel_ret_t *bam_maqindel(int n, int pos, const bam_maqindel_opt_t *mi, const bam_pileup1_t *pl, const char *ref,
								 int _n_types, int *_types)
{
	int i, j, n_types, *types, left, right, max_rd_len = 0;
	bam_maqindel_ret_t *ret = 0;
	// if there is no proposed indel, check if there is an indel from the alignment
	if (_n_types == 0) {
		for (i = 0; i < n; ++i) {
			const bam_pileup1_t *p = pl + i;
			if (!(p->b->core.flag&BAM_FUNMAP) && p->indel != 0) break;
		}
		if (i == n) return 0; // no indel
	}
	{ // calculate how many types of indels are available (set n_types and types)
		int m;
		uint32_t *aux;
		aux = (uint32_t*)calloc(n + _n_types + 1, 4);
		m = 0;
		aux[m++] = MINUS_CONST; // zero indel is always a type
		for (i = 0; i < n; ++i) {
			const bam_pileup1_t *p = pl + i;
			if (!(p->b->core.flag&BAM_FUNMAP) && p->indel != 0)
				aux[m++] = MINUS_CONST + p->indel;
			j = bam_cigar2qlen(&p->b->core, bam1_cigar(p->b));
			if (j > max_rd_len) max_rd_len = j;
		}
		if (_n_types) // then also add this to aux[]
			for (i = 0; i < _n_types; ++i)
				if (_types[i]) aux[m++] = MINUS_CONST + _types[i];
		ks_introsort(uint32_t, m, aux);
		// squeeze out identical types
		for (i = 1, n_types = 1; i < m; ++i)
			if (aux[i] != aux[i-1]) ++n_types;
		types = (int*)calloc(n_types, sizeof(int));
		j = 0;
		types[j++] = aux[0] - MINUS_CONST; 
		for (i = 1; i < m; ++i) {
			if (aux[i] != aux[i-1])
				types[j++] = aux[i] - MINUS_CONST;
		}
		free(aux);
	}
	{ // calculate left and right boundary
		left = pos > INDEL_WINDOW_SIZE? pos - INDEL_WINDOW_SIZE : 0;
		right = pos + INDEL_WINDOW_SIZE;
		if (types[0] < 0) right -= types[0];
		// in case the alignments stand out the reference
		for (i = pos; i < right; ++i)
			if (ref[i] == 0) break;
		right = i;
	}
	{ // the core part
		char *ref2, *rs, *inscns = 0;
		int k, l, *score, *pscore, max_ins = types[n_types-1];
		if (max_ins > 0) { // get the consensus of inserted sequences
			int *inscns_aux = (int*)calloc(4 * n_types * max_ins, sizeof(int));
			// count occurrences
			for (i = 0; i < n_types; ++i) {
				if (types[i] <= 0) continue; // not insertion
				for (j = 0; j < n; ++j) {
					const bam_pileup1_t *p = pl + j;
					if (!(p->b->core.flag&BAM_FUNMAP) && p->indel == types[i]) {
						for (k = 1; k <= p->indel; ++k) {
							int c = bam_nt16_nt4_table[bam1_seqi(bam1_seq(p->b), p->qpos + k)];
							if (c < 4) ++inscns_aux[i*max_ins*4 + (k-1)*4 + c];
						}
					}
				}
			}
			// construct the consensus of inserted sequence
			inscns = (char*)calloc(n_types * max_ins, sizeof(char));
			for (i = 0; i < n_types; ++i) {
				for (j = 0; j < types[i]; ++j) {
					int max = 0, max_k = -1, *ia = inscns_aux + i*max_ins*4 + j*4;
					for (k = 0; k < 4; ++k) {
						if (ia[k] > max) {
							max = ia[k];
							max_k = k;
						}
					}
					inscns[i*max_ins + j] = max? 1<<max_k : 15;
				}
			}
			free(inscns_aux);
		}
		// calculate score
		ref2 = (char*)calloc(right - left + types[n_types-1] + 2, 1);
		rs   = (char*)calloc(right - left + max_rd_len + types[n_types-1] + 2, 1);
		score = (int*)calloc(n_types * n, sizeof(int));
		pscore = (int*)calloc(n_types * n, sizeof(int));
		for (i = 0; i < n_types; ++i) {
			ka_param_t ap = ka_param_blast;
			ap.band_width = 2 * types[n_types - 1] + 2;
			// write ref2
			for (k = 0, j = left; j <= pos; ++j)
				ref2[k++] = bam_nt16_nt4_table[bam_nt16_table[(int)ref[j]]];
			if (types[i] <= 0) j += -types[i];
			else for (l = 0; l < types[i]; ++l)
					 ref2[k++] = bam_nt16_nt4_table[(int)inscns[i*max_ins + l]];
			for (; j < right && ref[j]; ++j)
				ref2[k++] = bam_nt16_nt4_table[bam_nt16_table[(int)ref[j]]];
			if (j < right) right = j;
			// calculate score for each read
			for (j = 0; j < n; ++j) {
				const bam_pileup1_t *p = pl + j;
				int qbeg, qend, tbeg, tend;
				if (p->b->core.flag & BAM_FUNMAP) continue;
				qbeg = bam_tpos2qpos(&p->b->core, bam1_cigar(p->b), left,  0, &tbeg);
				qend = bam_tpos2qpos(&p->b->core, bam1_cigar(p->b), right, 1, &tend);
				assert(tbeg >= left);
				for (l = qbeg; l < qend; ++l)
					rs[l - qbeg] = bam_nt16_nt4_table[bam1_seqi(bam1_seq(p->b), l)];
				{
					int x, y, n_acigar, ps;
					uint32_t *acigar;
					ps = 0;
					if (tend - tbeg + types[i] <= 0) {
						score[i*n+j] = -(1<<20);
						pscore[i*n+j] = 1<<20;
						continue;
					}
					acigar = ka_global_core((uint8_t*)ref2 + tbeg - left, tend - tbeg + types[i], (uint8_t*)rs, qend - qbeg, &ap, &score[i*n+j], &n_acigar);
					x = tbeg - left; y = 0;
					for (l = 0; l < n_acigar; ++l) {
						int op = acigar[l]&0xf;
						int len = acigar[l]>>4;
						if (op == BAM_CMATCH) {
							int k;
							for (k = 0; k < len; ++k)
								if (ref2[x+k] != rs[y+k]) ps += bam1_qual(p->b)[y+k];
							x += len; y += len;
						} else if (op == BAM_CINS || op == BAM_CSOFT_CLIP) {
							if (op == BAM_CINS) ps += mi->q_indel * len;
							y += len;
						} else if (op == BAM_CDEL) {
							ps += mi->q_indel * len;
							x += len;
						}
					}
					pscore[i*n+j] = ps;
					/*if (pos == 2618517) { // for debugging only
						fprintf(stderr, "pos=%d, type=%d, j=%d, score=%d, psore=%d, %d, %d, %d, %d, ", pos+1, types[i], j, score[i*n+j], pscore[i*n+j], tbeg, tend, qbeg, qend);
						for (l = 0; l < n_acigar; ++l) fprintf(stderr, "%d%c", acigar[l]>>4, "MIDS"[acigar[l]&0xf]); fprintf(stderr, "\n");
						for (l = 0; l < tend - tbeg + types[i]; ++l) fputc("ACGTN"[ref2[l]], stderr); fputc('\n', stderr);
						for (l = 0; l < qend - qbeg; ++l) fputc("ACGTN"[rs[l]], stderr); fputc('\n', stderr);
						}*/
					free(acigar);
				}
			}
		}
		{ // get final result
			int *sum, max1, max2, max1_i, max2_i;
			// pick up the best two score
			sum = (int*)calloc(n_types, sizeof(int));
			for (i = 0; i < n_types; ++i)
				for (j = 0; j < n; ++j)
					sum[i] += -pscore[i*n+j];
			max1 = max2 = -0x7fffffff; max1_i = max2_i = -1;
			for (i = 0; i < n_types; ++i) {
				if (sum[i] > max1) {
					max2 = max1; max2_i = max1_i; max1 = sum[i]; max1_i = i;
				} else if (sum[i] > max2) {
					max2 = sum[i]; max2_i = i;
				}
			}
			free(sum);
			// write ret
			ret = (bam_maqindel_ret_t*)calloc(1, sizeof(bam_maqindel_ret_t));
			ret->indel1 = types[max1_i]; ret->indel2 = types[max2_i];
			ret->s[0] = (char*)calloc(abs(ret->indel1) + 2, 1);
			ret->s[1] = (char*)calloc(abs(ret->indel2) + 2, 1);
			// write indel sequence
			if (ret->indel1 > 0) {
				ret->s[0][0] = '+';
				for (k = 0; k < ret->indel1; ++k)
					ret->s[0][k+1] = bam_nt16_rev_table[(int)inscns[max1_i*max_ins + k]];
			} else if (ret->indel1 < 0) {
				ret->s[0][0] = '-';
				for (k = 0; k < -ret->indel1 && ref[pos + k + 1]; ++k)
					ret->s[0][k+1] = ref[pos + k + 1];
			} else ret->s[0][0] = '*';
			if (ret->indel2 > 0) {
				ret->s[1][0] = '+';
				for (k = 0; k < ret->indel2; ++k)
					ret->s[1][k+1] = bam_nt16_rev_table[(int)inscns[max2_i*max_ins + k]];
			} else if (ret->indel2 < 0) {
				ret->s[1][0] = '-';
				for (k = 0; k < -ret->indel2 && ref[pos + k + 1]; ++k)
					ret->s[1][k+1] = ref[pos + k + 1];
			} else ret->s[1][0] = '*';
			// write count
			for (i = 0; i < n; ++i) {
				const bam_pileup1_t *p = pl + i;
				if (p->indel == ret->indel1) ++ret->cnt1;
				else if (p->indel == ret->indel2) ++ret->cnt2;
				else ++ret->cnt_anti;
			}
			{ // write gl[]
				int tmp, seq_err = 0;
				double x = 1.0;
				tmp = max1_i - max2_i;
				if (tmp < 0) tmp = -tmp;
				for (j = 0; j < tmp + 1; ++j) x *= INDEL_EXT_DEP;
				seq_err = mi->q_indel * (1.0 - x) / (1.0 - INDEL_EXT_DEP);
				ret->gl[0] = ret->gl[1] = 0;
				for (j = 0; j < n; ++j) {
					int s1 = pscore[max1_i*n + j], s2 = pscore[max2_i*n + j];
					//printf("%d, %d, %d, %d, %d\n", pl[j].b->core.pos+1, max1_i, max2_i, s1, s2);
					if (s1 > s2) ret->gl[0] += s1 - s2 < seq_err? s1 - s2 : seq_err;
					else ret->gl[1] += s2 - s1 < seq_err? s2 - s1 : seq_err;
				}
			}
			// write cnt_ref and cnt_ambi
			if (max1_i != 0 && max2_i != 0) {
				for (j = 0; j < n; ++j) {
					int diff1 = score[j] - score[max1_i * n + j];
					int diff2 = score[j] - score[max2_i * n + j];
					if (diff1 > 0 && diff2 > 0) ++ret->cnt_ref;
					else if (diff1 == 0 || diff2 == 0) ++ret->cnt_ambi;
				}
			}
		}
		free(score); free(pscore); free(ref2); free(rs); free(inscns);
	}
	{ // call genotype
		int q[3], qr_indel = (int)(-4.343 * log(mi->r_indel) + 0.5);
		int min1, min2, min1_i;
		q[0] = ret->gl[0] + (ret->s[0][0] != '*'? 0 : 0) * qr_indel;
		q[1] = ret->gl[1] + (ret->s[1][0] != '*'? 0 : 0) * qr_indel;
		q[2] = n * 3 + (ret->s[0][0] == '*' || ret->s[1][0] == '*'? 1 : 1) * qr_indel;
		min1 = min2 = 0x7fffffff; min1_i = -1;
		for (i = 0; i < 3; ++i) {
			if (q[i] < min1) {
				min2 = min1; min1 = q[i]; min1_i = i;
			} else if (q[i] < min2) min2 = q[i];
		}
		ret->gt = min1_i;
		ret->q_cns = min2 - min1;
		// set q_ref
		if (ret->gt < 2) ret->q_ref = (ret->s[ret->gt][0] == '*')? 0 : q[1-ret->gt] - q[ret->gt] - qr_indel - 3;
		else ret->q_ref = (ret->s[0][0] == '*')? q[0] - q[2] : q[1] - q[2];
		if (ret->q_ref < 0) ret->q_ref = 0;
	}
	free(types);
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %r9d, %r15d
movq %r8, 0x58(%rsp)
movq %rdx, 0x78(%rsp)
movq %rsi, 0x38(%rsp)
movl %edi, %r13d
testl %r9d, %r9d
je 0x80a4
movq %rcx, 0x20(%rsp)
leal (%r15,%r13), %eax
incl %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3530
movq %rax, %rbx
movl $0x10000000, (%rax)     # imm = 0x10000000
movl %r13d, %ecx
testl %r13d, %r13d
movq %r13, 0x18(%rsp)
movq %rcx, 0x30(%rsp)
jle 0x80e5
leaq (,%rcx,8), %rax
leaq (%rax,%rax,2), %r14
movl $0x1, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x20(%rsp), %rax
movq (%rax,%r13), %rdi
movq 0x8(%rdi), %rsi
movabsq $0x400000000, %rcx      # imm = 0x400000000
testq %rcx, %rsi
jne 0x8080
movl 0xc(%rax,%r13), %eax
testl %eax, %eax
je 0x8080
addl $0x10000000, %eax       # imm = 0x10000000
movslq %r12d, %rcx
incl %r12d
movl %eax, (%rbx,%rcx,4)
movq 0x8(%rdi), %rsi
shrl $0x18, %esi
addq 0x30(%rdi), %rsi
callq 0x122aa
cmpl %ebp, %eax
cmovgl %eax, %ebp
addq $0x18, %r13
cmpq %r13, %r14
jne 0x8049
addl $0x2, %ebp
movq 0x18(%rsp), %r13
jmp 0x80f0
testl %r13d, %r13d
jle 0x8b08
movabsq $0x400000000, %r8       # imm = 0x400000000
movl %r13d, %edx
xorl %ebx, %ebx
movq %rcx, %rsi
xorl %eax, %eax
movq (%rsi), %rdi
testq %r8, 0x8(%rdi)
jne 0x80d4
cmpl $0x0, 0xc(%rsi)
jne 0x8b0a
incq %rax
addq $0x18, %rsi
cmpq %rax, %rdx
jne 0x80c1
jmp 0x8e6f
movl $0x2, %ebp
movl $0x1, %r12d
testl %r15d, %r15d
jle 0x8120
movq 0x160(%rsp), %rax
movl %r15d, %ecx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
testl %esi, %esi
je 0x8118
addl $0x10000000, %esi       # imm = 0x10000000
movslq %r12d, %rdi
incl %r12d
movl %esi, (%rbx,%rdi,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x8102
movslq %r12d, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x69e2
movl $0x1, %r14d
cmpl $0x2, %r15d
jl 0x815a
movl %r12d, %eax
movl $0x1, %ecx
movl (%rbx,%rcx,4), %edx
xorl %esi, %esi
cmpl -0x4(%rbx,%rcx,4), %edx
setne %sil
addl %esi, %r14d
incq %rcx
cmpq %rcx, %rax
jne 0x8142
movslq %r14d, %rdi
movl $0x4, %esi
movq %rdi, 0xb0(%rsp)
callq 0x3530
movl $0xf0000000, %r15d      # imm = 0xF0000000
addl (%rbx), %r15d
movq %rax, 0x28(%rsp)
movl %r15d, (%rax)
cmpl $0x2, %r12d
jl 0x81c0
movl %r12d, %eax
movl $0x1, %ecx
movl $0x1, %edx
movq 0x28(%rsp), %r8
movl (%rbx,%rdx,4), %esi
cmpl -0x4(%rbx,%rdx,4), %esi
je 0x81b0
addl $0xf0000000, %esi       # imm = 0xF0000000
movslq %ecx, %rdi
incl %ecx
movl %esi, (%r8,%rdi,4)
incq %rdx
cmpq %rdx, %rax
jne 0x8198
movq 0x28(%rsp), %rax
movl (%rax), %r15d
movq %rbx, %rdi
callq 0x32c0
movq 0x38(%rsp), %rdx
leal -0x32(%rdx), %eax
xorl %ecx, %ecx
cmpl $0x33, %edx
cmovgel %eax, %ecx
movl %ecx, 0x14(%rsp)
movl %r15d, %eax
sarl $0x1f, %eax
andl %r15d, %eax
movl %edx, %ecx
subl %eax, %ecx
addl $0x32, %ecx
movl %edx, %esi
cmpl %edx, %ecx
jle 0x8219
movslq 0x38(%rsp), %rdx
addq 0x58(%rsp), %rdx
negl %eax
addq $0x32, %rax
xorl %esi, %esi
cmpb $0x0, (%rdx,%rsi)
je 0x8215
incq %rsi
cmpl %esi, %eax
jne 0x8204
movl %ecx, %esi
jmp 0x8219
addl 0x38(%rsp), %esi
movq %rsi, 0x70(%rsp)
movq 0x28(%rsp), %rax
movq 0xb0(%rsp), %rcx
movslq -0x4(%rax,%rcx,4), %r15
testq %r15, %r15
movq %r15, 0x48(%rsp)
jle 0x843a
movl %r14d, %eax
imull %r15d, %eax
shll $0x2, %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3530
movq %rax, %r13
cmpl $0x2, %r14d
movl $0x1, %eax
cmovgel %r14d, %eax
movq %rax, 0x50(%rsp)
leal (,%r15,4), %eax
movl %eax, 0x98(%rsp)
xorl %edx, %edx
leaq 0x260de(%rip), %rsi     # 0x2e360
xorl %edi, %edi
movq 0x20(%rsp), %r10
cmpl $0x0, 0x18(%rsp)
setle %cl
movq 0x28(%rsp), %rax
movl (%rax,%rdi,4), %r8d
testl %r8d, %r8d
setle %r9b
orb %cl, %r9b
jne 0x8368
xorl %r9d, %r9d
leaq (%r9,%r9,2), %rcx
movq (%r10,%rcx,8), %r11
movq 0x8(%r11), %r10
movabsq $0x400000000, %rax      # imm = 0x400000000
testq %rax, %r10
jne 0x8355
movq 0x20(%rsp), %rax
leaq (%rax,%rcx,8), %rcx
movl 0xc(%rcx), %ebx
cmpl %r8d, %ebx
setne %r15b
testl %ebx, %ebx
setle %bl
orb %r15b, %bl
jne 0x8355
movq %r10, %rbx
shrq $0x30, %rbx
shlq $0x2, %rbx
addq 0x30(%r11), %rbx
shrl $0x18, %r10d
addq %rbx, %r10
movl 0x8(%rcx), %eax
incl %eax
movl %edx, %ebx
movl %r8d, %r15d
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
movl %ecx, %r12d
sarl %r12d
movslq %r12d, %r12
movzbl (%r10,%r12), %r12d
andl $0x3e, %ecx
movl %eax, %r11d
subl %ecx, %r11d
shll $0x2, %r11d
movb $0x4, %cl
subb %r11b, %cl
shrl %cl, %r12d
andl $0xf, %r12d
movsbl (%r12,%rsi), %ecx
cmpl $0x3, %ecx
jg 0x834b
addl %ebx, %ecx
movslq %ecx, %rcx
incl (%r13,%rcx,4)
incl %eax
addl $0x4, %ebx
decl %r15d
jne 0x8309
incq %r9
cmpq 0x30(%rsp), %r9
movq 0x20(%rsp), %r10
jne 0x82ad
incq %rdi
addl 0x98(%rsp), %edx
cmpq 0x50(%rsp), %rdi
jne 0x8289
movq 0x48(%rsp), %rbx
movl %ebx, %eax
imull %r14d, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x40(%rsp)
leaq (,%rbx,4), %rax
xorl %edx, %edx
movl $0xf, %esi
xorl %edi, %edi
movq 0x28(%rsp), %rcx
movslq (%rcx,%rdi,4), %r8
testq %r8, %r8
jle 0x8419
movl %edx, %r9d
shrl $0x2, %r9d
shlq $0x4, %r9
addq %r13, %r9
movq %rdi, %r10
imulq 0x48(%rsp), %r10
addq 0x40(%rsp), %r10
xorl %r11d, %r11d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
xorl %ebx, %ebx
movl (%r9,%r15,4), %r12d
cmpl %ebx, %r12d
cmovgl %r15d, %ecx
cmovgl %r12d, %ebx
incq %r15
cmpq $0x4, %r15
jne 0x83e2
movl $0x1, %r15d
shll %cl, %r15d
testl %ebx, %ebx
cmovel %esi, %r15d
movb %r15b, (%r10,%r11)
incq %r11
addq $0x10, %r9
cmpq %r8, %r11
jne 0x83d8
incq %rdi
addq %rax, %rdx
cmpq 0x50(%rsp), %rdi
jne 0x83ab
movq %r13, %rdi
callq 0x32c0
movq 0x18(%rsp), %r13
movq 0x48(%rsp), %r15
jmp 0x8455
cmpl $0x2, %r14d
movl $0x1, %eax
cmovgel %r14d, %eax
movq %rax, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x70(%rsp), %rbx
subl 0x14(%rsp), %ebx
leal (%rbx,%r15), %eax
addl $0x2, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, %r12
addl %ebx, %ebp
addl %r15d, %ebp
movq %r15, %rbx
movslq %ebp, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x80(%rsp)
imull %r13d, %r14d
movslq %r14d, %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x68(%rsp)
movl $0x4, %esi
movq %r15, %rdi
callq 0x3530
movq %rax, 0x60(%rsp)
movslq 0x14(%rsp), %rax
movq %r12, %rcx
subq %rax, %rcx
movq %rcx, 0x118(%rsp)
movq 0x38(%rsp), %rcx
cmpl $0x33, %ecx
movl $0x32, %eax
cmovgel %ecx, %eax
leal 0x2(,%rbx,2), %edx
movl %edx, 0xa0(%rsp)
movl %ecx, %esi
subl %eax, %esi
addl $0x33, %esi
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax), %rdi
addq $-0x32, %rdi
addq $-0x32, %rax
movq %rax, 0xf8(%rsp)
xorl %ebx, %ebx
leaq 0x266c9(%rip), %r14     # 0x2ebe0
movq 0x40(%rsp), %r15
movq 0x30(%rsp), %r9
movq 0x20(%rsp), %r10
movq %r12, 0x88(%rsp)
movq %rsi, 0x108(%rsp)
movq %rdi, 0x100(%rsp)
leaq 0x26623(%rip), %rax     # 0x2eb68
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
movapd %xmm1, 0xe0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movl 0xa0(%rsp), %eax
movl %eax, 0xec(%rsp)
movl $0x0, %ecx
movl 0x14(%rsp), %edx
movl %edx, %eax
cmpl 0x38(%rsp), %edx
movq 0x70(%rsp), %r11
jg 0x85af
xorl %eax, %eax
leaq 0x25dd3(%rip), %rdx     # 0x2e360
movsbq (%rdi,%rax), %rcx
movzbl (%r14,%rcx), %ecx
movb (%rcx,%rdx), %cl
movb %cl, (%r12,%rax)
incq %rax
cmpq %rax, %rsi
jne 0x858d
addl 0xf8(%rsp), %eax
movl %esi, %ecx
movq 0x28(%rsp), %rdx
movslq (%rdx,%rbx,4), %rdx
testq %rdx, %rdx
movq %rdx, 0xc8(%rsp)
jle 0x85f2
movl %ecx, %ecx
leaq (%r12,%rcx), %rsi
xorl %edx, %edx
leaq 0x25d8c(%rip), %r8      # 0x2e360
movsbq (%r15,%rdx), %rdi
movb (%rdi,%r8), %dil
movb %dil, (%rsi,%rdx)
incq %rdx
cmpq %rdx, 0xc8(%rsp)
jne 0x85d4
addl %edx, %ecx
jmp 0x85f4
subl %edx, %eax
movq %r15, 0x110(%rsp)
cmpl %r11d, %eax
movq %rbx, 0xb8(%rsp)
jge 0x864f
movslq %eax, %rdi
movslq %r11d, %rdx
movslq %ecx, %rcx
addq %r12, %rcx
movq 0x58(%rsp), %rsi
addq %rdi, %rsi
subq %rdi, %rdx
xorl %edi, %edi
movsbq (%rsi,%rdi), %r8
testq %r8, %r8
je 0x864d
movzbl (%r14,%r8), %r8d
leaq 0x25d28(%rip), %r15     # 0x2e360
movb (%r8,%r15), %r8b
movb %r8b, (%rcx,%rdi)
incq %rdi
cmpq %rdi, %rdx
jne 0x8622
movl %r11d, %eax
jmp 0x864f
addl %edi, %eax
cmpl %r11d, %eax
cmovll %eax, %r11d
movq %r11, 0x70(%rsp)
testl %r13d, %r13d
jle 0x896a
movq 0xb8(%rsp), %rax
imull 0x18(%rsp), %eax
movq %rax, 0xc0(%rsp)
xorl %edx, %edx
leaq (%rdx,%rdx,2), %r14
movq (%r10,%r14,8), %r15
movq 0x8(%r15), %r13
movabsq $0x400000000, %rax      # imm = 0x400000000
testq %rax, %r13
jne 0x895e
movq %rdx, 0x90(%rsp)
shrl $0x18, %r13d
addq 0x30(%r15), %r13
movq %r15, %rdi
movq %r13, %rsi
movl 0x14(%rsp), %ebx
movl %ebx, %edx
xorl %ecx, %ecx
leaq 0xac(%rsp), %r8
callq 0x7f1f
movl %eax, %r12d
movq %r15, %rdi
movq %r13, %rsi
movq 0x70(%rsp), %rdx
movl $0x1, %ecx
leaq 0xa8(%rsp), %r8
callq 0x7f1f
movslq 0xac(%rsp), %rcx
cmpl %ebx, %ecx
jl 0x8e84
movq %rcx, %r13
movl %eax, %r8d
subl %r12d, %r8d
movq 0x80(%rsp), %rdx
leaq 0x25c53(%rip), %rbx     # 0x2e360
jle 0x8776
movslq %r12d, %rcx
cltq
subq %rcx, %rax
movl %r12d, %r11d
xorl %esi, %esi
movq 0x8(%r15), %rcx
movq %rcx, %rdi
shrq $0x30, %rdi
shlq $0x2, %rdi
addq 0x30(%r15), %rdi
shrl $0x18, %ecx
addq %rdi, %rcx
leal (%r11,%rsi), %edi
movl %edi, %r9d
shrl $0x1f, %r9d
addl %edi, %r9d
movl %r9d, %r10d
sarl %r10d
movslq %r10d, %r10
movzbl (%r10,%rcx), %r10d
andl $0x3e, %r9d
subl %r9d, %edi
shll $0x2, %edi
movb $0x4, %cl
subb %dil, %cl
shrl %cl, %r10d
andl $0xf, %r10d
movb (%r10,%rbx), %cl
movb %cl, (%rdx,%rsi)
incq %rsi
cmpq %rsi, %rax
jne 0x871c
movl 0xa8(%rsp), %esi
movq %r13, %r15
subl %r15d, %esi
addl 0xc8(%rsp), %esi
jle 0x88fd
movq 0x118(%rsp), %rax
leaq (%rax,%r15), %rdi
movq 0xc0(%rsp), %rax
movq 0x90(%rsp), %rcx
addq %rax, %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x120(%rsp)
leaq (%rax,%rcx,4), %r9
leaq 0xa4(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %ecx
leaq 0xd0(%rsp), %r8
callq 0xea2c
movslq 0xa4(%rsp), %rcx
testq %rcx, %rcx
jle 0x892a
movq 0x20(%rsp), %rdx
leaq (%rdx,%r14,8), %rdx
subl 0x14(%rsp), %r15d
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
leaq 0x1ad1f(%rip), %rbx     # 0x23528
movl (%rax,%rdi,4), %r10d
movl %r10d, %r11d
andl $0xf, %r11d
cmpl $0x4, %r11d
ja 0x88ef
movl %r10d, %r9d
shrl $0x4, %r9d
movslq (%rbx,%r11,4), %r11
addq %rbx, %r11
jmpq *%r11
cmpl $0x10, %r10d
movq %r15, 0x98(%rsp)
jb 0x88af
movslq %r15d, %r10
movslq %r8d, %r11
addq 0x88(%rsp), %r10
movq 0x80(%rsp), %rbx
leaq (%rbx,%r11), %r14
xorl %r12d, %r12d
movb (%r10,%r12), %r15b
cmpb (%r14,%r12), %r15b
je 0x88a7
movq (%rdx), %r15
movq 0x8(%r15), %rbp
movq %rbp, %rbx
shrq $0x30, %rbx
shlq $0x2, %rbx
addq 0x30(%r15), %rbx
shrl $0x18, %ebp
movl 0x10(%r15), %r13d
movl %r13d, %r15d
incl %r15d
shrl $0x1f, %r15d
addl %r13d, %r15d
incl %r15d
sarl %r15d
movslq %r15d, %r15
addq %rbp, %r15
addq %r11, %r15
addq %rbx, %r15
movzbl (%r12,%r15), %ebx
addl %ebx, %esi
incq %r12
cmpq %r12, %r9
jne 0x885a
movq 0x98(%rsp), %r15
addl %r9d, %r15d
addl %r9d, %r8d
leaq 0x1ac64(%rip), %rbx     # 0x23528
jmp 0x88ef
movq 0x78(%rsp), %r10
movl (%r10), %r10d
imull %r9d, %r10d
addl %r10d, %esi
addl %r8d, %r9d
movl %r9d, %r8d
jmp 0x88ef
movq 0x78(%rsp), %r10
movl (%r10), %r10d
imull %r9d, %r10d
addl %r10d, %esi
addl %r9d, %r15d
incq %rdi
cmpq %rcx, %rdi
jne 0x8809
jmp 0x892c
movq 0xc0(%rsp), %rax
movq 0x90(%rsp), %rdx
addq %rdx, %rax
movq 0x68(%rsp), %rcx
movl $0xfff00000, (%rcx,%rax,4) # imm = 0xFFF00000
movq 0x60(%rsp), %rcx
movl $0x100000, (%rcx,%rax,4) # imm = 0x100000
jmp 0x894c
xorl %esi, %esi
movq 0x60(%rsp), %rcx
movq 0x120(%rsp), %rdx
movl %esi, (%rcx,%rdx,4)
movq %rax, %rdi
callq 0x32c0
movq 0x90(%rsp), %rdx
movq 0x30(%rsp), %r9
movq 0x20(%rsp), %r10
movq 0x88(%rsp), %r12
incq %rdx
cmpq %r9, %rdx
jne 0x867b
movq 0xb8(%rsp), %rbx
incq %rbx
movq 0x110(%rsp), %r15
addq 0x48(%rsp), %r15
cmpq 0x50(%rsp), %rbx
movq 0x18(%rsp), %r13
movq 0x108(%rsp), %rsi
movq 0x100(%rsp), %rdi
leaq 0x2623d(%rip), %r14     # 0x2ebe0
jne 0x853e
movl $0x4, %esi
movq 0xb0(%rsp), %rdi
callq 0x3530
movq 0x30(%rsp), %r9
leaq (,%r9,4), %rcx
xorl %edx, %edx
movq 0x60(%rsp), %rsi
testl %r13d, %r13d
jle 0x89e9
movl (%rax,%rdx,4), %edi
xorl %r8d, %r8d
subl (%rsi,%r8,4), %edi
incq %r8
cmpq %r8, %r9
jne 0x89da
movl %edi, (%rax,%rdx,4)
incq %rdx
addq %rcx, %rsi
cmpq 0x50(%rsp), %rdx
jne 0x89cf
movl $0x80000001, %esi       # imm = 0x80000001
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x80000001, %edi       # imm = 0x80000001
movl (%rax,%rcx,4), %r8d
cmpl %edi, %r8d
jle 0x8a25
movl %ecx, %r12d
movl %edx, %r14d
movl %ecx, %edx
movl %edi, %esi
movl %r8d, %edi
jmp 0x8a33
cmpl %esi, %r8d
cmovgl %r8d, %esi
cmovgl %ecx, %r14d
movl %edx, %r12d
incq %rcx
cmpq %rcx, 0x50(%rsp)
jne 0x8a0d
movq %rax, %rdi
callq 0x32c0
movl $0x1, %edi
movl $0x48, %esi
callq 0x3530
movq %rax, %rbx
movslq %r12d, %rax
movq 0x28(%rsp), %rcx
movslq (%rcx,%rax,4), %r13
movl %r13d, (%rbx)
movslq %r14d, %rax
movl (%rcx,%rax,4), %ebp
movl %ebp, 0x4(%rbx)
movl %r13d, %edi
negl %edi
cmovsl %r13d, %edi
addl $0x2, %edi
movl $0x1, %esi
callq 0x3530
movq %rax, %r15
movq %rax, 0x20(%rbx)
movl %ebp, %edi
negl %edi
cmovsl %ebp, %edi
addl $0x2, %edi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x28(%rbx)
testq %r13, %r13
jle 0x8aee
movb $0x2b, (%r15)
movl %r12d, %ecx
imull 0x48(%rsp), %ecx
movslq %ecx, %rcx
leaq 0x26421(%rip), %rdx     # 0x2eee0
movq (%rdx), %rdx
movq 0x40(%rsp), %r10
addq %r10, %rcx
xorl %esi, %esi
movq 0x30(%rsp), %r8
movq 0x20(%rsp), %r9
movsbq (%rcx,%rsi), %rdi
movb (%rdx,%rdi), %dil
movb %dil, 0x1(%r15,%rsi)
incq %rsi
cmpq %rsi, %r13
jne 0x8ad6
jmp 0x8b5b
testl %r13d, %r13d
movq 0x20(%rsp), %r9
movq 0x40(%rsp), %r10
js 0x8b1a
movb $0x2a, (%r15)
movq 0x30(%rsp), %r8
jmp 0x8b5b
xorl %eax, %eax
cmpl %r13d, %eax
jne 0x7ffb
xorl %ebx, %ebx
jmp 0x8e6f
movb $0x2d, (%r15)
movl %r13d, %edx
negl %edx
movslq 0x38(%rsp), %rsi
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
incq %rdx
xorl %esi, %esi
movq 0x30(%rsp), %r8
movb (%rdx,%rsi), %dil
testb %dil, %dil
je 0x8b5b
movb %dil, 0x1(%r15,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x8b45
testl %ebp, %ebp
jle 0x8b95
movb $0x2b, (%rax)
leaq 0x26377(%rip), %rcx     # 0x2eee0
movq (%rcx), %rcx
movq 0x48(%rsp), %rdx
imull %r14d, %edx
movslq %edx, %rdx
addq %r10, %rdx
xorl %esi, %esi
movsbq (%rdx,%rsi), %rdi
movb (%rcx,%rdi), %dil
movb %dil, 0x1(%rax,%rsi)
incq %rsi
cmpq %rsi, %rbp
jne 0x8b7d
jmp 0x8bd8
testl %ebp, %ebp
js 0x8b9e
movb $0x2a, (%rax)
jmp 0x8bd8
movb $0x2d, (%rax)
movl %ebp, %edx
negl %edx
movslq 0x38(%rsp), %rsi
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
incq %rdx
xorl %esi, %esi
movb (%rdx,%rsi), %dil
testb %dil, %dil
je 0x8bd8
movb %dil, 0x1(%rax,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x8bc2
cmpl $0x0, 0x18(%rsp)
jle 0x8c1e
leaq (,%r8,8), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
movl 0xc(%r9,%rcx), %r8d
cmpl %r13d, %r8d
jne 0x8c04
incl %edx
movl %edx, 0x8(%rbx)
jmp 0x8c15
cmpl %ebp, %r8d
jne 0x8c10
incl %esi
movl %esi, 0xc(%rbx)
jmp 0x8c15
incl %edi
movl %edi, 0x10(%rbx)
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x8bf3
movl %r12d, %ecx
subl %r14d, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
incl %eax
movsd 0x1a89b(%rip), %xmm0    # 0x234d0
movsd 0x1a8cb(%rip), %xmm1    # 0x23508
mulsd %xmm1, %xmm0
decl %eax
jne 0x8c3d
movq 0x78(%rsp), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
movq $0x0, 0x34(%rbx)
movq 0x18(%rsp), %rsi
testl %esi, %esi
jle 0x8d51
movsd 0x1a862(%rip), %xmm2    # 0x234d0
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
divsd 0x1a892(%rip), %xmm2    # 0x23510
cvttsd2si %xmm2, %edx
movl %r12d, %eax
imull %esi, %eax
movl %r14d, %ecx
imull %esi, %ecx
cltq
movslq %ecx, %rcx
movq 0x60(%rsp), %rdi
leaq (%rdi,%rax,4), %rsi
leaq (%rdi,%rcx,4), %rdi
xorl %r13d, %r13d
xorl %ebp, %ebp
xorl %r8d, %r8d
movl (%rsi,%r8,4), %r11d
movl (%rdi,%r8,4), %r9d
movl %r11d, %r10d
subl %r9d, %r10d
jle 0x8cc8
cmpl %edx, %r10d
cmovgel %edx, %r10d
addl %r10d, %r13d
movl %r13d, 0x34(%rbx)
jmp 0x8cd8
subl %r11d, %r9d
cmpl %edx, %r9d
cmovgel %edx, %r9d
addl %r9d, %ebp
movl %ebp, 0x38(%rbx)
incq %r8
movq 0x30(%rsp), %r11
cmpq %r8, %r11
jne 0x8ca8
cmpl $0x0, 0x18(%rsp)
setle %dl
testl %r12d, %r12d
sete %sil
testl %r14d, %r14d
sete %dil
orb %sil, %dil
orb %dl, %dil
jne 0x8d56
movq 0x68(%rsp), %rdx
leaq (%rdx,%rax,4), %rax
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
xorl %esi, %esi
xorl %edi, %edi
movq 0x68(%rsp), %r8
movl (%r8,%rdi,4), %r8d
movl (%rax,%rdi,4), %r10d
movl (%rcx,%rdi,4), %r9d
cmpl %r10d, %r8d
jle 0x8d38
cmpl %r9d, %r8d
jle 0x8d38
incl %edx
movl %edx, 0x14(%rbx)
jmp 0x8d47
cmpl %r10d, %r8d
je 0x8d42
cmpl %r9d, %r8d
jne 0x8d47
incl %esi
movl %esi, 0x18(%rbx)
incq %rdi
cmpq %rdi, %r11
jne 0x8d16
jmp 0x8d56
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x68(%rsp), %rdi
callq 0x32c0
movq 0x60(%rsp), %rdi
callq 0x32c0
movq 0x88(%rsp), %rdi
callq 0x32c0
movq 0x80(%rsp), %rdi
callq 0x32c0
movq 0x40(%rsp), %rdi
callq 0x32c0
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rax), %xmm0
callq 0x32a0
mulsd 0x1a740(%rip), %xmm0    # 0x234e8
addsd 0x1a748(%rip), %xmm0    # 0x234f8
cvttsd2si %xmm0, %eax
movl %r13d, 0xd0(%rsp)
movl %ebp, 0xd4(%rsp)
movq 0x18(%rsp), %rcx
leal (%rcx,%rcx,2), %ecx
movb (%r15), %sil
addl %eax, %ecx
movl %ecx, 0xd8(%rsp)
movl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl %r9d, %r10d
movl 0xd0(%rsp,%r8,4), %r9d
cmpl %edi, %r9d
cmovll %r9d, %edi
cmpl %r10d, %r9d
cmovgel %r10d, %r9d
cmovll %r10d, %edi
cmovll %r8d, %edx
incq %r8
cmpq $0x3, %r8
jne 0x8dea
movl %edx, 0x30(%rbx)
subl %r9d, %edi
movl %edi, 0x3c(%rbx)
cmpl $0x1, %edx
jg 0x8e4d
movslq %edx, %rcx
movq 0x20(%rbx,%rcx,8), %rsi
xorl %ebp, %ebp
cmpb $0x2a, (%rsi)
je 0x8e57
movl $0x1, %esi
subl %edx, %esi
movl 0xd0(%rsp,%rsi,4), %ebp
addl 0xd0(%rsp,%rcx,4), %eax
subl %eax, %ebp
addl $-0x3, %ebp
jmp 0x8e57
cmpb $0x2a, %sil
cmovel %r13d, %ebp
subl %ecx, %ebp
movl %ebp, 0x40(%rbx)
testl %ebp, %ebp
jns 0x8e65
movl $0x0, 0x40(%rbx)
movq 0x28(%rsp), %rdi
callq 0x32c0
movq %rbx, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a6b1(%rip), %rdi     # 0x2353c
leaq 0x1a6b7(%rip), %rsi     # 0x23549
leaq 0x1a6bd(%rip), %rcx     # 0x23556
movl $0x1d1, %edx            # imm = 0x1D1
callq 0x3140
nop