// File: /workspace/github_c_makefile_star2_O1/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, %r12
movq %rcx, 0x18(%rsp)
movq %rsi, %r15
movq %rdi, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq 0x80(%rsp), %r13
movl %r9d, 0xc(%rsp)
testl %r9d, %r9d
jle 0x1e90e
movl 0xc(%rsp), %ecx
xorl %esi, %esi
leaq 0x1234f(%rip), %rdi     # 0x30c40
movsbq (%r13,%rsi), %r8
cmpq $0x15, %r8
jl 0x1e901
movb (%rdi,%r8), %r8b
movb %r8b, (%r13,%rsi)
incq %rsi
cmpq %rsi, %rcx
jne 0x1e8f1
movq %rax, (%rsp)
leaq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rbp
movq %rbp, %rcx
movl 0xc(%rsp), %r14d
movl %r14d, %r8d
movq %r13, %r9
callq 0x144b9
movl (%rbx), %esi
movq 0x10(%rbx), %rbx
movq %r15, %rdi
movq %rbx, %rdx
callq 0x15eda
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 %r12, %rdx
movl %r14d, %ecx
movq %r13, %r8
callq 0x1a650
leaq 0x124c7(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1e98d
leaq 0x30(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x14389
movq 0x10(%rsp), %rax
movq $0x0, 0x18(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movl 0x24(%rsp), %eax
testl %eax, %eax
je 0x1ea05
movl %eax, %ebp
movq 0x28(%rsp), %r14
xorl %ebx, %ebx
leaq 0x12488(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1e9cd
leaq 0xa511(%rip), %rdi      # 0x28ed5
movl %ebx, %esi
xorl %eax, %eax
callq 0xe215
movq 0x10(%rsp), %rax
movq %rax, (%rsp)
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
movl 0xc(%rsp), %ecx
movq %r13, %r8
movq %r14, %r9
callq 0x1a7c6
movq 0x20(%r14), %rdi
callq 0x3390
incq %rbx
addq $0x28, %r14
cmpq %rbx, %rbp
jne 0x1e9b1
movq 0x28(%rsp), %rdi
callq 0x3390
movq 0x10(%rsp), %rbp
movl (%rbp), %r8d
movq 0x18(%rbp), %r14
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r9
callq 0x19caa
movl %eax, %ebx
cltq
movq %rax, (%rbp)
testb $0x40, 0x48(%r15)
je 0x1ea77
testl %ebx, %ebx
je 0x1ea6c
movl 0xc(%rsp), %eax
imull (%r15), %eax
cmpl %eax, 0x20(%r14)
jne 0x1ea6c
leaq 0x60(%r14), %rsi
decl %ebx
movslq %ebx, %rax
shlq $0x5, %rax
leaq (%rax,%rax,2), %rdx
movq %r14, %rdi
callq 0x3600
movslq %ebx, %rax
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x123c2(%rip), %rax     # 0x30e40
cmpl $0x4, (%rax)
jl 0x1ead7
movq 0x10(%rsp), %rax
movq (%rax), %r15
leaq 0xa465(%rip), %rdi      # 0x28ef7
movq %r15, %rsi
xorl %eax, %eax
callq 0xe215
testq %r15, %r15
je 0x1ead7
leaq 0x1c(%r14), %r12
leaq 0xa481(%rip), %rbx      # 0x28f2d
movl (%r12), %esi
movl -0xc(%r12), %edx
movl -0x8(%r12), %ecx
movq -0x1c(%r12), %r8
movq -0x14(%r12), %r9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3060
addq $0x60, %r12
decq %r15
jne 0x1eaac
movq 0x10(%rsp), %rax
movq (%rax), %rax
testq %rax, %rax
je 0x1eb21
addq $0x48, %r14
movl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movslq -0x30(%r14), %rdx
testq %rdx, %rdx
js 0x1eb18
movq 0x18(%rsp), %rsi
movq 0x10(%rsi), %rsi
leaq (%rdx,%rdx,4), %rdx
cmpl $0x0, 0x14(%rsi,%rdx,8)
je 0x1eb18
movl (%r14), %edx
andl %ecx, %edx
orl $0x40000000, %edx       # imm = 0x40000000
movl %edx, (%r14)
addq $0x60, %r14
decq %rax
jne 0x1eaed
movq 0x10(%rsp), %rax
movl $0x0, 0x10(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq