// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %r8, %rbp
movq %rcx, 0x70(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r10
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x160(%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)
movq $0x0, 0x68(%rsp)
movq %rax, 0x4c(%rsp)
testb $0x20, 0x48(%rdi)
movq %r9, 0x60(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x8(%rsp)
jne 0x20b5f
movq %rbp, 0x40(%rsp)
movq %rbx, 0x30(%rsp)
xorl %r14d, %r14d
movq %r14, 0x218(%rsp)
movapd %xmm0, 0x1e0(%rsp)
movupd %xmm0, 0x1f8(%rsp)
movq %r14, 0x208(%rsp)
movq %r14, %rax
shlq $0x5, %rax
movq 0x300(%rsp), %rcx
cmpq $0x0, (%rcx,%rax)
je 0x20a54
leaq (%rcx,%rax), %r15
leaq (%rsp,%rax), %rbp
addq $0x1e0, %rbp            # imm = 0x1E0
xorl %ebx, %ebx
xorl %r13d, %r13d
movq 0x18(%r15), %rax
movl 0x1c(%rax), %ecx
subl 0x18(%r10), %ecx
cmpl %ecx, 0x1c(%rax,%rbx)
jl 0x20a44
movq (%rbp), %r12
movq 0x8(%rbp), %rax
cmpq %rax, %r12
jne 0x20a20
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rbp)
movq 0x18(%rbp), %rdi
shlq $0x5, %rcx
leaq (%rcx,%rcx,2), %rsi
leaq 0x883a(%rip), %rdx      # 0x29240
movl $0x10f, %ecx            # imm = 0x10F
leaq 0x8a28(%rip), %r8       # 0x2943a
callq 0x22d64
movq 0x8(%rsp), %r10
movq %rax, 0x18(%rbp)
leaq 0x1(%r12), %rax
movq %rax, (%rbp)
leaq (%r12,%r12,2), %rdi
shlq $0x5, %rdi
addq 0x18(%rbp), %rdi
movq 0x18(%r15), %rsi
addq %rbx, %rsi
movl $0xc, %ecx
rep  movsq (%rsi), %es:(%rdi)
incq %r13
addq $0x60, %rbx
cmpq %r13, (%r15)
ja 0x209c1
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
je 0x20993
xorl %ecx, %ecx
movq $0x0, 0x68(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
movq 0x1e0(%rsp,%rax), %r15
testq %r15, %r15
movq %rcx, 0x20(%rsp)
je 0x20b17
leaq (%rsp,%rax), %r13
addq $0x1e0, %r13            # imm = 0x1E0
movl %ecx, %ebp
xorq $0x1, %rbp
leaq (,%rbp,2), %r12
addq %rbp, %r12
shlq $0x4, %r12
addq 0x60(%rsp), %r12
shlq $0x5, %rbp
addq 0x300(%rsp), %rbp
xorl %ebx, %ebx
xorl %r14d, %r14d
movslq 0xb8(%r10), %rax
cmpq %rax, %r14
jge 0x20b17
movq 0x18(%r13), %r8
addq %rbx, %r8
movl (%r12), %r9d
movq %r10, %rdi
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdx
movq 0x70(%rsp), %rcx
pushq %rbp
pushq 0x18(%r12)
callq 0x1fbdc
movq 0x18(%rsp), %r10
addq $0x10, %rsp
movq 0x68(%rsp), %rcx
addl %eax, %ecx
movq %rcx, 0x68(%rsp)
incq %r14
addq $0x60, %rbx
cmpq %r14, %r15
jne 0x20ac2
movq 0x20(%rsp), %rcx
leaq 0x1(%rcx), %rax
testq %rcx, %rcx
movq %rax, %rcx
je 0x20a6f
movq 0x1f8(%rsp), %rdi
callq 0x3390
movq 0x218(%rsp), %rdi
callq 0x3390
movq 0x8(%rsp), %r10
movq 0x60(%rsp), %r15
movq 0x30(%rsp), %rbx
movq 0x18(%rsp), %r14
movq 0x40(%rsp), %rbp
movq 0x300(%rsp), %r12
movl (%r12), %esi
movq 0x18(%r12), %rdx
leaq (,%rbp,2), %rcx
movq %r10, %rdi
callq 0x1a040
movl %eax, %r13d
movl %eax, 0x38(%rsp)
movl 0x20(%r12), %esi
movq 0x38(%r12), %rdx
leaq 0x1(,%rbp,2), %rcx
movq 0x8(%rsp), %rdi
callq 0x1a040
movq 0x8(%rsp), %r11
movl %eax, 0x3c(%rsp)
movl $0x1, %r12d
testb $0x4, 0x48(%r11)
jne 0x20eb9
testl %r13d, %r13d
setne %cl
testl %eax, %eax
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x20eb9
subq $0x8, %rsp
leaq 0x40(%rsp), %rax
leaq 0x60(%rsp), %rdx
leaq 0x84(%rsp), %r8
leaq 0x5c(%rsp), %r10
movq %r11, %rdi
movq %r14, %rsi
movq 0x78(%rsp), %rcx
movq 0x308(%rsp), %r14
movq %r14, %r9
pushq %rax
pushq %rdx
pushq %r8
pushq %r10
pushq %rbp
callq 0x202db
movq %r14, %r10
movq 0x38(%rsp), %r11
addq $0x30, %rsp
testl %eax, %eax
jle 0x20ec1
movl %eax, %r13d
xorl %eax, %eax
movl $0x9c, %ecx
movslq 0x38(%rsp,%rax,4), %rsi
cmpq $0x2, %rsi
setge %dl
jl 0x20c82
movq %rax, %rdi
shlq $0x5, %rdi
movq 0x18(%r10,%rdi), %rdi
addq %rcx, %rdi
movl $0x1, %r8d
subq %rsi, %r8
movl $0x2, %r9d
cmpl $0x0, (%rdi)
jns 0x20c68
movl -0x20(%rdi), %r10d
cmpl 0x44(%r11), %r10d
jge 0x20c82
cmpq %rsi, %r9
setb %dl
addq $0x60, %rdi
leaq (%r8,%r9), %r10
incq %r10
incq %r9
cmpq $0x2, %r10
jne 0x20c59
movzbl %dl, %edx
andl $0x1, %edx
movl %edx, 0x90(%rsp,%rax,4)
leaq 0x1(%rax), %rdx
testq %rax, %rax
movq %rdx, %rax
movq 0x300(%rsp), %r10
je 0x20c2d
movl 0x94(%rsp), %eax
orl 0x90(%rsp), %eax
sete %al
movl $0x1, %r12d
jne 0x216b8
movb %al, 0x17(%rsp)
movq %rbx, 0x30(%rsp)
movq 0x18(%r10), %rax
movq 0x38(%r10), %rcx
movl 0x1c(%rcx), %ebp
addl 0x1c(%rax), %ebp
subl 0x18(%r11), %ebp
movl 0x54(%rsp), %eax
cmpl %ebp, %eax
cmovlel %ebp, %eax
movl %eax, 0x54(%rsp)
movl %r13d, %ecx
subl %eax, %ecx
cvtsi2sd %ecx, %xmm0
mulsd 0x851f(%rip), %xmm0     # 0x29218
cvtsi2sdl (%r11), %xmm1
divsd %xmm1, %xmm0
addsd 0x4a96(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %ebx
movl 0x7c(%rsp), %eax
testl %eax, %eax
jle 0x20d47
incl %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
callq 0x3250
movq 0x300(%rsp), %r10
movq 0x8(%rsp), %r11
mulsd 0x7a7f(%rip), %xmm0     # 0x287b8
addsd 0x4a5f(%rip), %xmm0     # 0x257a0
cvttsd2si %xmm0, %eax
subl %eax, %ebx
xorl %ecx, %ecx
testl %ebx, %ebx
cmovgl %ebx, %ecx
cmpl $0x3c, %ecx
movl $0x3c, %eax
cmovll %ecx, %eax
movq 0x18(%r10), %rsi
cmpl %ebp, %r13d
jle 0x2112e
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x38(%r10), %rax
movss 0x50(%rsi), %xmm1
addss 0x50(%rax), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x8499(%rip), %xmm1     # 0x29220
addsd 0x7709(%rip), %xmm1     # 0x28498
mulsd %xmm0, %xmm1
addsd 0x4a05(%rip), %xmm1     # 0x257a0
cvttsd2si %xmm1, %ebp
movslq 0x58(%rsp), %rcx
leaq (%rcx,%rcx,2), %r13
shlq $0x5, %r13
addq %rsi, %r13
movq %r13, 0x1e0(%rsp)
movslq 0x5c(%rsp), %rcx
leaq (%rcx,%rcx,2), %r14
shlq $0x5, %r14
addq %rax, %r14
movq %r14, 0x1e8(%rsp)
xorl %ebx, %ebx
movq 0x1e0(%rsp,%rbx,2), %rsi
movslq 0x3c(%rsi), %rax
testq %rax, %rax
js 0x20dfd
movq 0x18(%r10,%rbx,8), %rcx
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
movl 0x1c(%rcx,%rax), %eax
movl %eax, 0x24(%rsi)
movl $0xfffffffe, 0x3c(%rsi) # imm = 0xFFFFFFFE
movq %r11, %rdi
callq 0x1dd1f
movq 0x300(%rsp), %r10
movq 0x8(%rsp), %r11
movl %eax, 0x28(%rsp,%rbx)
addq $0x4, %rbx
cmpq $0x4, %rbx
je 0x20dd1
movl 0x28(%rsp), %eax
leal 0x28(%rax), %ecx
cmpl %ebp, %ecx
cmovgel %ebp, %ecx
movl 0x2c(%rsp), %edx
cmpl %ebp, %eax
cmovgl %eax, %ecx
leal 0x28(%rdx), %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
movl %ecx, 0x28(%rsp)
cmpl %ebp, %edx
cmovgl %edx, %eax
movl %eax, 0x2c(%rsp)
movl 0x1c(%r13), %edx
subl 0x2c(%r13), %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
movsd 0x83b7(%rip), %xmm1     # 0x29218
mulsd %xmm1, %xmm0
cvtsi2sdl (%r11), %xmm2
divsd %xmm2, %xmm0
movsd 0x492a(%rip), %xmm3     # 0x257a0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %edx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x28(%rsp)
movl 0x1c(%r14), %ecx
subl 0x2c(%r14), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movl %eax, 0x2c(%rsp)
movl $0x3, %ebx
jmp 0x2116f
movq 0x300(%rsp), %r10
movl %r12d, 0x20(%rsp)
leaq 0x20(%r10), %r12
leaq 0x100(%rsp), %rbp
xorl %r13d, %r13d
movq %r15, %r14
movq (%r10,%r13,8), %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x20f15
movq 0x18(%r10,%r13,8), %rcx
movl 0x44(%r11), %edx
xorl %eax, %eax
cmpl %edx, 0x1c(%rcx)
jge 0x20f15
movslq 0x38(%rsp,%r13), %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rsi, %rdi
jbe 0x20f15
leaq (%rsi,%rsi,2), %rdi
shlq $0x5, %rdi
cmpl %edx, 0x1c(%rcx,%rdi)
jl 0x20f15
movl %esi, %eax
testl %eax, %eax
js 0x20f49
movl (%r14), %r8d
movq 0x18(%r14), %r9
movl %eax, %eax
leaq (%rax,%rax,2), %rax
shlq $0x5, %rax
addq 0x18(%r10,%r13,8), %rax
subq $0x8, %rsp
leaq 0xa0(%rsp), %rdi
movq %r11, %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
pushq %rax
jmp 0x20f69
movl (%r14), %r8d
movq 0x18(%r14), %r9
subq $0x8, %rsp
leaq 0xa0(%rsp), %rdi
movq %r11, %rsi
movq 0x20(%rsp), %rdx
movq %rbx, %rcx
pushq $0x0
callq 0x1e2f7
addq $0x10, %rsp
movq 0xc8(%rsp), %rax
movq %rax, 0x30(%rbp)
movupd 0x98(%rsp), %xmm0
movupd 0xa8(%rsp), %xmm1
movupd 0xb8(%rsp), %xmm2
movupd %xmm2, 0x20(%rbp)
movupd %xmm1, 0x10(%rbp)
movupd %xmm0, (%rbp)
addq $0x4, %r13
addq $0x30, %r14
addq $0x38, %rbp
cmpq $0x4, %r13
movq 0x8(%rsp), %r11
movq 0x300(%rsp), %r10
je 0x20ed8
testb $0x4, 0x48(%r11)
jne 0x21078
movl 0x108(%rsp), %eax
testl %eax, %eax
movq 0x18(%rsp), %r14
movq %r12, %r13
js 0x21080
cmpl 0x140(%rsp), %eax
movl 0x20(%rsp), %ebp
jne 0x21084
movq (%r14), %rax
movq 0x18(%r10), %rcx
movq 0x38(%r10), %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 0x70(%rsp), %rdx
cmpl $0x0, 0x8(%rdx,%rcx)
jne 0x21084
addq %rcx, %rdx
movslq (%rdx), %rcx
cmpq %rcx, %rax
jl 0x21084
movslq 0x4(%rdx), %rcx
cmpq %rcx, %rax
movl $0x3, %eax
cmovlel %eax, %ebp
jmp 0x21084
movq 0x18(%rsp), %r14
movq %r12, %r13
movl 0x20(%rsp), %ebp
movl %ebp, %r9d
orl $0x41, %r9d
leaq 0x138(%rsp), %rax
subq $0x8, %rsp
movq %r11, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movq %r10, %r8
pushq %rax
movq %r11, %r12
callq 0x1df0b
addq $0x10, %rsp
leaq 0x30(%r15), %rcx
orl $0x81, %ebp
subq $0x8, %rsp
leaq 0x108(%rsp), %rax
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movq %r13, %r8
movl %ebp, %r9d
pushq %rax
callq 0x1df0b
addq $0x10, %rsp
movq 0x8(%r15), %r14
movq 0x38(%r15), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x34d0
testl %eax, %eax
jne 0x216c5
movq 0x118(%rsp), %rdi
callq 0x3390
movq 0x150(%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 $0x0, 0x58(%rsp)
movq %r11, %rdi
callq 0x1dd1f
movl %eax, 0x28(%rsp)
movq 0x300(%rsp), %rax
movq 0x38(%rax), %rsi
movq 0x8(%rsp), %rdi
callq 0x1dd1f
movq 0x300(%rsp), %r10
movq 0x8(%rsp), %r11
movl %eax, 0x2c(%rsp)
movl $0x1, %ebx
xorl %eax, %eax
movq 0x18(%rsp), %rbp
movq %rax, %r8
shlq $0x5, %r8
movq 0x18(%r10,%r8), %rcx
movslq 0x58(%rsp,%rax,4), %rsi
leaq (%rsi,%rsi,2), %rdx
shlq $0x5, %rdx
movslq 0x40(%rcx,%rdx), %rdi
testq %rdi, %rdi
js 0x211f3
cmpl 0x38(%rsp,%rax,4), %edi
jge 0x211f3
leaq (%rdi,%rdi,2), %r9
shlq $0x5, %r9
cmpl $0x0, 0x40(%rcx,%r9)
jns 0x216e0
addq %r10, %r8
movq (%r8), %r8
testq %r8, %r8
je 0x211de
leaq 0x40(%rcx), %r9
xorl %r10d, %r10d
cmpq %r10, %rdi
je 0x211cf
cmpl %edi, (%r9)
jne 0x211d2
movl %esi, (%r9)
incq %r10
addq $0x60, %r9
cmpq %r10, %r8
jne 0x211c5
addq %rdx, %rcx
addq $0x40, %rcx
movl $0xffffffff, (%rcx)     # imm = 0xFFFFFFFF
movq 0x300(%rsp), %r10
leaq 0x1(%rax), %rcx
testq %rax, %rax
movq %rcx, %rax
je 0x21176
movl %ebx, 0x20(%rsp)
testb $0x8, 0x48(%r11)
jne 0x21253
xorl %ebx, %ebx
movq %r10, %r13
movq %r15, %r14
movq 0x30(%rsp), %r12
movl (%r14), %r8d
movq 0x18(%r14), %r9
movq %r11, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0x22334
movq 0x8(%rsp), %r11
movq %rax, 0xf0(%rsp,%rbx,8)
incq %rbx
addq $0x30, %r14
addq $0x20, %r13
cmpq $0x1, %rbx
je 0x2121b
jmp 0x21260
xorpd %xmm0, %xmm0
movapd %xmm0, 0xf0(%rsp)
xorl %ecx, %ecx
xorl %r13d, %r13d
xorl %ebp, %ebp
movq 0x300(%rsp), %rsi
movl (%r15), %r8d
movq %r15, %r12
movq 0x18(%r15), %r9
movslq 0x58(%rsp,%rbp), %r15
leaq (%r15,%r15,2), %rax
shlq $0x5, %rax
addq 0x18(%rsi,%rbp,8), %rax
subq $0x8, %rsp
movq %rcx, %rbx
leaq 0xa0(%rsp), %rdi
movq %r11, %rsi
movq 0x20(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %rax
callq 0x1e2f7
movq %rbx, %rcx
addq $0x10, %rsp
movq 0xc8(%rsp), %rax
movq %rax, 0x130(%rsp,%r13)
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm2, 0x120(%rsp,%r13)
movups %xmm1, 0x110(%rsp,%r13)
movups %xmm0, 0x100(%rsp,%r13)
movl 0x28(%rsp,%rbp), %eax
movzbl %al, %eax
movl 0x110(%rsp,%r13), %edx
movl $0xfffffc03, %esi       # imm = 0xFFFFFC03
andl %esi, %edx
movl $0x40, %r14d
shll %cl, %r14d
leal (%rdx,%rax,4), %eax
movl %eax, 0x110(%rsp,%r13)
movl 0x10c(%rsp,%r13), %eax
orl 0x20(%rsp), %eax
orl %r14d, %eax
movl %eax, 0x10c(%rsp,%r13)
movq 0xf0(%rsp,%rbp,2), %r8
testq %r8, %r8
je 0x2134b
movq (%r8,%r15,8), %rax
jmp 0x2134d
xorl %eax, %eax
leaq (%rsp,%r13), %rsi
addq $0x100, %rsi            # imm = 0x100
movq %rax, 0x20(%rsi)
movslq 0x4c(%rsp,%rbp), %r10
leaq 0x1(%r10), %r9
movl %r9d, 0x4c(%rsp,%rbp)
imulq $0x38, %r10, %rax
addq %rsp, %rax
addq $0x1e0, %rax            # imm = 0x1E0
movq 0x30(%rsi), %rdx
movq %rdx, 0x30(%rax,%r13,2)
movupd (%rsi), %xmm0
movupd 0x10(%rsi), %xmm1
movupd 0x20(%rsi), %xmm2
movupd %xmm2, 0x20(%rax,%r13,2)
movupd %xmm1, 0x10(%rax,%r13,2)
movupd %xmm0, (%rax,%r13,2)
movslq 0x38(%rsp,%rbp), %r15
movq 0x300(%rsp), %rsi
cmpq %r15, (%rsi,%rbp,8)
movq 0x8(%rsp), %r11
jbe 0x21513
movq 0x18(%rsi,%rbp,8), %rax
leaq (%r15,%r15,2), %rdi
shlq $0x5, %rdi
movl 0x1c(%rax,%rdi), %edx
cmpl 0x44(%r11), %edx
jl 0x21513
addq %rdi, %rax
cmpl $0x0, 0x3c(%rax)
jns 0x21513
cmpl $0x40000000, 0x48(%rax) # imm = 0x40000000
jb 0x21513
movq %r10, 0x80(%rsp)
movq %r9, 0x88(%rsp)
movq %r8, 0x40(%rsp)
movl (%r12), %r8d
movq 0x18(%r12), %r9
subq $0x8, %rsp
leaq 0xa0(%rsp), %rdi
movq %r11, %rsi
movq 0x20(%rsp), %rdx
movq 0x38(%rsp), %rcx
pushq %rax
callq 0x1e2f7
movq 0x50(%rsp), %rcx
addq $0x10, %rsp
movups 0x98(%rsp), %xmm0
movups 0xa8(%rsp), %xmm1
movups 0xb8(%rsp), %xmm2
movups %xmm0, 0x170(%rsp,%r13)
orl 0x17c(%rsp,%r13), %r14d
orl 0x20(%rsp), %r14d
orl $0x800, %r14d           # imm = 0x800
movq 0xc8(%rsp), %rax
movq %rax, 0x1a0(%rsp,%r13)
movups %xmm2, 0x190(%rsp,%r13)
movups %xmm1, 0x180(%rsp,%r13)
movl %r14d, 0x17c(%rsp,%r13)
testq %rcx, %rcx
je 0x214a3
movq (%rcx,%r15,8), %rax
jmp 0x214a5
xorl %eax, %eax
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rsi
leaq (%rsp,%r13), %rcx
addq $0x170, %rcx            # imm = 0x170
movq %rax, 0x20(%rcx)
addl $0x2, %esi
movl %esi, 0x4c(%rsp,%rbp)
imulq $0x38, %rdx, %rax
addq %rsp, %rax
addq $0x1e0, %rax            # imm = 0x1E0
movq 0x30(%rcx), %rdx
movq %rdx, 0x30(%rax,%r13,2)
movupd (%rcx), %xmm0
movupd 0x10(%rcx), %xmm1
movupd 0x20(%rcx), %xmm2
movupd %xmm2, 0x20(%rax,%r13,2)
movupd %xmm1, 0x10(%rax,%r13,2)
movupd %xmm0, (%rax,%r13,2)
movq 0x8(%rsp), %r11
movq 0x300(%rsp), %rsi
movq %rbx, %rcx
addq $0x4, %rbp
addq $0x38, %r13
movq %r12, %r15
addq $0x30, %r15
incl %ecx
cmpq $0x4, %rbp
je 0x2126f
movl 0x4c(%rsp), %r13d
testl %r13d, %r13d
movq 0x60(%rsp), %r15
movq 0x18(%rsp), %r12
movq %r11, %rbp
jle 0x2157e
xorl %ebx, %ebx
leaq 0x138(%rsp), %r14
movq %rbp, %rdi
movq %r12, %rsi
leaq 0xd0(%rsp), %rdx
movq %r15, %rcx
movl %r13d, %r8d
leaq 0x1e0(%rsp), %r9
pushq %r14
pushq %rbx
callq 0x1b6bb
addq $0x10, %rsp
incl %ebx
cmpl %ebx, %r13d
jne 0x2154f
movq 0xe0(%rsp), %rdi
leaq 0x7cb3(%rip), %rsi      # 0x29240
leaq 0x7ea6(%rip), %rcx      # 0x2943a
movl $0x160, %edx            # imm = 0x160
callq 0x22d9d
movq %rax, 0x28(%r15)
movq $0x0, 0xd0(%rsp)
movl 0x50(%rsp), %r13d
testl %r13d, %r13d
jle 0x215fc
leaq 0x30(%r15), %rax
movq %rax, 0x40(%rsp)
xorl %ebx, %ebx
leaq 0x100(%rsp), %r14
movq %rbp, %rdi
movq %r12, %rsi
leaq 0xd0(%rsp), %rdx
movq 0x40(%rsp), %rcx
movl %r13d, %r8d
leaq 0x250(%rsp), %r9
pushq %r14
pushq %rbx
callq 0x1b6bb
addq $0x10, %rsp
incl %ebx
cmpl %ebx, %r13d
jne 0x215cb
movq 0xe0(%rsp), %rax
movq %rax, 0x58(%r15)
movq 0x8(%r15), %r13
movq 0x38(%r15), %rbx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x34d0
testl %eax, %eax
jne 0x216ff
xorl %r14d, %r14d
movl 0x20(%rsp), %r12d
imulq $0x38, %r14, %rbx
movq 0x118(%rsp,%rbx), %rdi
callq 0x3390
movq 0x188(%rsp,%rbx), %rdi
callq 0x3390
movq 0xf0(%rsp,%r14,8), %r13
testq %r13, %r13
je 0x21696
movq %r14, %rbx
shlq $0x5, %rbx
movq 0x300(%rsp), %rax
cmpq $0x0, (%rax,%rbx)
je 0x21689
addq 0x300(%rsp), %rbx
xorl %r15d, %r15d
movq (%r13,%r15,8), %rdi
callq 0x3390
incq %r15
cmpq %r15, (%rbx)
ja 0x21677
movq %r13, %rdi
callq 0x3390
movq 0x60(%rsp), %r15
leaq 0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
je 0x2162b
movq 0x30(%rsp), %rbx
movq 0x8(%rsp), %r11
movq 0x300(%rsp), %r10
movb 0x17(%rsp), %al
testb %al, %al
je 0x20ec1
jmp 0x21117
leaq 0x7d6e(%rip), %rdi      # 0x2943a
leaq 0x7e0e(%rip), %rsi      # 0x294e1
movq %r14, %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0xde26
leaq 0x7d5e(%rip), %rdi      # 0x29445
leaq 0x7b52(%rip), %rsi      # 0x29240
leaq 0x7d6c(%rip), %rcx      # 0x29461
movl $0x143, %edx            # imm = 0x143
callq 0x31a0
leaq 0x7d34(%rip), %rdi      # 0x2943a
leaq 0x7dd4(%rip), %rsi      # 0x294e1
movq %r13, %rdx
movq %rbx, %rcx
jmp 0x216d9
nopl (%rax)