// File: /workspace/github_c_makefile_star2_O3/ToniWestbrook[P]paladin/bwamem.c
// Function: mem_align1_core
mem_alnreg_v mem_align1_core(const mem_opt_t *opt, const bwt_t *bwt, const bntseq_t *bns, const uint8_t *pac, int l_seq, char *seq, void *buf)
{
	int i;
	mem_chain_v chn;
	mem_alnreg_v regs;

	for (i = 0; i < l_seq; ++i) {
		// Hash IUPAC value
		seq[i] = seq[i] < VALUE_DEFINED - 1 ? seq[i] : aa_encode_hash[(int)seq[i]];
	}

	chn = mem_chain(opt, bwt, bns, l_seq, (uint8_t*)seq, buf);
	chn.n = mem_chain_flt(opt, chn.n, chn.a);
	mem_flt_chained_seeds(opt, bns, pac, l_seq, (uint8_t*)seq, chn.n, chn.a);
	if (bwa_verbose >= 4) mem_print_chain(bns, &chn);

	kv_init(regs);
	for (i = 0; i < chn.n; ++i) {
		mem_chain_t *p = &chn.a[i];
		if (bwa_verbose >= 4) err_printf("* ---> Processing chain(%d) <---\n", i);
		mem_chain2aln(opt, bns, pac, l_seq, (uint8_t*)seq, p, &regs);
		free(chn.a[i].seeds);
	}
	free(chn.a);
	regs.n = mem_sort_dedup_patch(opt, bns, pac, (uint8_t*)seq, regs.n, regs.a);
	if (opt->flag & MEM_F_SELF_OVLP)
		regs.n = mem_test_and_remove_exact(opt, regs.n, regs.a, l_seq);
	if (bwa_verbose >= 4) {
		err_printf("* %ld chains remain after removing duplicated chains\n", regs.n);
		for (i = 0; i < regs.n; ++i) {
			mem_alnreg_t *p = &regs.a[i];
			printf("** %d, [%d,%d) <=> [%ld,%ld)\n", p->score, p->qb, p->qe, (long)p->rb, (long)p->re);
		}
	}
	for (i = 0; i < regs.n; ++i) {
		mem_alnreg_t *p = &regs.a[i];
		if (p->rid >= 0 && bns->anns[p->rid].is_alt)
			p->is_alt = 1;
	}

	// Mark as filtered by default
	regs.active = 0;

	return regs;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rsi, %r15
movq %rdi, %r12
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %r14
movl %r9d, 0xc(%rsp)
testl %r9d, %r9d
jle 0x1effd
movl 0xc(%rsp), %ecx
xorl %esi, %esi
leaq 0x11c5e(%rip), %r9      # 0x30c40
movsbq (%r14,%rsi), %r8
cmpq $0x15, %r8
jl 0x1eff1
movb (%r9,%r8), %r8b
movb %r8b, (%r14,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x1efe2
movq %rax, (%rsp)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rbp
movq %rbp, %rcx
movl 0xc(%rsp), %r13d
movl %r13d, %r8d
movq %r14, %r9
callq 0x1481e
movl (%rbx), %esi
movq 0x10(%rbx), %rbx
movq %r15, %rdi
movq %rbx, %rdx
callq 0x16492
movl %eax, 0x24(%rsp)
movslq %eax, %r9
leaq 0x30(%rsp), %rax
movq %r9, (%rax)
movq %rbx, 0x28(%rsp)
movq %rbx, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rdx
movl %r13d, %ecx
movq %r14, %r8
callq 0x1abcc
leaq 0x11dd6(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1f07e
leaq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x146ec
movq $0x0, 0x18(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movl 0x24(%rsp), %eax
testl %eax, %eax
je 0x1f0ff
movl %eax, %ebp
movq 0x28(%rsp), %r13
xorl %ebx, %ebx
leaq 0x11d99(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1f0bc
leaq 0x9f12(%rip), %rdi      # 0x28fc5
movl %ebx, %esi
xorl %eax, %eax
callq 0xe4a3
movq %r12, (%rsp)
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl 0xc(%rsp), %ecx
movq %r14, %r8
movq %r13, %r9
callq 0x1ad42
movq 0x20(%r13), %rdi
callq 0x3390
incq %rbx
addq $0x28, %r13
cmpq %rbx, %rbp
jne 0x1f0a0
movq %r12, %rbp
movl (%r12), %ebx
movq 0x18(%r12), %r13
jmp 0x1f107
movq %r12, %rbp
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x28(%rsp), %rdi
callq 0x3390
movq %r15, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rcx
movl %ebx, %r8d
movq %r13, %r9
callq 0x1a266
movslq %eax, %r14
movq %r14, (%rbp)
testb $0x40, 0x48(%r15)
je 0x1f172
movl %eax, %ebx
testl %eax, %eax
je 0x1f169
movl 0xc(%rsp), %eax
imull (%r15), %eax
cmpl %eax, 0x20(%r13)
jne 0x1f16b
leaq 0x60(%r13), %rsi
decl %ebx
movslq %ebx, %rax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rdx
movq %r13, %rdi
callq 0x3600
jmp 0x1f16b
xorl %ebx, %ebx
movslq %ebx, %r14
movq %r14, (%rbp)
leaq 0x11cc7(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1f1ca
leaq 0x9e62(%rip), %rdi      # 0x28fe7
movq %r14, %rsi
xorl %eax, %eax
callq 0xe4a3
testq %r14, %r14
je 0x1f20e
leaq 0x1c(%r13), %r15
leaq 0x9e7e(%rip), %rbx      # 0x2901d
movq %r14, %r12
movl (%r15), %esi
movl -0xc(%r15), %edx
movl -0x8(%r15), %ecx
movq -0x1c(%r15), %r8
movq -0x14(%r15), %r9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3060
addq $0x60, %r15
decq %r12
jne 0x1f1a2
jmp 0x1f1cf
testq %r14, %r14
je 0x1f20e
addq $0x48, %r13
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movslq -0x30(%r13), %rcx
testq %rcx, %rcx
js 0x1f205
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rdx
leaq (%rcx,%rcx,4), %rcx
cmpl $0x0, 0x14(%rdx,%rcx,8)
je 0x1f205
movl (%r13), %ecx
andl %eax, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, (%r13)
addq $0x60, %r13
decq %r14
jne 0x1f1d8
movl $0x0, 0x10(%rbp)
movq %rbp, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq