// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwamem_pair.c
// Function: mem_sam_pe
int mem_sam_pe(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_pestat_t pes[4], uint64_t id, bseq1_t s[2], mem_alnreg_v a[2])
{
	extern int mem_mark_primary_se(const mem_opt_t *opt, int n, mem_alnreg_t *a, int64_t id);
	extern int mem_approx_mapq_se(const mem_opt_t *opt, const mem_alnreg_t *a);
	extern void mem_reg2sam(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, bseq1_t *s, mem_alnreg_v *a, int extra_flag, const mem_aln_t *m);
	extern char **mem_gen_alt(const mem_opt_t *opt, const bntseq_t *bns, const uint8_t *pac, const mem_alnreg_v *a, int l_query, const char *query);

	int n = 0, i, j, z[2], o, subo, n_sub, extra_flag = 1, n_pri[2], n_aa[2];
	kstring_t str;
	mem_aln_t h[2], g[2], aa[2][2];

	str.l = str.m = 0; str.s = 0;
	memset(h, 0, sizeof(mem_aln_t) * 2);
	memset(g, 0, sizeof(mem_aln_t) * 2);
	n_aa[0] = n_aa[1] = 0;
	if (!(opt->flag & MEM_F_NO_RESCUE)) { // then perform SW for the best alignment
		mem_alnreg_v b[2];
		kv_init(b[0]); kv_init(b[1]);
		for (i = 0; i < 2; ++i)
			for (j = 0; j < a[i].n; ++j)
				if (a[i].a[j].score >= a[i].a[0].score  - opt->pen_unpaired)
					kv_push(mem_alnreg_t, b[i], a[i].a[j]);
		for (i = 0; i < 2; ++i)
			for (j = 0; j < b[i].n && j < opt->max_matesw; ++j)
				n += mem_matesw(opt, bns, pac, pes, &b[i].a[j], s[!i].l_seq, (uint8_t*)s[!i].seq, &a[!i]);
		free(b[0].a); free(b[1].a);
	}
	n_pri[0] = mem_mark_primary_se(opt, a[0].n, a[0].a, id<<1|0);
	n_pri[1] = mem_mark_primary_se(opt, a[1].n, a[1].a, id<<1|1);
	if (opt->flag&MEM_F_NOPAIRING) goto no_pairing;
	// pairing single-end hits
	if (n_pri[0] && n_pri[1] && (o = mem_pair(opt, bns, pac, pes, s, a, id, &subo, &n_sub, z, n_pri)) > 0) {
		int is_multi[2], q_pe, score_un, q_se[2];
		char **XA[2];
		// check if an end has multiple hits even after mate-SW
		for (i = 0; i < 2; ++i) {
			for (j = 1; j < n_pri[i]; ++j)
				if (a[i].a[j].secondary < 0 && a[i].a[j].score >= opt->T) break;
			is_multi[i] = j < n_pri[i]? 1 : 0;
		}
		if (is_multi[0] || is_multi[1]) goto no_pairing; // TODO: in rare cases, the true hit may be long but with low score
		// compute mapQ for the best SE hit
		score_un = a[0].a[0].score + a[1].a[0].score - opt->pen_unpaired;
		//q_pe = o && subo < o? (int)(MEM_MAPQ_COEF * (1. - (double)subo / o) * log(a[0].a[z[0]].seedcov + a[1].a[z[1]].seedcov) + .499) : 0;
		subo = subo > score_un? subo : score_un;
		q_pe = raw_mapq(o - subo, opt->a);
		if (n_sub > 0) q_pe -= (int)(4.343 * log(n_sub+1) + .499);
		if (q_pe < 0) q_pe = 0;
		if (q_pe > 60) q_pe = 60;
		q_pe = (int)(q_pe * (1. - .5 * (a[0].a[0].frac_rep + a[1].a[0].frac_rep)) + .499);
		// the following assumes no split hits
		if (o > score_un) { // paired alignment is preferred
			mem_alnreg_t *c[2];
			c[0] = &a[0].a[z[0]]; c[1] = &a[1].a[z[1]];
			for (i = 0; i < 2; ++i) {
				if (c[i]->secondary >= 0)
					c[i]->sub = a[i].a[c[i]->secondary].score, c[i]->secondary = -2;
				q_se[i] = mem_approx_mapq_se(opt, c[i]);
			}
			q_se[0] = q_se[0] > q_pe? q_se[0] : q_pe < q_se[0] + 40? q_pe : q_se[0] + 40;
			q_se[1] = q_se[1] > q_pe? q_se[1] : q_pe < q_se[1] + 40? q_pe : q_se[1] + 40;
			extra_flag |= 2;
			// cap at the tandem repeat score
			q_se[0] = q_se[0] < raw_mapq(c[0]->score - c[0]->csub, opt->a)? q_se[0] : raw_mapq(c[0]->score - c[0]->csub, opt->a);
			q_se[1] = q_se[1] < raw_mapq(c[1]->score - c[1]->csub, opt->a)? q_se[1] : raw_mapq(c[1]->score - c[1]->csub, opt->a);
		} else { // the unpaired alignment is preferred
			z[0] = z[1] = 0;
			q_se[0] = mem_approx_mapq_se(opt, &a[0].a[0]);
			q_se[1] = mem_approx_mapq_se(opt, &a[1].a[0]);
		}
		for (i = 0; i < 2; ++i) {
			int k = a[i].a[z[i]].secondary_all;
			if (k >= 0 && k < n_pri[i]) { // switch secondary and primary if both of them are non-ALT
				assert(a[i].a[k].secondary_all < 0);
				for (j = 0; j < a[i].n; ++j)
					if (a[i].a[j].secondary_all == k || j == k)
						a[i].a[j].secondary_all = z[i];
				a[i].a[z[i]].secondary_all = -1;
			}
		}
		if (!(opt->flag & MEM_F_ALL)) {
			for (i = 0; i < 2; ++i)
				XA[i] = mem_gen_alt(opt, bns, pac, &a[i], s[i].l_seq, s[i].seq);
		} else XA[0] = XA[1] = 0;
		// write SAM
		for (i = 0; i < 2; ++i) {
			h[i] = mem_reg2aln(opt, bns, pac, s[i].l_seq, s[i].seq, &a[i].a[z[i]]);
			h[i].mapq = q_se[i];
			h[i].flag |= 0x40<<i | extra_flag;
			h[i].XA = XA[i]? XA[i][z[i]] : 0;
			aa[i][n_aa[i]++] = h[i];
			if (n_pri[i] < a[i].n) { // the read has ALT hits
				mem_alnreg_t *p = &a[i].a[n_pri[i]];
				if (p->score < opt->T || p->secondary >= 0 || !p->is_alt) continue;
				g[i] = mem_reg2aln(opt, bns, pac, s[i].l_seq, s[i].seq, p);
				g[i].flag |= 0x800 | 0x40<<i | extra_flag;
				g[i].XA = XA[i]? XA[i][n_pri[i]] : 0;
				aa[i][n_aa[i]++] = g[i];
			}
		}
		for (i = 0; i < n_aa[0]; ++i)
			mem_aln2sam(opt, bns, &str, &s[0], n_aa[0], aa[0], i, &h[1]); // write read1 hits
		s[0].sam = strdup(str.s); str.l = 0;
		for (i = 0; i < n_aa[1]; ++i)
			mem_aln2sam(opt, bns, &str, &s[1], n_aa[1], aa[1], i, &h[0]); // write read2 hits
		s[1].sam = str.s;
		if (strcmp(s[0].name, s[1].name) != 0) err_fatal(__func__, "paired reads have different names: \"%s\", \"%s\"\n", s[0].name, s[1].name);
		// free
		for (i = 0; i < 2; ++i) {
			free(h[i].cigar); free(g[i].cigar);
			if (XA[i] == 0) continue;
			for (j = 0; j < a[i].n; ++j) free(XA[i][j]);
			free(XA[i]);
		}
	} else goto no_pairing;
	return n;

no_pairing:
	for (i = 0; i < 2; ++i) {
		int which = -1;
		if (a[i].n) {
			if (a[i].a[0].score >= opt->T) which = 0;
			else if (n_pri[i] < a[i].n && a[i].a[n_pri[i]].score >= opt->T)
				which = n_pri[i];
		}
		if (which >= 0) h[i] = mem_reg2aln(opt, bns, pac, s[i].l_seq, s[i].seq, &a[i].a[which]);
		else h[i] = mem_reg2aln(opt, bns, pac, s[i].l_seq, s[i].seq, 0);
	}
	if (!(opt->flag & MEM_F_NOPAIRING) && h[0].rid == h[1].rid && h[0].rid >= 0) { // if the top hits from the two ends constitute a proper pair, flag it.
		int64_t dist;
		int d;
		d = mem_infer_dir(bns->l_pac, a[0].a[0].rb, a[1].a[0].rb, &dist);
		if (!pes[d].failed && dist >= pes[d].low && dist <= pes[d].high) extra_flag |= 2;
	}
	mem_reg2sam(opt, bns, pac, &s[0], &a[0], 0x41|extra_flag, &h[1]);
	mem_reg2sam(opt, bns, pac, &s[1], &a[1], 0x81|extra_flag, &h[0]);
	if (strcmp(s[0].name, s[1].name) != 0) err_fatal(__func__, "paired reads have different names: \"%s\", \"%s\"\n", s[0].name, s[1].name);
	free(h[0].cigar); free(h[1].cigar);
	return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %r9, 0x20(%rsp)
movq %r8, %r15
movq %rcx, 0x58(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r10
movq 0x300(%rsp), %r13
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movq $0x0, 0xa0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x190(%rsp)
movapd %xmm0, 0x1a0(%rsp)
movapd %xmm0, 0x1b0(%rsp)
movapd %xmm0, 0x1c0(%rsp)
movapd %xmm0, 0x1d0(%rsp)
xorl %eax, %eax
movl %eax, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
movl %eax, 0x64(%rsp)
testb $0x20, 0x48(%rdi)
movq %rdi, 0x8(%rsp)
jne 0x2103a
movq %r15, 0x48(%rsp)
leaq 0x200(%rsp), %rax
xorl %ebp, %ebp
movq %rbp, 0x18(%rax)
movapd %xmm0, -0x20(%rax)
movupd %xmm0, -0x8(%rax)
movq %rbp, 0x8(%rax)
leaq 0x1e0(%rsp), %r14
movb $0x1, %bl
shlq $0x5, %rbp
movq (%r13,%rbp), %rax
testq %rax, %rax
je 0x20f38
addq 0x300(%rsp), %rbp
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x18(%rbp), %rsi
movl 0x1c(%rsi), %ecx
subl 0x18(%r10), %ecx
cmpl %ecx, 0x1c(%rsi,%r13)
jl 0x20f28
movq (%r14), %r12
movq 0x18(%r14), %rax
cmpq 0x8(%r14), %r12
jne 0x20f06
leaq (%r12,%r12), %rcx
testq %r12, %r12
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%r14)
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
leaq 0x8488(%rip), %rdx      # 0x29370
movl $0x10f, %ecx            # imm = 0x10F
leaq 0x8676(%rip), %r8       # 0x2956a
callq 0x2324c
movq 0x8(%rsp), %r10
movq %rax, 0x18(%r14)
movq 0x18(%rbp), %rsi
leaq 0x1(%r12), %rcx
movq %rcx, (%r14)
leaq (%r12,%r12,2), %rdi
shlq $0x5, %rdi
addq %rax, %rdi
addq %r13, %rsi
movl $0xc, %ecx
rep  movsq (%rsi), %es:(%rdi)
movq (%rbp), %rax
incq %r15
addq $0x60, %r13
cmpq %r15, %rax
ja 0x20ea3
movl $0x1, %ebp
leaq 0x200(%rsp), %r14
testb $0x1, %bl
movl $0x0, %ebx
movq 0x300(%rsp), %r13
jne 0x20e83
movq $0x0, 0x68(%rsp)
movl $0x1, %r14d
leaq 0x1e0(%rsp), %r15
movb $0x1, %al
movq %rax, 0x18(%rsp)
movq (%r15), %rbp
testq %rbp, %rbp
movq 0x20(%rsp), %rax
je 0x20ff3
leaq (%r14,%r14,2), %r12
shlq $0x4, %r12
addq %rax, %r12
shlq $0x5, %r14
addq %r13, %r14
xorl %ebx, %ebx
xorl %r13d, %r13d
movslq 0xb8(%r10), %rax
cmpq %rax, %r13
jge 0x20ff3
movq 0x18(%r15), %r8
addq %rbx, %r8
movl (%r12), %r9d
movq %r10, %rdi
movq 0x10(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x58(%rsp), %rcx
pushq %r14
pushq 0x18(%r12)
callq 0x200a9
movq 0x18(%rsp), %r10
addq $0x10, %rsp
movq 0x68(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x68(%rsp)
incq %r13
addq $0x60, %rbx
cmpq %r13, %rbp
jne 0x20f9d
xorl %r14d, %r14d
leaq 0x200(%rsp), %r15
testb $0x1, 0x18(%rsp)
movl $0x0, %eax
movq 0x300(%rsp), %r13
jne 0x20f74
movq 0x1f8(%rsp), %rdi
callq 0x3390
movq 0x218(%rsp), %rdi
callq 0x3390
movq 0x8(%rsp), %r10
movq 0x48(%rsp), %r15
leaq 0xf8(%rsp), %r12
leaq 0x2c(%rsp), %rbx
movl (%r13), %esi
movq 0x18(%r13), %rdx
leaq (%r15,%r15), %rcx
movq %r10, %rdi
callq 0x1a5f5
movl %eax, %r14d
movl %eax, -0x4(%rbx)
leaq 0x20(%r13), %rax
movq %rax, 0x18(%rsp)
movl 0x20(%r13), %esi
movq 0x38(%r13), %rdx
leaq 0x1(,%r15,2), %rcx
movq 0x8(%rsp), %rdi
callq 0x1a5f5
movq 0x8(%rsp), %r11
movl %eax, (%rbx)
testb $0x4, 0x48(%r11)
jne 0x211a3
testl %r14d, %r14d
setne %cl
testl %eax, %eax
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x211a3
subq $0x8, %rsp
leaq 0x30(%rsp), %rbx
leaq 0x58(%rsp), %r14
leaq 0x88(%rsp), %rax
leaq 0x8c(%rsp), %rdx
movq %r11, %rdi
movq 0x18(%rsp), %rsi
movq 0x60(%rsp), %rcx
movq %r13, %r9
pushq %rbx
pushq %r14
pushq %rax
pushq %rdx
pushq %r15
callq 0x207ee
movq 0x38(%rsp), %r11
addq $0x30, %rsp
testl %eax, %eax
jle 0x211a3
leaq 0x7c(%rsp), %rsi
movb $0x1, %bpl
xorl %r8d, %r8d
movl $0x9c, %ecx
leaq 0x78(%rsp), %rdx
movq 0x8(%rsp), %r15
movslq (%rbx), %rdi
movl $0x0, %r9d
cmpq $0x2, %rdi
jl 0x21175
shlq $0x5, %r8
movq 0x18(%r13,%r8), %r8
addq %rcx, %r8
movl $0x1, %r9d
subq %rdi, %r9
movb $0x1, %r10b
movl $0x2, %r11d
cmpl $0x0, (%r8)
jns 0x2114d
movl -0x20(%r8), %ebx
cmpl 0x44(%r15), %ebx
jge 0x21168
cmpq %rdi, %r11
setb %r10b
addq $0x60, %r8
leaq (%r9,%r11), %rbx
incq %rbx
incq %r11
cmpq $0x2, %rbx
jne 0x2113d
movzbl %r10b, %r9d
andl $0x1, %r9d
movq 0x8(%rsp), %r11
movl %r9d, (%rsi)
movl $0x1, %r8d
movq %rdx, %rsi
leaq 0x2c(%rsp), %rbx
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x21110
movl 0x78(%rsp), %ecx
orl 0x7c(%rsp), %ecx
je 0x2142a
leaq 0x28(%rsp), %rcx
leaq 0xc0(%rsp), %rbp
movb $0x1, %r15b
xorl %eax, %eax
leaq 0x1e0(%rsp), %r14
movq 0x20(%rsp), %rbx
movq %rax, %rdx
shlq $0x5, %rdx
movq (%r13,%rdx), %rdi
testq %rdi, %rdi
je 0x21239
addq %r13, %rdx
movq 0x18(%rdx), %r10
movl 0x44(%r11), %esi
xorl %edx, %edx
cmpl %esi, 0x1c(%r10)
jge 0x21203
movl (%rcx), %edx
movslq %edx, %rcx
cmpq %rcx, %rdi
jbe 0x21239
testl %edx, %edx
js 0x21239
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
cmpl %esi, 0x1c(%r10,%rcx)
jl 0x21239
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movl (%rbx,%rax), %r8d
movq 0x18(%rbx,%rax), %r9
movl %edx, %eax
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq %rax, %r10
subq $0x8, %rsp
movq %r14, %rdi
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %r10
jmp 0x21260
leaq (%rax,%rax,2), %rax
shlq $0x4, %rax
movl (%rbx,%rax), %r8d
movq 0x18(%rbx,%rax), %r9
subq $0x8, %rsp
movq %r14, %rdi
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq $0x0
callq 0x1e9f1
addq $0x10, %rsp
movq 0x210(%rsp), %rax
movq %rax, 0x30(%rbp)
movupd 0x1e0(%rsp), %xmm0
movupd 0x1f0(%rsp), %xmm1
movupd 0x200(%rsp), %xmm2
movupd %xmm2, 0x20(%rbp)
movupd %xmm1, 0x10(%rbp)
movupd %xmm0, (%rbp)
movl $0x1, %eax
movq %r12, %rbp
leaq 0x2c(%rsp), %rcx
testb $0x1, %r15b
movl $0x0, %r15d
movq 0x8(%rsp), %r11
jne 0x211c2
movl $0x1, %r14d
testb $0x4, 0x48(%r11)
jne 0x21370
movl 0xc8(%rsp), %eax
testl %eax, %eax
js 0x21370
cmpl 0x100(%rsp), %eax
jne 0x21370
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq 0x18(%r13), %rcx
movq 0x38(%r13), %rdx
movq (%rcx), %rcx
movq (%rdx), %rdx
cmpq %rax, %rcx
setge %sil
cmpq %rax, %rdx
setl %dil
xorb %sil, %dil
movq %rdx, %rsi
notq %rsi
leaq (%rsi,%rax,2), %rsi
cmovneq %rdx, %rsi
xorl %edx, %edx
subq %rcx, %rsi
setle %dl
movq %rsi, %rax
negq %rax
cmovsq %rsi, %rax
xorb $0x1, %dil
movzbl %dil, %esi
leal (%rdx,%rdx,2), %ecx
xorl %esi, %ecx
shll $0x5, %ecx
movq 0x58(%rsp), %rdx
cmpl $0x0, 0x8(%rdx,%rcx)
jne 0x21370
addq %rcx, %rdx
movslq (%rdx), %rcx
cmpq %rcx, %rax
jl 0x21370
movslq 0x4(%rdx), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
setle %dl
leal 0x1(,%rdx,2), %r14d
movl %r14d, %r9d
orl $0x41, %r9d
leaq 0xf8(%rsp), %rax
subq $0x8, %rsp
movq %r11, %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
movq 0x38(%rsp), %rbp
movq %rbp, %rdx
movq %rbx, %rcx
movq %r13, %r8
pushq %rax
movq %r11, %r12
callq 0x1e5f9
addq $0x10, %rsp
leaq 0x30(%rbx), %rcx
orl $0x81, %r14d
subq $0x8, %rsp
leaq 0xc8(%rsp), %rax
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq 0x20(%rsp), %r8
movl %r14d, %r9d
pushq %rax
callq 0x1e5f9
addq $0x10, %rsp
movq %rbx, %rax
movq 0x8(%rbx), %rbx
movq 0x38(%rax), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x34d0
testl %eax, %eax
jne 0x21bf4
movq 0xd8(%rsp), %rdi
callq 0x3390
movq 0x110(%rsp), %rdi
callq 0x3390
movq 0x68(%rsp), %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%r13), %rsi
movq 0x38(%r13), %rdi
movl 0x1c(%rdi), %ebx
addl 0x1c(%rsi), %ebx
subl 0x18(%r11), %ebx
movl 0x84(%rsp), %ecx
cmpl %ebx, %ecx
cmovlel %ebx, %ecx
movl %eax, %r15d
movl %eax, %edx
subl %ecx, %edx
cvtsi2sd %edx, %xmm0
mulsd 0x7e95(%rip), %xmm0     # 0x292f0
cvtsi2sdl (%r11), %xmm1
divsd %xmm1, %xmm0
addsd 0x4334(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebp
movl 0x80(%rsp), %ecx
testl %ecx, %ecx
jle 0x214ac
incl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
callq 0x3250
movq 0x8(%rsp), %r11
mulsd 0x7412(%rip), %xmm0     # 0x288a8
addsd 0x4302(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %eax
subl %eax, %ebp
movq 0x18(%r13), %rsi
movq 0x38(%r13), %rdi
xorl %edx, %edx
testl %ebp, %ebp
cmovgl %ebp, %edx
cmpl $0x3c, %edx
movl $0x3c, %ecx
cmovll %edx, %ecx
cmpl %ebx, %r15d
jle 0x21639
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movss 0x50(%rsi), %xmm1
addss 0x50(%rdi), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x7e14(%rip), %xmm1     # 0x292f8
addsd 0x7044(%rip), %xmm1     # 0x28530
mulsd %xmm0, %xmm1
addsd 0x42a8(%rip), %xmm1     # 0x257a0
cvttsd2si %xmm1, %ebp
movslq 0x50(%rsp), %rcx
leaq (%rcx,%rcx,2), %rbx
shlq $0x5, %rbx
addq %rsi, %rbx
movslq 0x54(%rsp), %rcx
leaq (%rcx,%rcx,2), %r15
shlq $0x5, %r15
addq %rdi, %r15
leaq 0x38(%rsp), %r13
movb $0x1, %r12b
xorl %eax, %eax
movq %rbx, %rsi
movslq 0x3c(%rsi), %rcx
testq %rcx, %rcx
js 0x21559
shlq $0x5, %rax
movq 0x300(%rsp), %rdx
movq 0x18(%rdx,%rax), %rax
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
movl 0x1c(%rax,%rcx), %eax
movl %eax, 0x24(%rsi)
movl $0xfffffffe, 0x3c(%rsi) # imm = 0xFFFFFFFE
movq %r11, %rdi
callq 0x1e409
movq 0x8(%rsp), %r11
movl %eax, (%r13)
movl $0x1, %eax
movq %r15, %rsi
leaq 0x3c(%rsp), %r13
testb $0x1, %r12b
movl $0x0, %r12d
jne 0x21529
cvtsi2sdl (%r11), %xmm2
movq 0x38(%rsp), %xmm1
movd %ebp, %xmm0
pshufd $0x50, %xmm0, %xmm3     # xmm3 = xmm0[0,0,1,1]
movdqa %xmm1, %xmm0
pcmpgtd %xmm3, %xmm0
movdqa 0x7da9(%rip), %xmm4     # 0x29350
paddd %xmm1, %xmm4
movdqa %xmm3, %xmm5
pcmpgtd %xmm4, %xmm5
pand %xmm5, %xmm4
pandn %xmm3, %xmm5
por %xmm4, %xmm5
pand %xmm0, %xmm1
pandn %xmm5, %xmm0
movd 0x1c(%r15), %xmm3
movd 0x1c(%rbx), %xmm4
punpckldq %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1]
movd 0x2c(%r15), %xmm3
movd 0x2c(%rbx), %xmm5
punpckldq %xmm3, %xmm5    # xmm5 = xmm5[0],xmm3[0],xmm5[1],xmm3[1]
psubd %xmm5, %xmm4
cvtdq2pd %xmm4, %xmm3
mulpd 0x7d6b(%rip), %xmm3     # 0x29360
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm3
addpd 0x7d0b(%rip), %xmm3     # 0x29310
cvttpd2dq %xmm3, %xmm2
por %xmm1, %xmm0
movapd %xmm2, %xmm1
pcmpgtd %xmm0, %xmm1
pand %xmm1, %xmm0
pandn %xmm2, %xmm1
por %xmm0, %xmm1
movq %xmm1, 0x38(%rsp)
movl $0x3, 0x44(%rsp)
movq 0x300(%rsp), %r13
jmp 0x2166d
movq $0x0, 0x50(%rsp)
movq %r11, %rdi
callq 0x1e409
movl %eax, 0x38(%rsp)
movq 0x38(%r13), %rsi
movq 0x8(%rsp), %rdi
callq 0x1e409
movq 0x8(%rsp), %r11
movl %eax, 0x3c(%rsp)
movl $0x1, 0x44(%rsp)
leaq 0x28(%rsp), %r9
movb $0x1, %al
xorl %r8d, %r8d
movq 0x20(%rsp), %rbx
shlq $0x5, %r8
movq 0x18(%r13,%r8), %rcx
movslq (%r14), %rsi
leaq (%rsi,%rsi,2), %rdx
shlq $0x5, %rdx
movslq 0x40(%rcx,%rdx), %rdi
testq %rdi, %rdi
js 0x216eb
cmpl (%r9), %edi
jge 0x216eb
leaq (%rdi,%rdi,2), %r9
shlq $0x5, %r9
cmpl $0x0, 0x40(%rcx,%r9)
jns 0x21c0f
addq %r13, %r8
movq (%r8), %r8
testq %r8, %r8
je 0x216de
leaq 0x40(%rcx), %r9
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0x216cf
cmpl %edi, (%r9)
jne 0x216d2
movl %esi, (%r9)
incq %r10
addq $0x60, %r9
cmpq %r10, %r8
jne 0x216c5
addq %rdx, %rcx
addq $0x40, %rcx
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movl $0x1, %r8d
leaq 0x2c(%rsp), %r9
leaq 0x54(%rsp), %r14
testb $0x1, %al
movl $0x0, %eax
jne 0x2167c
testb $0x8, 0x48(%r11)
jne 0x2175a
movl (%rbx), %r8d
movq 0x18(%rbx), %r9
movq %r11, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x30(%rsp), %r15
movq %r15, %rdx
movq %r13, %rcx
callq 0x22875
movq %rax, 0x70(%rsp)
movl 0x30(%rbx), %r8d
movq 0x48(%rbx), %r9
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq 0x18(%rsp), %rcx
callq 0x22875
movq 0x8(%rsp), %r11
jmp 0x21765
movq $0x0, 0x70(%rsp)
xorl %eax, %eax
leaq 0x88(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x50(%rsp), %rax
leaq 0x28(%rsp), %rsi
leaq 0x64(%rsp), %r12
leaq 0xc0(%rsp), %r15
leaq 0x170(%rsp), %rdx
leaq 0x38(%rsp), %rbp
leaq 0x70(%rsp), %rdi
movb $0x1, %cl
xorl %ebx, %ebx
movq %rdi, 0x48(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0xb0(%rsp)
movl %ecx, 0x58(%rsp)
leaq (%rbx,%rbx,2), %rdx
shlq $0x4, %rdx
movq 0x20(%rsp), %rcx
movl (%rcx,%rdx), %r8d
movq %rdx, 0xa8(%rsp)
movq 0x18(%rcx,%rdx), %r9
movq %rbx, %r14
shlq $0x5, %r14
movslq (%rax), %rax
movq %rax, 0xb8(%rsp)
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq 0x18(%r13,%r14), %rax
subq $0x8, %rsp
leaq 0x140(%rsp), %rdi
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %rax
callq 0x1e9f1
addq $0x10, %rsp
movq 0x168(%rsp), %rax
movq %rax, 0x30(%r15)
movups 0x138(%rsp), %xmm0
movups 0x148(%rsp), %xmm1
movups 0x158(%rsp), %xmm2
movups %xmm2, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movl (%rbp), %eax
movzbl %al, %eax
movl 0x10(%r15), %edx
movl $0xfffffc03, %ecx       # imm = 0xFFFFFC03
andl %ecx, %edx
movl $0x40, %ebp
movl %ebx, %ecx
shll %cl, %ebp
leal (%rdx,%rax,4), %eax
movl %eax, 0x10(%r15)
movl 0xc(%r15), %eax
orl 0x44(%rsp), %eax
orl %ebp, %eax
movl %eax, 0xc(%r15)
movq 0x48(%rsp), %rax
movq (%rax), %rsi
testq %rsi, %rsi
je 0x2188f
movq 0xb8(%rsp), %rax
movq (%rsi,%rax,8), %rax
jmp 0x21891
xorl %eax, %eax
movq 0x18(%rsp), %rdx
addq %r13, %r14
movq %rax, 0x20(%r15)
movslq (%r12), %r8
leaq 0x1(%r8), %rdi
movl %edi, (%r12)
imulq $0x70, %rbx, %rax
leaq (%rsp,%rax), %rbx
addq $0x1e0, %rbx            # imm = 0x1E0
imulq $0x38, %r8, %rax
movq 0x30(%r15), %rcx
movq %rcx, 0x30(%rax,%rbx)
movupd (%r15), %xmm0
movupd 0x10(%r15), %xmm1
movupd 0x20(%r15), %xmm2
movupd %xmm2, 0x20(%rax,%rbx)
movupd %xmm1, 0x10(%rax,%rbx)
movupd %xmm0, (%rax,%rbx)
movslq (%rdx), %r15
cmpq %r15, (%r14)
movq 0x8(%rsp), %r11
jbe 0x21a0a
movq 0x18(%r14), %rax
leaq (%r15,%r15,2), %rcx
shlq $0x5, %rcx
movl 0x1c(%rax,%rcx), %edx
cmpl 0x44(%r11), %edx
jl 0x21a0a
addq %rcx, %rax
cmpl $0x0, 0x3c(%rax)
jns 0x21a0a
cmpl $0x40000000, 0x48(%rax) # imm = 0x40000000
jb 0x21a0a
movq %r8, 0x48(%rsp)
movq %rdi, 0x18(%rsp)
movq 0xa8(%rsp), %rcx
addq 0x20(%rsp), %rcx
movl (%rcx), %r8d
movq 0x18(%rcx), %r9
subq $0x8, %rsp
leaq 0x140(%rsp), %rdi
movq %rsi, %r14
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %rax
callq 0x1e9f1
addq $0x10, %rsp
movq 0x168(%rsp), %rax
movq 0xb0(%rsp), %rdx
movq %rax, 0x30(%rdx)
movups 0x138(%rsp), %xmm0
movups 0x148(%rsp), %xmm1
movups 0x158(%rsp), %xmm2
movups %xmm2, 0x20(%rdx)
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
orl 0xc(%rdx), %ebp
orl 0x44(%rsp), %ebp
orl $0x800, %ebp            # imm = 0x800
movl %ebp, 0xc(%rdx)
testq %r14, %r14
je 0x219c2
movq (%r14,%r15,8), %rax
jmp 0x219c4
xorl %eax, %eax
movq 0x18(%rsp), %rcx
movq 0x48(%rsp), %rsi
movq %rax, 0x20(%rdx)
addl $0x2, %esi
movl %esi, (%r12)
imulq $0x38, %rcx, %rax
movq 0x30(%rdx), %rcx
movq %rcx, 0x30(%rax,%rbx)
movupd (%rdx), %xmm0
movupd 0x10(%rdx), %xmm1
movupd 0x20(%rdx), %xmm2
movupd %xmm2, 0x20(%rax,%rbx)
movupd %xmm1, 0x10(%rax,%rbx)
movupd %xmm0, (%rax,%rbx)
movq 0x8(%rsp), %r11
movl $0x1, %ebx
leaq 0x88(%rsp), %rdi
leaq 0x3c(%rsp), %rbp
leaq 0x1a8(%rsp), %rdx
leaq 0xf8(%rsp), %r15
leaq 0x60(%rsp), %r12
leaq 0x2c(%rsp), %rsi
leaq 0x54(%rsp), %rax
testb $0x1, 0x58(%rsp)
movl $0x0, %ecx
jne 0x2179d
movl 0x64(%rsp), %ebp
xorl %ebx, %ebx
testl %ebp, %ebp
jle 0x21aa7
leaq 0x90(%rsp), %r14
leaq 0x1e0(%rsp), %r15
movq 0x20(%rsp), %r13
movq 0x10(%rsp), %r12
movq %r11, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r13, %rcx
movl %ebp, %r8d
movq %r15, %r9
leaq 0xf8(%rsp), %rax
pushq %rax
pushq %rbx
callq 0x1bc0b
movq 0x18(%rsp), %r11
addq $0x10, %rsp
incl %ebx
cmpl %ebx, %ebp
jne 0x21a6f
movq 0xa0(%rsp), %rbx
leaq 0x78c2(%rip), %rsi      # 0x29370
leaq 0x7ab5(%rip), %rcx      # 0x2956a
movq %rbx, %rdi
movl $0x160, %edx            # imm = 0x160
callq 0x23285
movq 0x20(%rsp), %rcx
movq %rax, 0x28(%rcx)
movq $0x0, 0x90(%rsp)
movl 0x60(%rsp), %ebx
testl %ebx, %ebx
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %r13
jle 0x21b30
movq 0x20(%rsp), %rax
leaq 0x30(%rax), %r14
xorl %r12d, %r12d
leaq 0x90(%rsp), %rbp
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movl %ebx, %r8d
leaq 0x250(%rsp), %r9
leaq 0xc0(%rsp), %rax
pushq %rax
pushq %r12
callq 0x1bc0b
addq $0x10, %rsp
incl %r12d
cmpl %r12d, %ebx
jne 0x21afd
movq 0xa0(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rax, 0x58(%rcx)
movq 0x8(%rcx), %rbx
movq 0x38(%rcx), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x34d0
testl %eax, %eax
jne 0x21bf4
leaq 0x70(%rsp), %rbx
movb $0x1, %bpl
xorl %r15d, %r15d
leaq 0x88(%rsp), %r14
movq 0x300(%rsp), %r13
leaq 0x188(%rsp), %r12
leaq 0xd8(%rsp), %rax
movq (%rax), %rdi
callq 0x3390
movq (%r12), %rdi
callq 0x3390
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x21bcb
shlq $0x5, %r15
cmpq $0x0, (%r13,%r15)
je 0x21bc3
addq %r13, %r15
xorl %r12d, %r12d
movq (%rbx,%r12,8), %rdi
callq 0x3390
incq %r12
cmpq %r12, (%r15)
ja 0x21bb2
movq %rbx, %rdi
callq 0x3390
movl $0x1, %r15d
movq %r14, %rbx
leaq 0x1c0(%rsp), %r12
leaq 0x110(%rsp), %rax
testb $0x1, %bpl
movl $0x0, %ebp
jne 0x21b87
jmp 0x21413
leaq 0x796f(%rip), %rdi      # 0x2956a
leaq 0x7a0f(%rip), %rsi      # 0x29611
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0xe0b5
leaq 0x795f(%rip), %rdi      # 0x29575
leaq 0x7753(%rip), %rsi      # 0x29370
leaq 0x796d(%rip), %rcx      # 0x29591
movl $0x143, %edx            # imm = 0x143
callq 0x31a0
nop