// File: /workspace/github_c_makefile_star2_O2/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 $0x108, %rsp            # imm = 0x108
movq %rdi, 0x18(%rsp)
movl (%r9), %eax
testl %eax, %eax
je 0x190b6
movq %r9, %rbp
movq %rdx, 0x28(%rsp)
movl %ecx, 0x20(%rsp)
movq %r8, 0xd8(%rsp)
movq %rsi, 0xc8(%rsp)
movq (%rsi), %rcx
movq %rcx, 0x38(%rsp)
leaq (%rcx,%rcx), %rsi
xorl %ebx, %ebx
testl %eax, %eax
cmovlel %ebx, %eax
imulq $0x18, %rax, %rax
movq %rax, 0x30(%rsp)
xorl %edx, %edx
movq %rsi, %rdi
movq %r9, 0x70(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x18(%rsp), %r13
cmpq %rbx, 0x30(%rsp)
je 0x183eb
movq 0x70(%rsp), %rax
movq 0x20(%rax), %rbp
movq (%rbp,%rbx), %r14
movl 0x8(%rbp,%rbx), %r15d
movq %rdi, 0x10(%rsp)
movq %r13, %rdi
movl %r15d, %esi
movq %rdx, 0x8(%rsp)
callq 0x19106
addl %r15d, %eax
cltq
movq %r14, %r12
subq %rax, %r12
movslq 0xc(%rbp,%rbx), %rax
addq %rax, %r14
addl %r15d, %eax
movl 0x20(%rsp), %ebp
subl %eax, %ebp
movq %r13, %rdi
movl %ebp, %esi
callq 0x19106
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rdx
movq 0x58(%rsp), %rsi
addl %ebp, %eax
movq 0x70(%rsp), %rbp
cltq
addq %r14, %rax
cmpq %r12, %rdi
cmovgeq %r12, %rdi
movq %rdi, 0x40(%rsp)
cmpq %rax, %rdx
cmovleq %rax, %rdx
movq %rdx, 0x48(%rsp)
addq $0x18, %rbx
jmp 0x18356
xorl %ecx, %ecx
testq %rdi, %rdi
cmovgq %rdi, %rcx
cmpq %rsi, %rdx
cmovlq %rdx, %rsi
movq %rcx, 0x40(%rsp)
movq %rsi, 0x48(%rsp)
movq 0x20(%rbp), %rax
movq 0x38(%rsp), %rdx
cmpq %rdx, %rcx
movl 0x20(%rsp), %ebx
jge 0x18430
movq %rdx, %rcx
cmpq %rsi, %rdx
jge 0x18430
cmpq %rcx, (%rax)
jge 0x1842b
movq %rcx, 0x48(%rsp)
jmp 0x18430
movq %rcx, 0x40(%rsp)
movq (%rax), %rcx
leaq 0x40(%rsp), %rdx
leaq 0x104(%rsp), %r15
movq 0xc8(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x48(%rsp), %r8
movq %r15, %r9
callq 0xfb6d
movq %rax, 0xb8(%rsp)
movl 0xc(%rbp), %eax
cmpl (%r15), %eax
jne 0x190e7
movslq (%rbp), %rdi
shlq $0x3, %rdi
leaq 0xb3d3(%rip), %rsi      # 0x23850
leaq 0xb77e(%rip), %rcx      # 0x23c02
movl $0x2eb, %edx            # imm = 0x2EB
callq 0x1e045
movq %rax, 0x88(%rsp)
movslq (%rbp), %rdi
xorl %eax, %eax
testl %edi, %edi
movl $0x0, %ecx
cmovgl %edi, %ecx
pushq $0x10
popq %rdx
movq 0x88(%rsp), %r8
cmpq %rax, %rcx
je 0x184d1
movq 0x20(%rbp), %rsi
movl (%rsi,%rdx), %esi
shlq $0x20, %rsi
addq %rax, %rsi
movq %rsi, (%r8,%rax,8)
incq %rax
addq $0x18, %rdx
jmp 0x184b1
movq 0x88(%rsp), %r14
movq %r14, %rsi
callq 0xbee3
cvtsi2sd %ebx, %xmm0
mulsd 0x82a3(%rip), %xmm0     # 0x20790
movsd %xmm0, 0xf0(%rsp)
movl (%rbp), %r12d
movq 0x18(%rsp), %rax
addq $0xc4, %rax
movq %rax, 0xe0(%rsp)
leaq (%r14,%r12,8), %rax
movq %rax, 0xd0(%rsp)
movq 0xb8(%rsp), %rax
decq %rax
movq %rax, 0xe8(%rsp)
movq %r12, %r11
movq 0x140(%rsp), %r9
testl %r11d, %r11d
jle 0x1909c
movq %r12, 0xb0(%rsp)
movq %r11, %rax
decq %rax
movq %rax, 0xa0(%rsp)
movl %eax, %ecx
movq 0x88(%rsp), %rax
movq %rcx, 0xa8(%rsp)
movl (%rax,%rcx,8), %eax
imulq $0x18, %rax, %r10
addq 0x20(%rbp), %r10
movq (%r9), %r12
xorl %ebp, %ebp
movq %r10, 0x8(%rsp)
subq $0x1, %r12
jb 0x18862
movq 0x18(%r9), %r14
movq (%r10), %rbx
movq (%r14,%rbp), %r13
movq %rbx, %rax
subq %r13, %rax
jl 0x186dd
movslq 0xc(%r10), %rdi
leaq (%rbx,%rdi), %rcx
movq 0x8(%r14,%rbp), %rsi
movq %rsi, %r15
subq %rcx, %r15
jl 0x186dd
movslq 0x8(%r10), %rcx
movl 0x10(%r14,%rbp), %r8d
movq %rcx, 0x10(%rsp)
cmpl %r8d, %ecx
jl 0x186dd
movq 0x10(%rsp), %rcx
addl %edi, %ecx
movl 0x14(%r14,%rbp), %edx
movq %rdx, 0x58(%rsp)
subl %ecx, %edx
movl %edx, 0x30(%rsp)
jl 0x186dd
movl 0x44(%r14,%rbp), %ecx
movl %edi, %edx
subl %ecx, %edx
cvtsi2sd %edx, %xmm0
ucomisd 0xf0(%rsp), %xmm0
ja 0x186dd
movq %rdi, 0x80(%rsp)
movq %rsi, 0x38(%rsp)
movq %r11, 0x28(%rsp)
movq 0x10(%rsp), %rcx
movl %r8d, 0x78(%rsp)
subl %r8d, %ecx
movslq %ecx, %rsi
movq %rax, %rcx
subq %rsi, %rcx
movq %rcx, 0x50(%rsp)
cmovlq %rax, %rsi
movq 0x18(%rsp), %rdi
callq 0x19106
movl 0x34(%r14,%rbp), %esi
cmpl %esi, %eax
jl 0x1864d
movl %esi, %eax
movq 0x50(%rsp), %rdi
movq %rdi, %rcx
negq %rcx
cltq
cmpq %rax, %rcx
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r11
movq 0x38(%rsp), %rcx
movq 0x80(%rsp), %rdx
movl 0x78(%rsp), %r8d
jge 0x18680
cmpq %rax, %rdi
jl 0x186e6
movl %esi, 0x50(%rsp)
movslq 0x30(%rsp), %rsi
movq %r15, %r14
subq %rsi, %r14
cmovlq %r15, %rsi
movq 0x18(%rsp), %rdi
callq 0x19106
movl 0x50(%rsp), %ecx
cmpl %ecx, %eax
jl 0x186a7
movl %ecx, %eax
movq %r14, %rcx
negq %rcx
cltq
cmpq %rax, %rcx
movq 0x140(%rsp), %r9
movq 0x8(%rsp), %r10
movq 0x28(%rsp), %r11
movq 0x38(%rsp), %rcx
movq 0x80(%rsp), %rdx
movl 0x78(%rsp), %r8d
jge 0x186dd
cmpq %rax, %r14
jl 0x186e6
addq $0x60, %rbp
jmp 0x1857d
leaq 0x14753(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
movq 0x70(%rsp), %rbp
movq 0xb0(%rsp), %r12
jl 0x18741
subq $0x8, %rsp
leaq 0xb506(%rip), %rdi      # 0x23c10
movq %rcx, %r10
movq 0xa8(%rsp), %rsi
movq 0x18(%rsp), %rcx
movl %r8d, %r9d
movq %rbx, %r8
xorl %eax, %eax
pushq %r10
pushq %r13
pushq 0x70(%rsp)
callq 0x3060
movq 0x48(%rsp), %r11
movq 0x28(%rsp), %r10
addq $0x20, %rsp
movl (%rbp), %r12d
movq 0xd0(%rsp), %rax
cmpl %r11d, %r12d
jle 0x18804
movq (%rax), %rdx
testq %rdx, %rdx
je 0x187f8
movq 0x20(%rbp), %rcx
movl %edx, %edx
imulq $0x18, %rdx, %rdi
movl 0xc(%rcx,%rdi), %edx
cvtsi2sd %edx, %xmm0
movl 0xc(%r10), %esi
cvtsi2sd %esi, %xmm1
mulsd 0xb0a0(%rip), %xmm1     # 0x23820
ucomisd %xmm0, %xmm1
ja 0x187f8
addq %rdi, %rcx
movl 0x8(%r10), %r9d
movl 0x8(%rcx), %r8d
movl %r9d, %edi
subl %r8d, %edi
jg 0x187d8
leal (%r9,%rsi), %r10d
subl %r8d, %r10d
movq %r11, %r14
movl %esi, %r11d
sarl $0x2, %r11d
cmpl %r11d, %r10d
movq %r14, %r11
movq 0x8(%rsp), %r10
jl 0x187d8
movl %r8d, %r10d
subl %r9d, %r10d
movslq %r10d, %r10
movq (%rcx), %r11
movq 0x8(%rsp), %rbx
subq (%rbx), %r11
cmpq %r10, %r11
movq %r14, %r11
movq 0x8(%rsp), %r10
jne 0x18804
cmpl %r9d, %r8d
jg 0x187f8
subl %r9d, %edx
addl %r8d, %edx
sarl $0x2, %esi
cmpl %esi, %edx
jl 0x187f8
movslq %edi, %rdx
movq (%r10), %rsi
subq (%rcx), %rsi
cmpq %rdx, %rsi
jne 0x18804
addq $0x8, %rax
incl %r11d
jmp 0x18749
cmpl %r11d, %r12d
jne 0x1882b
movq 0x88(%rsp), %rax
movq 0xa8(%rsp), %rcx
andq $0x0, (%rax,%rcx,8)
movq 0x140(%rsp), %r9
jmp 0x19086
leaq 0x1460e(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
movq 0x140(%rsp), %r9
jl 0x18862
leaq 0xb428(%rip), %rdi      # 0x23c6e
movq 0xa0(%rsp), %rsi
xorl %eax, %eax
callq 0x3060
movq 0x8(%rsp), %r10
movq 0x140(%rsp), %r9
movq (%r9), %rax
movq 0x18(%r9), %rbx
cmpq 0x8(%r9), %rax
movq 0x70(%rsp), %rbp
jne 0x188bc
leaq (%rax,%rax), %rcx
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r9)
imulq $0x60, %rcx, %rsi
movq %rbx, %rdi
leaq 0xafbc(%rip), %rdx      # 0x23850
movl $0x319, %ecx            # imm = 0x319
leaq 0xb362(%rip), %r8       # 0x23c02
callq 0x1e0b4
movq 0x8(%rsp), %r10
movq 0x140(%rsp), %r9
movq %rax, %rbx
movq %rax, 0x18(%r9)
movq (%r9), %rax
leaq 0x1(%rax), %rcx
movq %rcx, (%r9)
imulq $0x60, %rax, %r14
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%rbx,%r14)
movupd %xmm0, 0x40(%rbx,%r14)
movupd %xmm0, 0x30(%rbx,%r14)
movupd %xmm0, 0x20(%rbx,%r14)
movupd %xmm0, 0x10(%rbx,%r14)
movupd %xmm0, (%rbx,%r14)
movq 0x18(%rsp), %rax
movl 0x24(%rax), %r15d
movl %r15d, 0x34(%rbx,%r14)
orq $-0x1, 0x1c(%rbx,%r14)
movslq 0xc(%rbp), %rax
movl %eax, 0x18(%rbx,%r14)
leaq 0x14528(%rip), %rcx     # 0x2ce40
cmpl $0x4, (%rcx)
jl 0x18960
movslq 0xc(%r10), %rdx
movslq 0x8(%r10), %rcx
movq (%r10), %r8
movq 0xc8(%rsp), %rsi
movq 0x10(%rsi), %rsi
imulq $0x28, %rax, %rax
movq 0x18(%rsi,%rax), %r9
leaq 0xb395(%rip), %rdi      # 0x23cd9
movq 0xa0(%rsp), %rsi
xorl %eax, %eax
callq 0xcda0
movq 0x8(%rsp), %r10
movq 0x140(%rsp), %r9
leaq (%rbx,%r14), %rdx
leaq (%rbx,%r14), %rax
addq $0x1c, %rax
movq %rax, 0x30(%rsp)
movslq 0x8(%r10), %rdi
testq %rdi, %rdi
leaq 0xabfd(%rip), %r12      # 0x2357c
movq %rdx, 0xc0(%rsp)
je 0x18c9d
leaq 0xaebc(%rip), %rsi      # 0x23850
movl $0x323, %edx            # imm = 0x323
leaq 0xb262(%rip), %rcx      # 0x23c02
callq 0x1e045
movq 0x8(%rsp), %rdi
movq %rax, %r13
pushq $-0x1
popq %rax
xorl %ecx, %ecx
movq 0xd8(%rsp), %rsi
movslq 0x8(%rdi), %rdx
cmpq %rdx, %rcx
jge 0x189d7
addl %eax, %edx
movslq %edx, %rdx
movb (%rsi,%rdx), %dl
movb %dl, (%r13,%rcx)
incq %rcx
decl %eax
jmp 0x189ba
movq (%rdi), %rbp
subq 0x40(%rsp), %rbp
movq %rbp, %rdi
leaq 0xae67(%rip), %rsi      # 0x23850
movl $0x326, %edx            # imm = 0x326
leaq 0xb20d(%rip), %rcx      # 0x23c02
callq 0x1e045
movq %rax, %r14
testq %rbp, %rbp
movl $0x0, %ebx
cmovgq %rbp, %rbx
movq 0xe8(%rsp), %rax
movq %rbp, 0x50(%rsp)
addq %rbp, %rax
xorl %ecx, %ecx
movq 0x30(%rsp), %r9
cmpq %rcx, %rbx
je 0x18a33
movb (%rax), %dl
movb %dl, (%r14,%rcx)
incq %rcx
decq %rax
jmp 0x18a20
xorl %ebp, %ebp
movl %r15d, %eax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r8
movq %r15, 0x58(%rsp)
cmpl $0x2, %ebp
je 0x18c19
movq 0x18(%rsp), %rax
movl 0x24(%rax), %eax
movl %ebp, %ecx
shll %cl, %eax
movq %rax, 0x10(%rsp)
movl (%r9), %eax
movl %eax, 0x28(%rsp)
leaq 0x143d1(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x18ae7
leaq 0xb297(%rip), %rdi      # 0x23d12
xorl %eax, %eax
callq 0x3060
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x18a9e
movzbl (%r14,%r15), %eax
movsbl (%rax,%r12), %edi
callq 0x34c0
incq %r15
jmp 0x18a85
pushq $0xa
popq %rdi
callq 0x34c0
leaq 0xb276(%rip), %rdi      # 0x23d23
xorl %eax, %eax
callq 0x3060
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
movslq 0x8(%rax), %rax
cmpq %rax, %r15
jge 0x18ada
movzbl (%r13,%r15), %eax
movsbl (%rax,%r12), %edi
callq 0x34c0
incq %r15
jmp 0x18ab7
pushq $0xa
popq %rdi
callq 0x34c0
movq 0x8(%rsp), %r8
movl 0x8(%r8), %edi
movq 0x18(%rsp), %rcx
movl (%rcx), %r12d
movl 0x8(%rcx), %eax
movq %rax, 0x38(%rsp)
movl 0xc(%rcx), %eax
movq %rax, 0x80(%rsp)
movl 0x10(%rcx), %eax
movq %rax, 0x78(%rsp)
movl 0x14(%rcx), %r15d
movl 0x1c(%rcx), %eax
movl 0x28(%rcx), %r10d
imull 0xc(%r8), %r12d
subq $0x8, %rsp
movq %r13, %rsi
movq 0x58(%rsp), %rdx
movq %r14, %rcx
pushq $0x16
popq %r8
movq 0xe8(%rsp), %r9
leaq 0xa0(%rsp), %r11
pushq %r11
leaq 0x34(%rsp), %r11
pushq %r11
leaq 0x7c(%rsp), %r11
pushq %r11
leaq 0x88(%rsp), %r11
pushq %r11
leaq 0x94(%rsp), %r11
pushq %r11
pushq %r12
pushq %r10
pushq %rax
movq 0x58(%rsp), %r12
pushq %r12
pushq %r15
pushq 0xd0(%rsp)
pushq 0xe0(%rsp)
pushq 0xa0(%rsp)
callq 0x1f008
addq $0x70, %rsp
movq 0x30(%rsp), %r9
movl %eax, (%r9)
leaq 0x142a0(%rip), %rcx     # 0x2ce40
cmpl $0x4, (%rcx)
jl 0x18be1
movl 0x98(%rsp), %r8d
leaq 0xb180(%rip), %rdi      # 0x23d34
movl 0x28(%rsp), %r15d
movl %r15d, %esi
movl %eax, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x3060
movq 0x133d9(%rip), %rax     # 0x2bfa8
movq (%rax), %rdi
callq 0x3370
movq 0x30(%rsp), %r9
movl (%r9), %eax
jmp 0x18be6
movl 0x28(%rsp), %r15d
cmpl %r15d, %eax
leaq 0xa98c(%rip), %r12      # 0x2357c
movq 0x8(%rsp), %r8
movq 0x58(%rsp), %r15
je 0x18c19
movq 0x10(%rsp), %rcx
movl %ecx, %eax
sarl %eax
sarl $0x2, %ecx
addl %eax, %ecx
incl %ebp
cmpl %ecx, 0x98(%rsp)
jge 0x18a47
movl 0x24(%rsp), %edx
testl %edx, %edx
jle 0x18c3c
movl (%r9), %edi
movq 0x18(%rsp), %rax
subl 0x1c(%rax), %edi
xorl %eax, %eax
leaq 0x64(%rsp), %rsi
leaq 0x24(%rsp), %rcx
cmpl %edi, %edx
jg 0x18c4c
movl 0x8(%r8), %eax
subl 0x6c(%rsp), %eax
leaq 0x68(%rsp), %rsi
movq %r9, %rcx
movq 0xc0(%rsp), %rbx
movl %eax, 0x10(%rbx)
movq (%r8), %rax
movslq (%rsi), %rdx
subq %rdx, %rax
movq %rax, (%rbx)
movl (%rcx), %eax
movl %eax, 0x20(%rbx)
movq %r13, %rdi
callq 0x3390
movq %r14, %rdi
callq 0x3390
movq 0x8(%rsp), %r10
movl 0x8(%r10), %esi
movl 0xc(%r10), %eax
movq 0x70(%rsp), %rbp
movl 0x20(%rsp), %ecx
movq 0x140(%rsp), %r9
movq 0x10(%rsp), %r14
jmp 0x18cc7
movl 0xc(%r10), %eax
movq 0x18(%rsp), %rcx
movl (%rcx), %ecx
imull %eax, %ecx
movl %ecx, 0x20(%rdx)
movl %ecx, 0x1c(%rdx)
andl $0x0, 0x10(%rdx)
movq (%r10), %rcx
movq %rcx, (%rdx)
xorl %esi, %esi
movl %r15d, %r14d
movl 0x20(%rsp), %ecx
movq %rdx, %rbx
addl %eax, %esi
movl %ecx, %edx
subl %esi, %edx
movl %edx, 0xb0(%rsp)
jne 0x18ce8
movl %ecx, 0x14(%rbx)
movslq %eax, %r8
addq (%r10), %r8
movq %r8, 0x8(%rbx)
jmp 0x18fd3
movq %r14, 0x10(%rsp)
movl %eax, %ebp
addq (%r10), %rbp
subq 0x40(%rsp), %rbp
testl %ebp, %ebp
js 0x190c8
movq 0x30(%rsp), %rax
movl (%rax), %edx
movq %rbp, 0xf8(%rsp)
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl %esi, 0x94(%rsp)
movslq %esi, %rbx
addq 0xd8(%rsp), %rbx
movq 0xb8(%rsp), %rax
leaq (%rax,%rbp), %r13
xorl %ecx, %ecx
movl 0xb0(%rsp), %eax
testl %eax, %eax
movl $0x0, %r12d
cmovgl %eax, %r12d
movq %rdx, 0xa8(%rsp)
movl %edx, %r14d
cmpl $0x2, %ecx
je 0x18f3f
movq 0x18(%rsp), %rax
movl 0x24(%rax), %eax
movl %ecx, 0x28(%rsp)
shll %cl, %eax
movq %rax, 0x58(%rsp)
leaq 0x140cb(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x18dff
leaq 0xb00c(%rip), %rdi      # 0x23d91
xorl %eax, %eax
callq 0x3060
xorl %r15d, %r15d
movq 0x48(%rsp), %rax
movq 0x40(%rsp), %rcx
addq %rbp, %rcx
subq %rcx, %rax
cmpq %r15, %rax
jle 0x18dbf
movzbl (%r13,%r15), %eax
leaq 0xa7cb(%rip), %rcx      # 0x2357c
movsbl (%rax,%rcx), %edi
callq 0x34c0
incq %r15
jmp 0x18d8f
pushq $0xa
popq %rdi
callq 0x34c0
leaq 0xafd5(%rip), %rdi      # 0x23da3
xorl %eax, %eax
callq 0x3060
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x18df7
movzbl (%rbx,%r15), %eax
leaq 0xa793(%rip), %rcx      # 0x2357c
movsbl (%rax,%rcx), %edi
callq 0x34c0
incq %r15
jmp 0x18dd8
pushq $0xa
popq %rdi
callq 0x34c0
movl 0x48(%rsp), %edx
movl 0x40(%rsp), %eax
addl 0xf8(%rsp), %eax
subl %eax, %edx
movq 0x18(%rsp), %rcx
movl 0x8(%rcx), %eax
movq %rax, 0x38(%rsp)
movl 0xc(%rcx), %eax
movq %rax, 0x80(%rsp)
movl 0x10(%rcx), %eax
movq %rax, 0x78(%rsp)
movl 0x14(%rcx), %eax
movq %rax, 0x50(%rsp)
movl 0x20(%rcx), %eax
movl 0x28(%rcx), %r10d
subq $0x8, %rsp
movl 0xb8(%rsp), %edi
movq %rbx, %rsi
movq %r13, %rcx
pushq $0x16
popq %r8
movq 0xe8(%rsp), %r9
leaq 0xa4(%rsp), %r11
pushq %r11
leaq 0x34(%rsp), %r11
pushq %r11
leaq 0x7c(%rsp), %r11
pushq %r11
leaq 0x88(%rsp), %r11
pushq %r11
leaq 0x94(%rsp), %r11
pushq %r11
pushq 0xd8(%rsp)
pushq %r10
pushq %rax
movq 0xa0(%rsp), %r15
pushq %r15
pushq 0xa0(%rsp)
pushq 0xd0(%rsp)
pushq 0xe0(%rsp)
pushq 0xa0(%rsp)
callq 0x1f008
addq $0x70, %rsp
movq 0x30(%rsp), %rcx
movl %eax, (%rcx)
leaq 0x13f71(%rip), %rcx     # 0x2ce40
cmpl $0x4, (%rcx)
jl 0x18f08
movl 0x9c(%rsp), %r8d
leaq 0xaed2(%rip), %rdi      # 0x23db5
movl %r14d, %esi
movl %eax, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3060
movq 0x130af(%rip), %rax     # 0x2bfa8
movq (%rax), %rdi
callq 0x3370
movq 0x30(%rsp), %rax
movl (%rax), %eax
movq 0x140(%rsp), %r9
movq 0x8(%rsp), %r10
cmpl %r14d, %eax
movl 0x28(%rsp), %ecx
je 0x18f3f
movl %r15d, %esi
sarl %esi
movl %r15d, %edx
sarl $0x2, %edx
addl %esi, %edx
incl %ecx
movl %eax, %r14d
cmpl %edx, 0x9c(%rsp)
jge 0x18d52
jmp 0x18f42
movl %r14d, %eax
movl 0x24(%rsp), %esi
testl %esi, %esi
jle 0x18f90
movl %eax, %edi
movq 0x18(%rsp), %rcx
subl 0x20(%rcx), %edi
movq 0x40(%rsp), %rdx
movq 0xc0(%rsp), %rbx
movl 0x20(%rbx), %ecx
cmpl %edi, %esi
movl 0x20(%rsp), %esi
movq 0x10(%rsp), %r14
movl 0x94(%rsp), %edi
jle 0x18fac
movl %esi, 0x14(%rbx)
addq %rbp, %rdx
movslq 0x64(%rsp), %r8
addq %rdx, %r8
movq %r8, 0x8(%rbx)
movl 0x24(%rsp), %eax
jmp 0x18fc2
movq 0x40(%rsp), %rdx
movq 0xc0(%rsp), %rbx
movl 0x20(%rbx), %ecx
movq 0x10(%rsp), %r14
movl 0x94(%rsp), %edi
addl 0x6c(%rsp), %edi
movl %edi, 0x14(%rbx)
addq %rbp, %rdx
movslq 0x68(%rsp), %r8
addq %rdx, %r8
movq %r8, 0x8(%rbx)
subl 0xa8(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x20(%rbx)
movq 0x70(%rsp), %rbp
leaq 0x13e66(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x1900f
movl 0x10(%rbx), %esi
movl 0x14(%rbx), %edx
movq (%rbx), %rcx
movl 0x1c(%rbx), %r9d
leaq 0xae18(%rip), %rdi      # 0x23e0b
xorl %eax, %eax
pushq %r15
pushq %r14
callq 0x3060
movq 0x18(%rsp), %r10
movq 0x150(%rsp), %r9
addq $0x10, %rsp
andl $0x0, 0x38(%rbx)
movl (%rbp), %r12d
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
imulq $0x18, %rcx, %rcx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x1906a
movq 0x20(%rbp), %rdi
movl 0x8(%rdi,%rax), %r8d
cmpl 0x10(%rbx), %r8d
jl 0x19064
movslq 0xc(%rdi,%rax), %rsi
addl %esi, %r8d
cmpl 0x14(%rbx), %r8d
jg 0x19064
movq (%rdi,%rax), %rdi
cmpq (%rbx), %rdi
jl 0x19064
addq %rsi, %rdi
cmpq 0x8(%rbx), %rdi
jg 0x19064
addl %esi, %edx
movl %edx, 0x38(%rbx)
addq $0x18, %rax
jmp 0x1902b
cmpl %r15d, %r14d
cmovgl %r14d, %r15d
movl %r15d, 0x34(%rbx)
movl 0xc(%r10), %eax
movl %eax, 0x44(%rbx)
movss 0x14(%rbp), %xmm0
movss %xmm0, 0x50(%rbx)
addq $-0x8, 0xd0(%rsp)
movq 0xa0(%rsp), %r11
jmp 0x18537
movq 0x88(%rsp), %rdi
callq 0x3390
movq 0xb8(%rsp), %rdi
callq 0x3390
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xacba(%rip), %rdi      # 0x23d89
leaq 0xa77a(%rip), %rsi      # 0x23850
leaq 0xaaa1(%rip), %rcx      # 0x23b7e
movl $0x343, %edx            # imm = 0x343
callq 0x31a0
leaq 0xaa82(%rip), %rdi      # 0x23b70
leaq 0xa75b(%rip), %rsi      # 0x23850
leaq 0xaa82(%rip), %rcx      # 0x23b7e
movl $0x2e9, %edx            # imm = 0x2E9
callq 0x31a0