// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_chain2aln
void mem_chain2aln(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, int l_query, const uint8_t *query, const mem_chain_t *c, mem_alnreg_v *av)
{
	int i, k, rid, max_off[2], aw[2]; // aw: actual bandwidth used in extension
	int64_t l_pac = bns->l_pac, rmax[2], tmp, max = 0;
	const mem_seed_t *s;
	uint8_t *rseq = 0;
	uint64_t *srt;

	if (c->n == 0) return;
	// get the max possible span
	rmax[0] = l_pac<<1; rmax[1] = 0;
	for (i = 0; i < c->n; ++i) {
		int64_t b, e;
		const mem_seed_t *t = &c->seeds[i];
		b = t->rbeg - (t->qbeg + cal_max_gap(opt, t->qbeg));
		e = t->rbeg + t->len + ((l_query - t->qbeg - t->len) + cal_max_gap(opt, l_query - t->qbeg - t->len));
		rmax[0] = rmax[0] < b? rmax[0] : b;
		rmax[1] = rmax[1] > e? rmax[1] : e;
		if (t->len > max) max = t->len;
	}
	rmax[0] = rmax[0] > 0? rmax[0] : 0;
	rmax[1] = rmax[1] < l_pac<<1? rmax[1] : l_pac<<1;
	if (rmax[0] < l_pac && l_pac < rmax[1]) { // crossing the forward-reverse boundary; then choose one side
		if (c->seeds[0].rbeg < l_pac) rmax[1] = l_pac; // this works because all seeds are guaranteed to be on the same strand
		else rmax[0] = l_pac;
	}
	// retrieve the reference sequence
	rseq = bns_fetch_seq(bns, pac, &rmax[0], c->seeds[0].rbeg, &rmax[1], &rid);
	assert(c->rid == rid);

	srt = malloc(c->n * 8);
	for (i = 0; i < c->n; ++i)
		srt[i] = (uint64_t)c->seeds[i].score<<32 | i;
	ks_introsort_64(c->n, srt);

	for (k = c->n - 1; k >= 0; --k) {
		mem_alnreg_t *a;
		s = &c->seeds[(uint32_t)srt[k]];

		for (i = 0; i < av->n; ++i) { // test whether extension has been made before
			mem_alnreg_t *p = &av->a[i];
			int64_t rd;
			int qd, w, max_gap;
			if (s->rbeg < p->rb || s->rbeg + s->len > p->re || s->qbeg < p->qb || s->qbeg + s->len > p->qe) continue; // not fully contained
			if (s->len - p->seedlen0 > .1 * l_query) continue; // this seed may give a better alignment
			// qd: distance ahead of the seed on query; rd: on reference
			qd = s->qbeg - p->qb; rd = s->rbeg - p->rb;
			max_gap = cal_max_gap(opt, qd < rd? qd : rd); // the maximal gap allowed in regions ahead of the seed
			w = max_gap < p->w? max_gap : p->w; // bounded by the band width
			if (qd - rd < w && rd - qd < w) break; // the seed is "around" a previous hit
			// similar to the previous four lines, but this time we look at the region behind
			qd = p->qe - (s->qbeg + s->len); rd = p->re - (s->rbeg + s->len);
			max_gap = cal_max_gap(opt, qd < rd? qd : rd);
			w = max_gap < p->w? max_gap : p->w;
			if (qd - rd < w && rd - qd < w) break;
		}
		if (i < av->n) { // the seed is (almost) contained in an existing alignment; further testing is needed to confirm it is not leading to a different aln
			if (bwa_verbose >= 4)
				printf("** Seed(%d) [%ld;%ld,%ld] is almost contained in an existing alignment [%d,%d) <=> [%ld,%ld)\n",
					   k, (long)s->len, (long)s->qbeg, (long)s->rbeg, av->a[i].qb, av->a[i].qe, (long)av->a[i].rb, (long)av->a[i].re);
			for (i = k + 1; i < c->n; ++i) { // check overlapping seeds in the same chain
				const mem_seed_t *t;
				if (srt[i] == 0) continue;
				t = &c->seeds[(uint32_t)srt[i]];
				if (t->len < s->len * .95) continue; // only check overlapping if t is long enough; TODO: more efficient by early stopping
				if (s->qbeg <= t->qbeg && s->qbeg + s->len - t->qbeg >= s->len>>2 && t->qbeg - s->qbeg != t->rbeg - s->rbeg) break;
				if (t->qbeg <= s->qbeg && t->qbeg + t->len - s->qbeg >= s->len>>2 && s->qbeg - t->qbeg != s->rbeg - t->rbeg) break;
			}
			if (i == c->n) { // no overlapping seeds; then skip extension
				srt[k] = 0; // mark that seed extension has not been performed
				continue;
			}
			if (bwa_verbose >= 4)
				printf("** Seed(%d) might lead to a different alignment even though it is contained. Extension will be performed.\n", k);
		}

		a = kv_pushp(mem_alnreg_t, *av);
		memset(a, 0, sizeof(mem_alnreg_t));
		a->w = aw[0] = aw[1] = opt->w;
		a->score = a->truesc = -1;
		a->rid = c->rid;

		if (bwa_verbose >= 4) err_printf("** ---> Extending from seed(%d) [%ld;%ld,%ld] @ %s <---\n", k, (long)s->len, (long)s->qbeg, (long)s->rbeg, bns->anns[c->rid].name);
		if (s->qbeg) { // left extension
			uint8_t *rs, *qs;
			int qle, tle, gtle, gscore;
			qs = malloc(s->qbeg);
			for (i = 0; i < s->qbeg; ++i) qs[i] = query[s->qbeg - 1 - i];
			tmp = s->rbeg - rmax[0];
			rs = malloc(tmp);
			for (i = 0; i < tmp; ++i) rs[i] = rseq[tmp - 1 - i];
			for (i = 0; i < MAX_BAND_TRY; ++i) {
				int prev = a->score;
				aw[0] = opt->w << i;
				if (bwa_verbose >= 4) {
					int j;
					printf("*** Left ref:   "); for (j = 0; j < tmp; ++j) putchar("ACGTN"[(int)rs[j]]); putchar('\n');
					printf("*** Left query: "); for (j = 0; j < s->qbeg; ++j) putchar("ACGTN"[(int)qs[j]]); putchar('\n');
				}
				a->score = ksw_extend2(s->qbeg, qs, tmp, rs, VALUE_DEFINED, opt->mat, opt->o_del, opt->e_del, opt->o_ins, opt->e_ins, aw[0], opt->pen_clip5, opt->zdrop, s->len * opt->a, &qle, &tle, &gtle, &gscore, &max_off[0]);
				if (bwa_verbose >= 4) { printf("*** Left extension: prev_score=%d; score=%d; bandwidth=%d; max_off_diagonal_dist=%d\n", prev, a->score, aw[0], max_off[0]); fflush(stdout); }
				if (a->score == prev || max_off[0] < (aw[0]>>1) + (aw[0]>>2)) break;
			}
			// check whether we prefer to reach the end of the query
			if (gscore <= 0 || gscore <= a->score - opt->pen_clip5) { // local extension
				a->qb = s->qbeg - qle, a->rb = s->rbeg - tle;
				a->truesc = a->score;
			} else { // to-end extension
				a->qb = 0, a->rb = s->rbeg - gtle;
				a->truesc = gscore;
			}
			free(qs); free(rs);
		} else a->score = a->truesc = s->len * opt->a, a->qb = 0, a->rb = s->rbeg;

		if (s->qbeg + s->len != l_query) { // right extension
			int qle, tle, qe, re, gtle, gscore, sc0 = a->score;
			qe = s->qbeg + s->len;
			re = s->rbeg + s->len - rmax[0];
			assert(re >= 0);
			for (i = 0; i < MAX_BAND_TRY; ++i) {
				int prev = a->score;
				aw[1] = opt->w << i;
				if (bwa_verbose >= 4) {
					int j;
					printf("*** Right ref:   "); for (j = 0; j < rmax[1] - rmax[0] - re; ++j) putchar("ACGTN"[(int)rseq[re+j]]); putchar('\n');
					printf("*** Right query: "); for (j = 0; j < l_query - qe; ++j) putchar("ACGTN"[(int)query[qe+j]]); putchar('\n');
				}

				a->score = ksw_extend2(l_query - qe, query + qe, rmax[1] - rmax[0] - re, rseq + re, VALUE_DEFINED, opt->mat, opt->o_del, opt->e_del, opt->o_ins, opt->e_ins, aw[1], opt->pen_clip3, opt->zdrop, sc0, &qle, &tle, &gtle, &gscore, &max_off[1]);
				if (bwa_verbose >= 4) { printf("*** Right extension: prev_score=%d; score=%d; bandwidth=%d; max_off_diagonal_dist=%d\n", prev, a->score, aw[1], max_off[1]); fflush(stdout); }
				if (a->score == prev || max_off[1] < (aw[1]>>1) + (aw[1]>>2)) break;
			}
			// similar to the above
			if (gscore <= 0 || gscore <= a->score - opt->pen_clip3) { // local extension
				a->qe = qe + qle, a->re = rmax[0] + re + tle;
				a->truesc += a->score - sc0;
			} else { // to-end extension
				a->qe = l_query, a->re = rmax[0] + re + gtle;
				a->truesc += gscore - sc0;
			}
		} else a->qe = l_query, a->re = s->rbeg + s->len;
		if (bwa_verbose >= 4) printf("*** Added alignment region: [%d,%d) <=> [%ld,%ld); score=%d; {left,right}_bandwidth={%d,%d}\n", a->qb, a->qe, (long)a->rb, (long)a->re, a->score, aw[0], aw[1]);

		// compute seedcov
		for (i = 0, a->seedcov = 0; i < c->n; ++i) {
			const mem_seed_t *t = &c->seeds[i];
			if (t->qbeg >= a->qb && t->qbeg + t->len <= a->qe && t->rbeg >= a->rb && t->rbeg + t->len <= a->re) // seed fully contained
				a->seedcov += t->len; // this is not very accurate, but for approx. mapQ, this is good enough
		}
		a->w = aw[0] > aw[1]? aw[0] : aw[1];
		a->seedlen0 = s->len;

		a->frac_rep = c->frac_rep;
	}
	free(srt); free(rseq);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %ecx, 0x3c(%rsp)
movq %rdi, 0x18(%rsp)
movl (%r9), %eax
testq %rax, %rax
je 0x1bbbb
movq (%rsi), %rcx
movq %rcx, 0x30(%rsp)
leaq (%rcx,%rcx), %rbx
testl %eax, %eax
movq %r9, 0x80(%rsp)
movq %r8, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movq %rdx, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
jle 0x1aec9
movq 0x20(%r9), %rsi
movq 0x18(%rsp), %rcx
movl (%rcx), %r8d
cvtsi2sdl 0xc(%rcx), %xmm0
movl 0x8(%rcx), %r9d
movl 0x10(%rcx), %r10d
cvtsi2sdl 0x14(%rcx), %xmm1
movl 0x24(%rcx), %edx
addl %edx, %edx
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movsd 0xd757(%rip), %xmm2     # 0x28530
xorl %edi, %edi
movl 0x8(%rsi,%r15), %r12d
movl %r8d, %eax
imull %r12d, %eax
movl %eax, %r11d
subl %r9d, %r11d
xorps %xmm3, %xmm3
cvtsi2sd %r11d, %xmm3
divsd %xmm0, %xmm3
addsd %xmm2, %xmm3
cvttsd2si %xmm3, %r11d
subl %r10d, %eax
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm1, %xmm3
addsd %xmm2, %xmm3
cvttsd2si %xmm3, %ebp
cmpl %ebp, %r11d
cmovgl %r11d, %ebp
cmpl $0x2, %ebp
jge 0x1ae29
movl $0x1, %ebp
cmpl %edx, %ebp
jl 0x1ae2f
movl %edx, %ebp
movslq 0xc(%rsi,%r15), %r13
movl 0x3c(%rsp), %ecx
subl %r12d, %ecx
subl %r13d, %ecx
movl %ecx, %eax
imull %r8d, %eax
movl %eax, %r11d
subl %r9d, %r11d
xorps %xmm3, %xmm3
cvtsi2sd %r11d, %xmm3
divsd %xmm0, %xmm3
addsd %xmm2, %xmm3
cvttsd2si %xmm3, %r14d
subl %r10d, %eax
xorps %xmm3, %xmm3
cvtsi2sd %eax, %xmm3
divsd %xmm1, %xmm3
addsd %xmm2, %xmm3
cvttsd2si %xmm3, %r11d
cmpl %r11d, %r14d
cmovgl %r14d, %r11d
cmpl $0x2, %r11d
jge 0x1ae89
movl $0x1, %r11d
cmpl %edx, %r11d
jl 0x1ae91
movl %edx, %r11d
movq (%rsi,%r15), %rax
addl %r12d, %ebp
movslq %ebp, %r14
addq %rax, %r13
subq %r14, %rax
addl %ecx, %r11d
movslq %r11d, %rcx
addq %r13, %rcx
cmpq %rax, %rbx
cmovgeq %rax, %rbx
cmpq %rcx, %rdi
cmovleq %rcx, %rdi
addq $0x18, %r15
cmpq %r15, 0x28(%rsp)
jne 0x1addb
jmp 0x1aecb
xorl %edi, %edi
xorl %ecx, %ecx
testq %rbx, %rbx
cmovgq %rbx, %rcx
leaq 0x68(%rsp), %r8
movq 0x10(%rsp), %rsi
cmpq %rsi, %rdi
cmovlq %rdi, %rsi
movq %rcx, -0x8(%r8)
movq %rsi, (%r8)
movq 0x80(%rsp), %r14
movq 0x20(%r14), %rax
movq 0x30(%rsp), %rdx
cmpq %rdx, %rcx
jge 0x1af1b
movq %rdx, %rcx
cmpq %rsi, %rdx
jge 0x1af1b
cmpq %rcx, (%rax)
jge 0x1af16
movq %rcx, 0x68(%rsp)
jmp 0x1af1b
movq %rcx, 0x60(%rsp)
movq (%rax), %rcx
leaq 0x60(%rsp), %rdx
leaq 0xf4(%rsp), %rbx
movq 0xa8(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rbx, %r9
callq 0x116eb
movq %rax, 0xa0(%rsp)
movl 0xc(%r14), %eax
cmpl (%rbx), %eax
jne 0x1bbec
movslq (%r14), %rdi
shlq $0x3, %rdi
leaq 0xd95e(%rip), %rsi      # 0x288c0
leaq 0xdd09(%rip), %rcx      # 0x28c72
movl $0x2eb, %edx            # imm = 0x2EB
callq 0x23213
movslq (%r14), %rdi
testq %rdi, %rdi
jle 0x1af9e
movq 0x20(%r14), %rsi
addq $0x10, %rsi
xorl %ecx, %ecx
movl (%rsi), %edx
shlq $0x20, %rdx
addq %rcx, %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
addq $0x18, %rsi
cmpq %rcx, %rdi
jne 0x1af85
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rsi
callq 0xd4c1
movq 0x78(%rsp), %rdi
movslq (%r14), %rcx
testq %rcx, %rcx
jle 0x1bba9
cvtsi2sdl 0x3c(%rsp), %xmm0
mulsd 0xa7c4(%rip), %xmm0     # 0x25790
movsd %xmm0, 0xd8(%rsp)
movq 0x18(%rsp), %rax
addq $0xc4, %rax
movq %rax, 0xc8(%rsp)
movl %ecx, %r15d
movq %r15, 0x48(%rsp)
leaq -0x1(%rcx), %rax
movq %rax, 0x88(%rsp)
movq %rcx, 0xb8(%rsp)
movl -0x8(%rdi,%rcx,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x20(%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x130(%rsp), %rax
movq (%rax), %rsi
testq %rsi, %rsi
je 0x1b217
movq 0x18(%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %r8
movq (%rdi), %r10
movq %r8, %rax
subq %r10, %rax
jl 0x1b20a
movq 0x8(%rsp), %rcx
movslq 0xc(%rcx), %rdx
leaq (%r8,%rdx), %rcx
movq 0x8(%rdi), %r11
movq %r11, %r14
subq %rcx, %r14
jl 0x1b20a
movq 0x8(%rsp), %rcx
movslq 0x8(%rcx), %rcx
movl 0x10(%rdi), %r9d
cmpl %r9d, %ecx
jl 0x1b20a
leal (%rcx,%rdx), %ebx
movl 0x14(%rdi), %r15d
movq %r15, 0x28(%rsp)
movl %r15d, %ebp
subl %ebx, %ebp
jl 0x1b20a
movl 0x44(%rdi), %ebx
movl %edx, %r15d
subl %ebx, %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
ucomisd 0xd8(%rsp), %xmm0
ja 0x1b20a
movl %ecx, %ebx
subl %r9d, %ebx
movslq %ebx, %r12
movq %rax, %rbx
subq %r12, %rbx
movq %rbx, 0x10(%rsp)
cmovlq %rax, %r12
movq 0x18(%rsp), %rbx
movl (%rbx), %r15d
movl 0x8(%rbx), %r13d
imull %r15d, %r12d
movl %r12d, %eax
movl %r13d, 0x4(%rsp)
subl %r13d, %eax
cvtsi2sd %eax, %xmm1
xorps %xmm0, %xmm0
cvtsi2sdl 0xc(%rbx), %xmm0
divsd %xmm0, %xmm1
movsd 0xd434(%rip), %xmm3     # 0x28530
addsd %xmm3, %xmm1
cvttsd2si %xmm1, %eax
movl 0x10(%rbx), %r13d
movl %r13d, 0x90(%rsp)
subl %r13d, %r12d
cvtsi2sd %r12d, %xmm2
xorps %xmm1, %xmm1
cvtsi2sdl 0x14(%rbx), %xmm1
divsd %xmm1, %xmm2
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %r12d
cmpl %r12d, %eax
cmovgl %eax, %r12d
cmpl $0x2, %r12d
jge 0x1b140
movl $0x1, %r12d
movq 0x18(%rsp), %rax
movl 0x24(%rax), %eax
addl %eax, %eax
cmpl %eax, %r12d
jl 0x1b152
movl %eax, %r12d
movl 0x34(%rdi), %ebx
movl %ebx, 0x30(%rsp)
cmpl %ebx, %r12d
jl 0x1b163
movl 0x30(%rsp), %r12d
movq 0x10(%rsp), %r13
movq %r13, %rbx
negq %rbx
movslq %r12d, %r12
cmpq %r12, %rbx
jge 0x1b17f
cmpq %r12, %r13
jl 0x1ba45
movslq %ebp, %r12
movq %r14, %rbx
subq %r12, %rbx
cmovlq %r14, %r12
imull %r12d, %r15d
movl %r15d, %ebp
subl 0x4(%rsp), %ebp
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
divsd %xmm0, %xmm2
movsd 0xd386(%rip), %xmm3     # 0x28530
addsd %xmm3, %xmm2
cvttsd2si %xmm2, %r14d
subl 0x90(%rsp), %r15d
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %ebp
cmpl %ebp, %r14d
cmovgl %r14d, %ebp
cmpl $0x2, %ebp
jge 0x1b1e0
movl $0x1, %ebp
cmpl %eax, %ebp
movl 0x30(%rsp), %r14d
jl 0x1b1eb
movl %eax, %ebp
cmpl %r14d, %ebp
jl 0x1b1f3
movl %r14d, %ebp
movq %rbx, %r14
negq %r14
movslq %ebp, %rax
cmpq %rax, %r14
jge 0x1b20a
cmpq %rax, %rbx
jl 0x1ba45
addq $0x60, %rdi
decq %rsi
jne 0x1b039
movq 0x130(%rsp), %r15
movq (%r15), %rax
movq 0x18(%r15), %rdx
cmpq 0x8(%r15), %rax
jne 0x1b26d
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r15)
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rdx, %rdi
leaq 0xd66e(%rip), %rdx      # 0x288c0
movl $0x319, %ecx            # imm = 0x319
leaq 0xda14(%rip), %r8       # 0x28c72
callq 0x2324c
movq %rax, %rdx
movq %rax, 0x18(%r15)
movq (%r15), %rax
movq 0x80(%rsp), %r14
leaq 0x15bc4(%rip), %r12     # 0x30e40
leaq 0xd361(%rip), %rbp      # 0x285e4
leaq 0x1(%rax), %rcx
movq %rcx, (%r15)
leaq (%rax,%rax,2), %rbx
shlq $0x5, %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%rdx,%rbx)
movupd %xmm0, 0x40(%rdx,%rbx)
movupd %xmm0, 0x30(%rdx,%rbx)
movupd %xmm0, 0x20(%rdx,%rbx)
movupd %xmm0, 0x10(%rdx,%rbx)
movupd %xmm0, (%rdx,%rbx)
movq 0x18(%rsp), %rax
movl 0x24(%rax), %r10d
movl %r10d, 0x34(%rdx,%rbx)
movq $-0x1, 0x1c(%rdx,%rbx)
movslq 0xc(%r14), %rax
movq %rdx, %r13
movl %eax, 0x18(%rdx,%rbx)
cmpl $0x4, (%r12)
jl 0x1b329
movq 0x8(%rsp), %rsi
movslq 0xc(%rsi), %rdx
movslq 0x8(%rsi), %rcx
movq (%rsi), %r8
movq 0xa8(%rsp), %rsi
movq 0x10(%rsi), %rsi
leaq (%rax,%rax,4), %rax
movq 0x18(%rsi,%rax,8), %r9
leaq 0xda3b(%rip), %rdi      # 0x28d49
movq 0x88(%rsp), %rsi
xorl %eax, %eax
movq %r14, %r15
movq %r10, %r14
callq 0xe4a3
movq %r14, %r10
movq %r15, %r14
addq %rbx, %r13
movq 0x8(%rsp), %rbx
movslq 0x8(%rbx), %rdi
testq %rdi, %rdi
movq %r13, 0x10(%rsp)
je 0x1b62d
movq %r10, 0x30(%rsp)
leaq 0xd571(%rip), %rsi      # 0x288c0
movl $0x323, %edx            # imm = 0x323
leaq 0xd917(%rip), %rcx      # 0x28c72
callq 0x23213
movl 0x8(%rbx), %edi
testl %edi, %edi
movq 0xb0(%rsp), %rsi
jle 0x1b391
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %edx, %edx
addl %ecx, %edi
movslq %edi, %rdi
movb (%rsi,%rdi), %dil
movb %dil, (%rax,%rdx)
incq %rdx
movslq 0x8(%rbx), %rdi
decl %ecx
cmpq %rdi, %rdx
jl 0x1b376
movq %rax, 0x40(%rsp)
movq (%rbx), %r14
movq 0x60(%rsp), %rbx
movq %r14, %rdi
subq %rbx, %rdi
leaq 0xd515(%rip), %rsi      # 0x288c0
movl $0x326, %edx            # imm = 0x326
leaq 0xd8bb(%rip), %rcx      # 0x28c72
callq 0x23213
movq %rax, %r15
subq %rbx, %r14
movq %r14, %rcx
movq 0xa0(%rsp), %rsi
jle 0x1b3dd
movb -0x1(%rsi,%rcx), %dl
movb %dl, (%rax)
incq %rax
decq %rcx
jne 0x1b3cf
movq 0x10(%rsp), %rax
movl 0x1c(%rax), %edi
movl (%r12), %edx
xorl %ecx, %ecx
movb $0x1, %al
movl %eax, 0x48(%rsp)
movq 0x8(%rsp), %rbx
movl %edi, 0x4(%rsp)
movq 0x18(%rsp), %rax
movl 0x24(%rax), %eax
shll %cl, %eax
movq %rax, 0x28(%rsp)
cmpl $0x4, %edx
jl 0x1b485
leaq 0xd96d(%rip), %rdi      # 0x28d82
xorl %eax, %eax
callq 0x3060
testq %r14, %r14
jle 0x1b43a
xorl %r12d, %r12d
movzbl (%r15,%r12), %eax
movsbl (%rax,%rbp), %edi
callq 0x34c0
incq %r12
cmpq %r12, %r14
jne 0x1b424
movl $0xa, %edi
callq 0x34c0
leaq 0xd948(%rip), %rdi      # 0x28d93
xorl %eax, %eax
callq 0x3060
cmpl $0x0, 0x8(%rbx)
movq 0x40(%rsp), %r13
jle 0x1b47b
xorl %r12d, %r12d
movzbl (%r13,%r12), %eax
movsbl (%rax,%rbp), %edi
callq 0x34c0
incq %r12
movslq 0x8(%rbx), %rax
cmpq %rax, %r12
jl 0x1b460
movl $0xa, %edi
callq 0x34c0
movl 0x8(%rbx), %edi
movq 0x18(%rsp), %rax
movq %rbx, %rcx
movl (%rax), %ebx
movl 0x8(%rax), %r13d
movl 0xc(%rax), %edx
movq %rdx, 0x90(%rsp)
movl 0x10(%rax), %r11d
movl 0x14(%rax), %r12d
movl 0x1c(%rax), %ebp
movl 0x28(%rax), %eax
imull 0xc(%rcx), %ebx
subq $0x8, %rsp
movq 0x48(%rsp), %rsi
movl %r14d, %edx
movq %r15, %rcx
movl $0x16, %r8d
movq 0xd0(%rsp), %r9
leaq 0xa0(%rsp), %r10
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x6c(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
leaq 0x84(%rsp), %r10
pushq %r10
pushq %rbx
pushq %rax
pushq %rbp
movq 0x70(%rsp), %rbp
pushq %rbp
pushq %r12
pushq %r11
pushq 0xf0(%rsp)
pushq %r13
callq 0x241fb
addq $0x70, %rsp
movq 0x10(%rsp), %rbx
movl %eax, 0x1c(%rbx)
leaq 0x15919(%rip), %r12     # 0x30e40
movl (%r12), %edx
cmpl $0x4, %edx
jl 0x1b56a
movl 0x98(%rsp), %r8d
leaq 0xd865(%rip), %rdi      # 0x28da4
movl 0x4(%rsp), %r13d
movl %r13d, %esi
movl %eax, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x3060
movq 0x14a4f(%rip), %rax     # 0x2ffa8
movq (%rax), %rdi
callq 0x3370
movl (%r12), %edx
movl 0x1c(%rbx), %eax
jmp 0x1b56f
movl 0x4(%rsp), %r13d
cmpl %r13d, %eax
leaq 0xd06b(%rip), %rbp      # 0x285e4
movq 0x8(%rsp), %rbx
je 0x1b5b3
movq 0x28(%rsp), %rsi
movl %esi, %ecx
sarl %ecx
sarl $0x2, %esi
addl %ecx, %esi
cmpl %esi, 0x98(%rsp)
setge %sil
movl $0x1, %ecx
movl %eax, %edi
testb %sil, 0x48(%rsp)
movl $0x0, 0x48(%rsp)
jne 0x1b3f6
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
jle 0x1b5e6
movl %eax, %edx
movq 0x18(%rsp), %rsi
subl 0x1c(%rsi), %edx
cmpl %edx, %ecx
jle 0x1b5e6
movq 0x10(%rsp), %rsi
movl $0x0, 0x10(%rsi)
movq (%rbx), %rcx
movslq 0x54(%rsp), %rax
subq %rax, %rcx
movl 0x24(%rsp), %eax
jmp 0x1b600
movl 0x8(%rbx), %ecx
subl 0x5c(%rsp), %ecx
movq 0x10(%rsp), %rsi
movl %ecx, 0x10(%rsi)
movq (%rbx), %rcx
movslq 0x58(%rsp), %rdx
subq %rdx, %rcx
movq 0x40(%rsp), %rdi
movq %rcx, (%rsi)
movl %eax, 0x20(%rsi)
callq 0x3390
movq %r15, %rdi
callq 0x3390
movl 0x8(%rbx), %eax
movl 0xc(%rbx), %ecx
movq 0x80(%rsp), %r14
movq 0x30(%rsp), %r10
jmp 0x1b65b
movl 0xc(%rbx), %ecx
movq 0x18(%rsp), %rax
movl (%rax), %eax
imull %ecx, %eax
movl %eax, 0x20(%r13)
movl %eax, 0x1c(%r13)
movl $0x0, 0x10(%r13)
movq (%rbx), %rax
movq %rax, (%r13)
xorl %eax, %eax
movl %r10d, %edx
movq %rdx, 0x28(%rsp)
leal (%rcx,%rax), %edx
movl 0x3c(%rsp), %esi
cmpl %esi, %edx
movl %esi, %edx
jne 0x1b685
movq 0x10(%rsp), %r13
movl %edx, 0x14(%r13)
movslq %ecx, %r8
addq (%rbx), %r8
movq %r8, 0x8(%r13)
movq 0x28(%rsp), %rbp
jmp 0x1b96b
movl 0xc(%rbx), %edi
movq (%rbx), %rbx
addq %rdi, %rbx
subq 0x60(%rsp), %rbx
testl %ebx, %ebx
movq 0xa0(%rsp), %rcx
js 0x1bbcd
movq 0x10(%rsp), %rsi
movl 0x1c(%rsi), %r8d
addl %eax, %edi
movq %rbx, 0xe0(%rsp)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movl %edx, %r14d
subl %edi, %r14d
movq %rdi, 0xd0(%rsp)
movslq %edi, %rsi
addq 0xb0(%rsp), %rsi
leaq (%rcx,%rbx), %r13
movl (%r12), %edx
xorl %ecx, %ecx
movb $0x1, %al
movl %eax, 0x48(%rsp)
movq %r8, 0xc0(%rsp)
movl %r8d, %edi
movq %rsi, 0x40(%rsp)
movq %rbx, 0xe8(%rsp)
movl %edi, 0x4(%rsp)
movq 0x18(%rsp), %rax
movl 0x24(%rax), %eax
shll %cl, %eax
movq %rax, 0x30(%rsp)
cmpl $0x4, %edx
jl 0x1b7ae
leaq 0xd6e1(%rip), %rdi      # 0x28e01
xorl %eax, %eax
callq 0x3060
movq 0x68(%rsp), %rax
movq 0x60(%rsp), %rcx
addq %rbx, %rcx
subq %rcx, %rax
testq %rax, %rax
jle 0x1b766
xorl %r12d, %r12d
movzbl (%r13,%r12), %eax
movsbl (%rax,%rbp), %edi
callq 0x34c0
incq %r12
movq 0x68(%rsp), %rax
movq 0x60(%rsp), %rcx
addq %rbx, %rcx
subq %rcx, %rax
cmpq %r12, %rax
jg 0x1b73f
movl $0xa, %edi
callq 0x34c0
leaq 0xd69c(%rip), %rdi      # 0x28e13
xorl %eax, %eax
callq 0x3060
testl %r14d, %r14d
movq 0x40(%rsp), %r15
jle 0x1b7a1
xorl %r12d, %r12d
movzbl (%r15,%r12), %eax
movsbl (%rax,%rbp), %edi
callq 0x34c0
incq %r12
cmpq %r12, %r14
jne 0x1b78b
movl $0xa, %edi
callq 0x34c0
movq %r15, %rsi
movl 0x68(%rsp), %edx
movl 0x60(%rsp), %eax
addl 0xe0(%rsp), %eax
subl %eax, %edx
movq 0x18(%rsp), %rax
movl 0x8(%rax), %r15d
movl 0xc(%rax), %ecx
movq %rcx, 0x90(%rsp)
movl 0x10(%rax), %r11d
movl 0x14(%rax), %r12d
movl 0x20(%rax), %ebp
movl 0x28(%rax), %eax
subq $0x8, %rsp
movl %r14d, %edi
movq %r13, %rcx
movl $0x16, %r8d
movq 0xd0(%rsp), %r9
leaq 0xa4(%rsp), %r10
pushq %r10
leaq 0x34(%rsp), %r10
pushq %r10
leaq 0x6c(%rsp), %r10
pushq %r10
leaq 0x78(%rsp), %r10
pushq %r10
leaq 0x84(%rsp), %r10
pushq %r10
pushq 0xf0(%rsp)
pushq %rax
pushq %rbp
movq 0x78(%rsp), %rbx
pushq %rbx
pushq %r12
pushq %r11
pushq 0xf0(%rsp)
pushq %r15
callq 0x241fb
addq $0x70, %rsp
movq 0x10(%rsp), %rbp
movl %eax, 0x1c(%rbp)
leaq 0x155ea(%rip), %r12     # 0x30e40
movl (%r12), %edx
cmpl $0x4, %edx
jl 0x1b899
movl 0x9c(%rsp), %r8d
leaq 0xd5b7(%rip), %rdi      # 0x28e25
movl 0x4(%rsp), %r15d
movl %r15d, %esi
movl %eax, %edx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x3060
movq 0x14720(%rip), %rax     # 0x2ffa8
movq (%rax), %rdi
callq 0x3370
movl (%r12), %edx
movl 0x1c(%rbp), %eax
jmp 0x1b89e
movl 0x4(%rsp), %r15d
cmpl %r15d, %eax
leaq 0xcd3c(%rip), %rbp      # 0x285e4
movq 0x30(%rsp), %r10
movq 0xe8(%rsp), %rbx
movq 0x40(%rsp), %rsi
je 0x1b8ee
movl %r10d, %ecx
sarl %ecx
movl %r10d, %edi
sarl $0x2, %edi
addl %ecx, %edi
cmpl %edi, 0x9c(%rsp)
setge %r8b
movl $0x1, %ecx
movl %eax, %edi
testb %r8b, 0x48(%rsp)
movl $0x0, 0x48(%rsp)
jne 0x1b6fd
movl 0x24(%rsp), %ecx
testl %ecx, %ecx
movq 0x80(%rsp), %r14
jle 0x1b930
movl %eax, %edx
movq 0x18(%rsp), %rsi
subl 0x20(%rsi), %edx
cmpl %edx, %ecx
jle 0x1b930
movl 0x3c(%rsp), %eax
movq 0x10(%rsp), %r13
movl %eax, 0x14(%r13)
addq 0x60(%rsp), %rbx
movslq 0x54(%rsp), %r8
addq %rbx, %r8
movq %r8, 0x8(%r13)
movl 0x24(%rsp), %eax
jmp 0x1b956
movq 0xd0(%rsp), %rcx
addl 0x5c(%rsp), %ecx
movq 0x10(%rsp), %r13
movl %ecx, 0x14(%r13)
addq 0x60(%rsp), %rbx
movslq 0x58(%rsp), %r8
addq %rbx, %r8
movq %r8, 0x8(%r13)
movq 0x28(%rsp), %rbp
subl 0xc0(%rsp), %eax
addl %eax, 0x20(%r13)
movq 0x8(%rsp), %rbx
cmpl $0x4, (%r12)
jl 0x1b9a3
movl 0x10(%r13), %esi
movl 0x14(%r13), %edx
movq (%r13), %rcx
movl 0x1c(%r13), %r9d
leaq 0xd4f2(%rip), %rdi      # 0x28e7b
xorl %eax, %eax
pushq %r10
pushq %rbp
movq %r14, %r15
movq %r10, %r14
callq 0x3060
movq %r14, %r10
movq %r15, %r14
addq $0x10, %rsp
movl $0x0, 0x38(%r13)
movslq (%r14), %r15
testq %r15, %r15
jle 0x1ba06
movq 0x20(%r14), %rax
movl 0x10(%r13), %ecx
leaq (,%r15,8), %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl 0x8(%rax,%rsi), %r9d
cmpl %ecx, %r9d
jl 0x1b9fd
movslq 0xc(%rax,%rsi), %r8
addl %r8d, %r9d
cmpl 0x14(%r13), %r9d
jg 0x1b9fd
movq (%rax,%rsi), %r9
cmpq (%r13), %r9
jl 0x1b9fd
addq %r8, %r9
cmpq 0x8(%r13), %r9
jg 0x1b9fd
addl %r8d, %edi
movl %edi, 0x38(%r13)
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0x1b9cb
cmpl %r10d, %ebp
cmovgl %ebp, %r10d
movl %r10d, 0x34(%r13)
movl 0xc(%rbx), %eax
movl %eax, 0x44(%r13)
movss 0x14(%r14), %xmm0
movss %xmm0, 0x50(%r13)
movq 0x78(%rsp), %rdi
cmpq $0x1, 0xb8(%rsp)
movq 0x88(%rsp), %rcx
jg 0x1afeb
jmp 0x1bba9
leaq 0x153f4(%rip), %rbx     # 0x30e40
cmpl $0x4, (%rbx)
movq 0x80(%rsp), %r14
movq 0x48(%rsp), %rsi
jl 0x1ba87
subq $0x8, %rsp
leaq 0xd217(%rip), %rdi      # 0x28c80
movq 0x90(%rsp), %rsi
xorl %eax, %eax
pushq %r11
pushq %r10
pushq 0x40(%rsp)
callq 0x3060
addq $0x20, %rsp
movl (%r14), %esi
movslq %esi, %rax
movq 0xb8(%rsp), %rdx
movq %rdx, %rcx
cmpq %rax, %rdx
movq %rsi, %r15
jge 0x1bb66
movq %rdx, %rcx
movq 0x78(%rsp), %rdi
movq (%rdi,%rcx,8), %rax
testq %rax, %rax
je 0x1bb53
movq 0x20(%r14), %rsi
movl %eax, %eax
leaq (%rax,%rax,2), %rdi
movl 0xc(%rsi,%rdi,8), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x8(%rsp), %rdx
movl 0xc(%rdx), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
mulsd 0xcdae(%rip), %xmm1     # 0x28890
ucomisd %xmm0, %xmm1
ja 0x1bb53
leaq (%rsi,%rdi,8), %rsi
movq 0x8(%rsp), %rdi
movl 0x8(%rdi), %r9d
movl 0x8(%rsi), %r8d
movl %r9d, %edi
subl %r8d, %edi
jg 0x1bb2e
leal (%r9,%rdx), %r10d
subl %r8d, %r10d
movl %edx, %r11d
sarl $0x2, %r11d
cmpl %r11d, %r10d
jl 0x1bb2e
movl %r8d, %r10d
subl %r9d, %r10d
movslq %r10d, %r10
movq (%rsi), %r11
movq 0x8(%rsp), %r12
subq (%r12), %r11
cmpq %r10, %r11
jne 0x1bb66
cmpl %r9d, %r8d
jg 0x1bb53
subl %r9d, %eax
addl %r8d, %eax
sarl $0x2, %edx
cmpl %edx, %eax
jl 0x1bb53
movslq %edi, %rax
movq 0x8(%rsp), %rdx
movq (%rdx), %rdx
subq (%rsi), %rdx
cmpq %rax, %rdx
jne 0x1bb66
incq %rcx
cmpl %ecx, %r15d
movq 0x78(%rsp), %rdi
jg 0x1baa9
jmp 0x1bb70
cmpl %ecx, %r15d
movq 0x78(%rsp), %rdi
jne 0x1bb85
movq 0x88(%rsp), %rax
movq $0x0, (%rdi,%rax,8)
jmp 0x1ba29
cmpl $0x4, (%rbx)
jl 0x1b217
leaq 0xd149(%rip), %rdi      # 0x28cde
movq 0x88(%rsp), %rsi
xorl %eax, %eax
callq 0x3060
jmp 0x1b217
callq 0x3390
movq 0xa0(%rsp), %rdi
callq 0x3390
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd225(%rip), %rdi      # 0x28df9
leaq 0xcce5(%rip), %rsi      # 0x288c0
leaq 0xd00c(%rip), %rcx      # 0x28bee
movl $0x343, %edx            # imm = 0x343
callq 0x31a0
leaq 0xcfed(%rip), %rdi      # 0x28be0
leaq 0xccc6(%rip), %rsi      # 0x288c0
leaq 0xcfed(%rip), %rcx      # 0x28bee
movl $0x2e9, %edx            # imm = 0x2E9
callq 0x31a0