// File: /workspace/github_c_makefile_star2_O2/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
xorl %ecx, %ecx
testl %r9d, %r9d
movl $0x0, %esi
movl %r9d, 0xc(%rsp)
cmovgl %r9d, %esi
leaq 0x12216(%rip), %rdi     # 0x2cc40
cmpq %rcx, %rsi
je 0x1aa49
movsbq (%r13,%rcx), %r8
cmpq $0x15, %r8
jl 0x1aa3f
movb (%rdi,%r8), %r8b
movb %r8b, (%r13,%rcx)
incq %rcx
jmp 0x1aa2a
movq %rax, (%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rcx
movl 0xc(%rsp), %ebp
movl %ebp, %r8d
movq %r13, %r9
callq 0x12743
movl (%r14), %esi
movq 0x10(%r14), %r14
movq %r15, %rdi
movq %r14, %rdx
callq 0x1407d
movl %eax, 0x24(%rsp)
movslq %eax, %r9
leaq 0x30(%rsp), %rax
movq %r9, (%rax)
movq %r14, 0x28(%rsp)
movq %r14, (%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movl %ebp, %ecx
movq %r13, %r8
callq 0x18196
leaq 0x1238d(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x1aac7
leaq 0x30(%rsp), %rsi
movq 0x18(%rsp), %rdi
callq 0x1262d
movq 0x10(%rsp), %rax
andq $0x0, 0x18(%rax)
movl 0x24(%rsp), %ebx
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq 0x28(%rsp), %r14
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x1ab38
leaq 0x12352(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x1ab03
leaq 0x945b(%rip), %rdi      # 0x23f55
movl %ebp, %esi
xorl %eax, %eax
callq 0xcda0
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 0x182e9
movq 0x20(%r14), %rdi
callq 0x3390
incq %rbp
addq $0x28, %r14
jmp 0x1aae2
movq 0x28(%rsp), %rdi
callq 0x3390
movq 0x10(%rsp), %rbx
movl (%rbx), %r8d
movq 0x18(%rbx), %r14
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r14, %r9
callq 0x17900
movslq %eax, %r12
movq %r12, (%rbx)
testb $0x40, 0x48(%r15)
je 0x1ab8d
movq %r15, %rdi
movl %eax, %esi
movq %r14, %rdx
movl 0xc(%rsp), %ecx
callq 0x17c1c
movslq %eax, %r12
movq 0x10(%rsp), %rax
movq %r12, (%rax)
leaq 0x122ac(%rip), %rax     # 0x2ce40
cmpl $0x4, (%rax)
jl 0x1abde
leaq 0x93d7(%rip), %rdi      # 0x23f77
movq %r12, %rsi
xorl %eax, %eax
callq 0xcda0
leaq 0x1c(%r14), %rbx
leaq 0x93f8(%rip), %r15      # 0x23fad
movq %r12, %r13
subq $0x1, %r13
jb 0x1abde
movl (%rbx), %esi
movl -0xc(%rbx), %edx
movl -0x8(%rbx), %ecx
movq -0x1c(%rbx), %r8
movq -0x14(%rbx), %r9
movq %r15, %rdi
xorl %eax, %eax
callq 0x3060
addq $0x60, %rbx
jmp 0x1abb8
addq $0x48, %r14
movl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
subq $0x1, %r12
jb 0x1ac1e
movslq -0x30(%r14), %rcx
testq %rcx, %rcx
js 0x1ac18
movq 0x18(%rsp), %rdx
movq 0x10(%rdx), %rdx
imulq $0x28, %rcx, %rcx
cmpl $0x0, 0x14(%rdx,%rcx)
je 0x1ac18
movl (%r14), %ecx
andl %eax, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, (%r14)
addq $0x60, %r14
jmp 0x1abe7
movq 0x10(%rsp), %rax
andl $0x0, 0x10(%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq