// File: /workspace/github_cpp_makefile_star2_O1/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, 0x50(%rsp)
movq %rdx, 0x78(%rsp)
movq %rsi, 0x38(%rsp)
movl %edi, %r12d
movl %edi, %esi
testl %r9d, %r9d
jne 0x7dc1
xorl %eax, %eax
testl %r12d, %r12d
jle 0x7db5
movq %rcx, %rdi
movabsq $0x400000000, %r8       # imm = 0x400000000
movq (%rdi), %rdx
testq %r8, 0x8(%rdx)
jne 0x7da7
cmpl $0x0, 0xc(%rdi)
jne 0x7db5
incq %rax
addq $0x18, %rdi
cmpq %rax, %rsi
jne 0x7d98
movl %esi, %eax
cmpl %r12d, %eax
jne 0x7dc1
xorl %ebx, %ebx
jmp 0x8be6
movq %rcx, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
leal (%r12,%r15), %eax
incl %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x3530
movq %rax, %rbx
movl $0x10000000, (%rax)     # imm = 0x10000000
testl %r12d, %r12d
movq %r12, 0x40(%rsp)
jle 0x7e62
movq 0x30(%rsp), %rax
leaq (,%rax,8), %rax
leaq (%rax,%rax,2), %r12
movl $0x1, %r14d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x18(%rsp), %rax
movq (%rax,%r13), %rdi
movabsq $0x400000000, %rcx      # imm = 0x400000000
testq %rcx, 0x8(%rdi)
jne 0x7e3d
movl 0xc(%rax,%r13), %eax
testl %eax, %eax
je 0x7e3d
addl $0x10000000, %eax       # imm = 0x10000000
movslq %r14d, %rcx
incl %r14d
movl %eax, (%rbx,%rcx,4)
movzbl 0xb(%rdi), %esi
addq 0x30(%rdi), %rsi
callq 0x11c4a
cmpl %ebp, %eax
cmovgl %eax, %ebp
addq $0x18, %r13
cmpq %r13, %r12
jne 0x7e0d
addl $0x2, %ebp
movq 0x40(%rsp), %r12
jmp 0x7e6d
movl $0x2, %ebp
movl $0x1, %r14d
testl %r15d, %r15d
jle 0x7e9d
movq 0x160(%rsp), %rax
movl %r15d, %ecx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
testl %esi, %esi
je 0x7e95
addl $0x10000000, %esi       # imm = 0x10000000
movslq %r14d, %rdi
incl %r14d
movl %esi, (%rbx,%rdi,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x7e7f
movslq %r14d, %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x672c
movl $0x1, %r13d
cmpl $0x2, %r15d
jl 0x7edd
movl %r14d, %eax
movl $0x1, %r13d
movl $0x1, %ecx
movl (%rbx,%rcx,4), %edx
xorl %esi, %esi
cmpl -0x4(%rbx,%rcx,4), %edx
setne %sil
addl %esi, %r13d
incq %rcx
cmpq %rcx, %rax
jne 0x7ec5
movslq %r13d, %rdi
movl $0x4, %esi
movq %rdi, 0xb8(%rsp)
callq 0x3530
movl $0xf0000000, %ecx       # imm = 0xF0000000
addl (%rbx), %ecx
movq %rax, 0x28(%rsp)
movl %ecx, (%rax)
cmpl $0x2, %r14d
jl 0x7f38
movl %r14d, %eax
movl $0x1, %ecx
movl $0x1, %edx
movq 0x28(%rsp), %r8
movl (%rbx,%rdx,4), %esi
cmpl -0x4(%rbx,%rdx,4), %esi
je 0x7f30
addl $0xf0000000, %esi       # imm = 0xF0000000
movslq %ecx, %rdi
incl %ecx
movl %esi, (%r8,%rdi,4)
incq %rdx
cmpq %rdx, %rax
jne 0x7f18
movq %rbx, %rdi
callq 0x32c0
movq 0x38(%rsp), %rdx
leal -0x32(%rdx), %eax
xorl %ecx, %ecx
cmpl $0x33, %edx
cmovgel %eax, %ecx
movl %ecx, 0x24(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %ecx
movl %ecx, %eax
sarl $0x1f, %eax
andl %ecx, %eax
movl %edx, %ecx
subl %eax, %ecx
addl $0x32, %ecx
movl %edx, %ebx
cmpl %edx, %ecx
jle 0x7f96
movslq 0x38(%rsp), %rdx
addq 0x50(%rsp), %rdx
negl %eax
addq $0x32, %rax
xorl %ebx, %ebx
cmpb $0x0, (%rdx,%rbx)
je 0x7f92
incq %rbx
cmpl %ebx, %eax
jne 0x7f81
movl %ecx, %ebx
jmp 0x7f96
addl 0x38(%rsp), %ebx
movq 0x28(%rsp), %rax
movq 0xb8(%rsp), %rcx
movslq -0x4(%rax,%rcx,4), %rcx
movq $0x0, 0x10(%rsp)
movl %ecx, %eax
movq %rax, 0x48(%rsp)
testq %rcx, %rcx
movq %rcx, 0x80(%rsp)
movq %rbx, 0x70(%rsp)
jle 0x81d5
movl %r13d, %eax
imull %ecx, %eax
shll $0x2, %eax
movslq %eax, %rdi
movl $0x4, %esi
movq %rcx, %r14
callq 0x3530
cmpl $0x2, %r13d
movl $0x1, %ebx
movq %r13, 0x68(%rsp)
cmovgel %r13d, %ebx
movq %rax, %r15
leal (,%r14,4), %eax
leaq 0x27355(%rip), %rdx     # 0x2f360
xorl %esi, %esi
movq 0x18(%rsp), %r9
cmpl $0x0, 0x40(%rsp)
setle %cl
movq 0x28(%rsp), %rdi
movl (%rdi,%rsi,4), %edi
testl %edi, %edi
setle %r8b
orb %cl, %r8b
jne 0x80fb
xorl %r8d, %r8d
leaq (%r8,%r8,2), %rcx
movq (%r9,%rcx,8), %r11
movq 0x8(%r11), %r9
movabsq $0x400000000, %r10      # imm = 0x400000000
testq %r10, %r9
jne 0x80e8
movq 0x18(%rsp), %r10
leaq (%r10,%rcx,8), %rcx
movl 0xc(%rcx), %r10d
cmpl %edi, %r10d
setne %r14b
testl %r10d, %r10d
setle %r12b
orb %r14b, %r12b
jne 0x80e8
movq %r9, %r14
shrq $0x30, %r14
shlq $0x2, %r14
addq 0x30(%r11), %r14
shrl $0x18, %r9d
addq %r14, %r9
movl 0x8(%rcx), %r11d
incl %r11d
movq 0x10(%rsp), %rcx
movl %ecx, %r14d
movl %r11d, %ecx
shrl $0x1f, %ecx
addl %r11d, %ecx
movl %ecx, %r12d
sarl %r12d
movslq %r12d, %r12
movzbl (%r9,%r12), %r12d
andl $0x3e, %ecx
movl %r11d, %r13d
subl %ecx, %r13d
shll $0x2, %r13d
movb $0x4, %cl
subb %r13b, %cl
shrl %cl, %r12d
andl $0xf, %r12d
movsbl (%r12,%rdx), %ecx
cmpl $0x3, %ecx
jg 0x80dc
addl %r14d, %ecx
movslq %ecx, %rcx
incl (%r15,%rcx,4)
incl %r11d
addl $0x4, %r14d
decl %r10d
jne 0x8098
incq %r8
cmpq 0x30(%rsp), %r8
movq 0x18(%rsp), %r9
jne 0x8034
incq %rsi
movq 0x10(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x10(%rsp)
cmpq %rbx, %rsi
jne 0x8012
movq 0x48(%rsp), %r14
movl %r14d, %eax
imull 0x68(%rsp), %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x10(%rsp)
leaq (,%r14,4), %rax
xorl %edx, %edx
movl $0xf, %esi
xorl %edi, %edi
movq 0x28(%rsp), %rcx
movslq (%rcx,%rdi,4), %r8
testq %r8, %r8
jle 0x81b3
movl %edx, %r9d
shrl $0x2, %r9d
shlq $0x4, %r9
addq %r15, %r9
movq %rdi, %r10
imulq 0x48(%rsp), %r10
addq 0x10(%rsp), %r10
xorl %r11d, %r11d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %r14d, %r14d
movl (%r9,%r12,4), %r13d
cmpl %r14d, %r13d
cmovgl %r12d, %ecx
cmovgl %r13d, %r14d
incq %r12
cmpq $0x4, %r12
jne 0x817b
movl $0x1, %r12d
shll %cl, %r12d
testl %r14d, %r14d
cmovel %esi, %r12d
movb %r12b, (%r10,%r11)
incq %r11
addq $0x10, %r9
cmpq %r8, %r11
jne 0x8170
incq %rdi
addq %rax, %rdx
cmpq %rbx, %rdi
jne 0x8143
movq %r15, %rdi
callq 0x32c0
movq 0x40(%rsp), %r12
movq 0x68(%rsp), %r13
movq 0x70(%rsp), %rbx
movl 0x24(%rsp), %r15d
subl %r15d, %ebx
movq 0x48(%rsp), %rax
addl %ebx, %eax
addl $0x2, %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, %r14
addl %ebx, %ebp
addl 0x80(%rsp), %ebp
movslq %ebp, %rdi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x90(%rsp)
movl %r13d, %eax
imull %r12d, %eax
movslq %eax, %rbx
movl $0x4, %esi
movq %rbx, %rdi
callq 0x3530
movq %rax, 0x60(%rsp)
movl $0x4, %esi
movq %rbx, %rdi
callq 0x3530
movq %rax, 0x58(%rsp)
movslq %r15d, %rax
movq %r14, %rcx
subq %rax, %rcx
movq %rcx, 0x108(%rsp)
movq 0x38(%rsp), %rcx
cmpl $0x33, %ecx
movl $0x32, %eax
cmovgel %ecx, %eax
movq 0x48(%rsp), %rdx
leal 0x2(,%rdx,2), %edx
movl %edx, 0xa8(%rsp)
subl %eax, %ecx
addl $0x33, %ecx
movq %rcx, 0x100(%rsp)
cmpl $0x2, %r13d
movl $0x1, %ecx
cmovll %ecx, %r13d
movq %r13, 0x68(%rsp)
leaq -0x32(%rax), %rcx
movq %rcx, 0xf8(%rsp)
movq 0x50(%rsp), %rcx
addq %rcx, %rax
addq $-0x32, %rax
movq %rax, 0xf0(%rsp)
xorl %r15d, %r15d
leaq 0x27920(%rip), %r13     # 0x2fbe0
leaq 0x27099(%rip), %rbp     # 0x2f360
movq 0x10(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq %r14, 0x98(%rsp)
leaq 0x2787b(%rip), %rax     # 0x2fb68
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movl 0xa8(%rsp), %eax
movl %eax, 0xec(%rsp)
movl $0x0, %ecx
movl 0x24(%rsp), %edx
movl %edx, %eax
cmpl 0x38(%rsp), %edx
movq 0x70(%rsp), %r11
movq 0x88(%rsp), %r8
jg 0x8366
xorl %ecx, %ecx
movq 0x100(%rsp), %rdx
movq 0xf0(%rsp), %rsi
movsbq (%rsi,%rcx), %rax
movzbl (%r13,%rax), %eax
movb (%rax,%rbp), %al
movb %al, (%r14,%rcx)
incq %rcx
cmpq %rcx, %rdx
jne 0x8342
movq 0xf8(%rsp), %rax
addl %ecx, %eax
movq 0x28(%rsp), %rdx
movslq (%rdx,%r15,4), %rbx
testq %rbx, %rbx
jle 0x8395
movl %ecx, %ecx
leaq (%r14,%rcx), %rsi
xorl %edx, %edx
movsbq (%r8,%rdx), %rdi
movb (%rdi,%rbp), %dil
movb %dil, (%rsi,%rdx)
incq %rdx
cmpq %rdx, %rbx
jne 0x837c
addl %edx, %ecx
jmp 0x8397
subl %ebx, %eax
cmpl %r11d, %eax
movq %r15, 0xc0(%rsp)
jge 0x83e4
movslq %eax, %rdi
movslq %r11d, %rdx
movslq %ecx, %rcx
addq %r14, %rcx
movq 0x50(%rsp), %rsi
addq %rdi, %rsi
subq %rdi, %rdx
xorl %edi, %edi
movsbq (%rsi,%rdi), %r8
testq %r8, %r8
je 0x83e2
movzbl (%r13,%r8), %r8d
movb (%r8,%rbp), %r8b
movb %r8b, (%rcx,%rdi)
incq %rdi
cmpq %rdi, %rdx
jne 0x83bd
movl %r11d, %eax
jmp 0x83e4
addl %edi, %eax
movq %rbx, 0x110(%rsp)
cmpl %r11d, %eax
cmovll %eax, %r11d
movq %r11, 0x70(%rsp)
testl %r12d, %r12d
jle 0x8704
movq 0xc0(%rsp), %rax
imull 0x40(%rsp), %eax
movq %rax, 0xc8(%rsp)
xorl %edx, %edx
leaq (%rdx,%rdx,2), %r13
movq (%r10,%r13,8), %rbx
movq 0x8(%rbx), %rbp
movabsq $0x400000000, %rax      # imm = 0x400000000
testq %rax, %rbp
jne 0x86f8
movq %rdx, 0xa0(%rsp)
shrl $0x18, %ebp
addq 0x30(%rbx), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
movl 0x24(%rsp), %r14d
movl %r14d, %edx
xorl %ecx, %ecx
leaq 0xb4(%rsp), %r8
callq 0x7c93
movl %eax, %r12d
movq %rbx, %rdi
movq %rbp, %rsi
movq 0x70(%rsp), %rdx
movl $0x1, %ecx
leaq 0xb0(%rsp), %r8
callq 0x7c93
movslq 0xb4(%rsp), %rcx
cmpl %r14d, %ecx
jl 0x8bfb
movq %rcx, %r15
movl %eax, %r8d
subl %r12d, %r8d
movq 0x90(%rsp), %rdx
leaq 0x26eb4(%rip), %r14     # 0x2f360
jle 0x8515
movslq %r12d, %rcx
cltq
subq %rcx, %rax
movl %r12d, %r11d
xorl %esi, %esi
movq 0x8(%rbx), %rcx
movq %rcx, %rdi
shrq $0x30, %rdi
shlq $0x2, %rdi
addq 0x30(%rbx), %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,%r14), %cl
movb %cl, (%rdx,%rsi)
incq %rsi
cmpq %rsi, %rax
jne 0x84bb
movl 0xb0(%rsp), %esi
movq %r15, %r14
subl %r14d, %esi
addl 0x110(%rsp), %esi
jle 0x8697
movq 0x108(%rsp), %rax
leaq (%rax,%r14), %rdi
movq 0xc8(%rsp), %rax
movq 0xa0(%rsp), %rcx
addq %rax, %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0x118(%rsp)
leaq (%rax,%rcx,4), %r9
leaq 0xac(%rsp), %rax
movq %rax, (%rsp)
movl %r8d, %ecx
leaq 0xd0(%rsp), %r8
callq 0xe468
movslq 0xac(%rsp), %rcx
testq %rcx, %rcx
jle 0x86c4
movq 0x18(%rsp), %rdx
leaq (%rdx,%r13,8), %rdx
subl 0x24(%rsp), %r14d
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
leaq 0x1bf28(%rip), %rbx     # 0x244d0
movl (%rax,%rdi,4), %r10d
movl %r10d, %r11d
andl $0xf, %r11d
cmpl $0x4, %r11d
ja 0x8689
movl %r10d, %r9d
shrl $0x4, %r9d
movslq (%rbx,%r11,4), %r11
addq %rbx, %r11
jmpq *%r11
cmpl $0x10, %r10d
movq %r14, 0x120(%rsp)
jb 0x8649
movslq %r14d, %r10
movslq %r8d, %r11
addq 0x98(%rsp), %r10
movq 0x90(%rsp), %rbx
leaq (%rbx,%r11), %r12
xorl %r13d, %r13d
movb (%r10,%r13), %bl
cmpb (%r12,%r13), %bl
je 0x8641
movq (%rdx), %rbx
movq 0x8(%rbx), %r15
movq %r15, %r14
shrq $0x30, %r14
shlq $0x2, %r14
addq 0x30(%rbx), %r14
shrl $0x18, %r15d
movl 0x10(%rbx), %ebp
movl %ebp, %ebx
incl %ebx
shrl $0x1f, %ebx
addl %ebp, %ebx
incl %ebx
sarl %ebx
movslq %ebx, %rbx
addq %r15, %rbx
addq %r11, %rbx
addq %r14, %rbx
movzbl (%r13,%rbx), %ebx
addl %ebx, %esi
incq %r13
cmpq %r13, %r9
jne 0x85f9
movq 0x120(%rsp), %r14
addl %r9d, %r14d
addl %r9d, %r8d
leaq 0x1be72(%rip), %rbx     # 0x244d0
jmp 0x8689
movq 0x78(%rsp), %r10
movl (%r10), %r10d
imull %r9d, %r10d
addl %r10d, %esi
addl %r8d, %r9d
movl %r9d, %r8d
jmp 0x8689
movq 0x78(%rsp), %r10
movl (%r10), %r10d
imull %r9d, %r10d
addl %r10d, %esi
addl %r9d, %r14d
incq %rdi
cmpq %rcx, %rdi
jne 0x85a8
jmp 0x86c6
movq 0xc8(%rsp), %rax
movq 0xa0(%rsp), %rdx
addq %rdx, %rax
movq 0x60(%rsp), %rcx
movl $0xfff00000, (%rcx,%rax,4) # imm = 0xFFF00000
movq 0x58(%rsp), %rcx
movl $0x100000, (%rcx,%rax,4) # imm = 0x100000
jmp 0x86e6
xorl %esi, %esi
movq 0x58(%rsp), %rcx
movq 0x118(%rsp), %rdx
movl %esi, (%rcx,%rdx,4)
movq %rax, %rdi
callq 0x32c0
movq 0xa0(%rsp), %rdx
movq 0x30(%rsp), %r9
movq 0x18(%rsp), %r10
movq 0x98(%rsp), %r14
incq %rdx
cmpq %r9, %rdx
jne 0x8418
movq 0xc0(%rsp), %r15
incq %r15
movq 0x88(%rsp), %rax
addq 0x80(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x68(%rsp), %rbx
cmpq %rbx, %r15
movq 0x40(%rsp), %r12
leaq 0x274a5(%rip), %r13     # 0x2fbe0
leaq 0x26c1e(%rip), %rbp     # 0x2f360
jne 0x82e6
movl $0x4, %esi
movq 0xb8(%rsp), %rdi
callq 0x3530
movq 0x30(%rsp), %r9
leaq (,%r9,4), %rcx
xorl %edx, %edx
movq 0x58(%rsp), %rsi
testl %r12d, %r12d
jle 0x8788
movl (%rax,%rdx,4), %edi
xorl %r8d, %r8d
subl (%rsi,%r8,4), %edi
incq %r8
cmpq %r8, %r9
jne 0x8779
movl %edi, (%rax,%rdx,4)
incq %rdx
addq %rcx, %rsi
cmpq %rbx, %rdx
jne 0x876e
movl $0x80000001, %esi       # imm = 0x80000001
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x80000001, %edi       # imm = 0x80000001
movl (%rax,%rcx,4), %r8d
cmpl %edi, %r8d
jle 0x87c0
movl %ecx, %r14d
movl %edx, %ebp
movl %ecx, %edx
movl %edi, %esi
movl %r8d, %edi
jmp 0x87cd
cmpl %esi, %r8d
cmovgl %r8d, %esi
cmovgl %ecx, %ebp
movl %edx, %r14d
incq %rcx
cmpq %rcx, %rbx
jne 0x87a9
movq %rax, %rdi
callq 0x32c0
movl $0x1, %edi
movl $0x48, %esi
callq 0x3530
movq %rax, %rbx
movslq %r14d, %rax
movq 0x28(%rsp), %rcx
movslq (%rcx,%rax,4), %r15
movl %r15d, (%rbx)
movslq %ebp, %rax
movl (%rcx,%rax,4), %r13d
movl %r13d, 0x4(%rbx)
movl %r15d, %edi
negl %edi
cmovsl %r15d, %edi
addl $0x2, %edi
movl $0x1, %esi
callq 0x3530
movq %rax, %r12
movq %rax, 0x20(%rbx)
movl %r13d, %edi
negl %edi
cmovsl %r13d, %edi
addl $0x2, %edi
movl $0x1, %esi
callq 0x3530
movq %rax, 0x28(%rbx)
testq %r15, %r15
jle 0x8888
movb $0x2b, (%r12)
movq 0x48(%rsp), %rdx
imull %r14d, %edx
movq 0x20(%rbx), %rcx
movslq %edx, %rdx
addq 0x10(%rsp), %rdx
xorl %esi, %esi
leaq 0x27678(%rip), %rdi     # 0x2fee0
movq 0x18(%rsp), %r10
movq (%rdi), %r8
movsbq (%rdx,%rsi), %r9
movb (%r8,%r9), %r8b
movb %r8b, 0x1(%rcx,%rsi)
incq %rsi
cmpq %rsi, %r15
jne 0x886d
jmp 0x88da
testl %r15d, %r15d
movq 0x18(%rsp), %r10
js 0x8899
movb $0x2a, (%r12)
jmp 0x88da
movb $0x2d, (%r12)
movl %r15d, %edx
negl %edx
movslq 0x38(%rsp), %rsi
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
incq %rdx
xorl %esi, %esi
movb (%rdx,%rsi), %dil
testb %dil, %dil
je 0x88da
movq 0x20(%rbx), %r8
movb %dil, 0x1(%r8,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x88c0
testl %r13d, %r13d
jle 0x891e
movb $0x2b, (%rax)
leaq 0x275f7(%rip), %rcx     # 0x2fee0
movq (%rcx), %rcx
movq 0x80(%rsp), %rdx
imull %ebp, %edx
movslq %edx, %rdx
addq 0x10(%rsp), %rdx
xorl %esi, %esi
movq 0x30(%rsp), %r9
movsbq (%rdx,%rsi), %rdi
movb (%rcx,%rdi), %dil
movb %dil, 0x1(%rax,%rsi)
incq %rsi
cmpq %rsi, %r13
jne 0x8906
jmp 0x8968
testl %r13d, %r13d
movq 0x30(%rsp), %r9
js 0x892d
movb $0x2a, (%rax)
jmp 0x8968
movb $0x2d, (%rax)
movl %r13d, %edx
negl %edx
movslq 0x38(%rsp), %rsi
cmpl $0x2, %edx
movl $0x1, %ecx
cmovgel %edx, %ecx
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
incq %rdx
xorl %esi, %esi
movb (%rdx,%rsi), %dil
testb %dil, %dil
je 0x8968
movb %dil, 0x1(%rax,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x8952
cmpl $0x0, 0x40(%rsp)
jle 0x89a2
leaq (,%r9,8), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
movl 0xc(%r10,%rcx), %edx
cmpl %r15d, %edx
jne 0x898c
incl 0x8(%rbx)
jmp 0x8999
cmpl %r13d, %edx
jne 0x8996
incl 0xc(%rbx)
jmp 0x8999
incl 0x10(%rbx)
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0x897d
movl %r14d, %ecx
subl %ebp, %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
incl %eax
movsd 0x1bab8(%rip), %xmm0    # 0x24470
movsd 0x1baf0(%rip), %xmm1    # 0x244b0
mulsd %xmm1, %xmm0
decl %eax
jne 0x89c0
movq 0x78(%rsp), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax), %xmm1
movq $0x0, 0x34(%rbx)
movq 0x40(%rsp), %r15
testl %r15d, %r15d
jle 0x8a62
movsd 0x1ba82(%rip), %xmm2    # 0x24470
subsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
divsd 0x1baba(%rip), %xmm2    # 0x244b8
cvttsd2si %xmm2, %eax
leaq 0x34(%rbx), %rcx
movq %rbx, %rdx
addq $0x38, %rdx
movl %r14d, %esi
imull %r15d, %esi
movl %ebp, %edi
imull %r15d, %edi
movslq %esi, %rsi
movslq %edi, %rdi
movq 0x58(%rsp), %r8
leaq (%r8,%rsi,4), %rsi
leaq (%r8,%rdi,4), %rdi
xorl %r8d, %r8d
movl (%rsi,%r8,4), %r10d
movq %rcx, %r9
subl (%rdi,%r8,4), %r10d
jg 0x8a40
movq %rdx, %r9
movl %r10d, %r11d
negl %r11d
cmovsl %r10d, %r11d
cmpl %eax, %r11d
jl 0x8a52
movl %eax, %r11d
addl %r11d, (%r9)
incq %r8
movq 0x30(%rsp), %r9
cmpq %r8, %r9
jne 0x8a30
testl %r14d, %r14d
sete %al
testl %ebp, %ebp
sete %cl
orb %al, %cl
testl %r15d, %r15d
setle %al
orb %cl, %al
jne 0x8ac7
imull %r15d, %r14d
imull %r15d, %ebp
movslq %r14d, %rax
movslq %ebp, %rcx
movq 0x60(%rsp), %rdx
leaq (%rdx,%rax,4), %rax
leaq (%rdx,%rcx,4), %rcx
xorl %edx, %edx
movq 0x60(%rsp), %rsi
movl (%rsi,%rdx,4), %esi
movl (%rax,%rdx,4), %r8d
movl (%rcx,%rdx,4), %edi
cmpl %r8d, %esi
jle 0x8ab3
cmpl %edi, %esi
jle 0x8ab3
incl 0x14(%rbx)
jmp 0x8abf
cmpl %r8d, %esi
je 0x8abc
cmpl %edi, %esi
jne 0x8abf
incl 0x18(%rbx)
incq %rdx
cmpq %rdx, %r9
jne 0x8a96
movq 0x60(%rsp), %rdi
callq 0x32c0
movq 0x58(%rsp), %rdi
callq 0x32c0
movq 0x98(%rsp), %rdi
callq 0x32c0
movq 0x90(%rsp), %rdi
callq 0x32c0
movq 0x10(%rsp), %rdi
callq 0x32c0
movq 0x78(%rsp), %rax
xorps %xmm0, %xmm0
cvtss2sd 0x4(%rax), %xmm0
callq 0x32a0
mulsd 0x1b96f(%rip), %xmm0    # 0x24488
addsd 0x1b977(%rip), %xmm0    # 0x24498
cvttsd2si %xmm0, %ecx
movl 0x34(%rbx), %edx
movl %edx, 0xd0(%rsp)
movl 0x38(%rbx), %eax
movl %eax, 0xd4(%rsp)
leal (%r15,%r15,2), %esi
movq 0x20(%rbx), %rdi
movb (%rdi), %r8b
addl %ecx, %esi
movl %esi, 0xd8(%rsp)
movl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl %r11d, %ebp
movl 0xd0(%rsp,%r10,4), %r11d
cmpl %r9d, %r11d
cmovll %r11d, %r9d
cmpl %ebp, %r11d
cmovgel %ebp, %r11d
cmovll %ebp, %r9d
cmovll %r10d, %edi
incq %r10
cmpq $0x3, %r10
jne 0x8b61
movl %edi, 0x30(%rbx)
subl %r11d, %r9d
movl %r9d, 0x3c(%rbx)
cmpl $0x1, %edi
jg 0x8bc5
movslq %edi, %rdx
movq 0x20(%rbx,%rdx,8), %rsi
xorl %eax, %eax
cmpb $0x2a, (%rsi)
je 0x8bce
movl $0x1, %eax
subl %edi, %eax
movl 0xd0(%rsp,%rax,4), %eax
addl 0xd0(%rsp,%rdx,4), %ecx
subl %ecx, %eax
addl $-0x3, %eax
jmp 0x8bce
cmpb $0x2a, %r8b
cmovel %edx, %eax
subl %esi, %eax
movl %eax, 0x40(%rbx)
testl %eax, %eax
jns 0x8bdc
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 0x1b8e2(%rip), %rdi     # 0x244e4
leaq 0x1b8e8(%rip), %rsi     # 0x244f1
leaq 0x1b8ee(%rip), %rcx     # 0x244fe
movl $0x1d1, %edx            # imm = 0x1D1
callq 0x3140
nop