// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/miniwfa.c
// Function: mwf_wfa_chain
void mwf_wfa_chain(void *km, const mwf_opt_t *opt, int32_t tl, const char *ts, int32_t ql, const char *qs, mwf_rst_t *r)
{
	int32_t n_a, i, x0, y0;
	uint64_t *a;
	void *km_wfa;
	wf_cigar_t c = {0,0,0};

	km_wfa = !(opt->flag&MWF_F_NO_KALLOC)? km_init2(km, 0) : 0;
	a = mg_chain(km_wfa, tl, ts, ql, qs, opt->kmer, opt->max_occ, &n_a);
	n_a = wf_anchor_filter(n_a, a, tl, ql, opt->kmer, opt->min_len);
	r->s = 0;
	for (i = 0, x0 = y0 = 0; i <= n_a; ++i) {
		int32_t x1, y1;
		if (i == n_a) x1 = tl, y1 = ql;
		else x1 = (int32_t)(a[i]>>32) + 1, y1 = (int32_t)a[i] + 1;
		if (i < n_a && x1 - x0 == y1 - y0 && x1 - x0 <= opt->kmer) {
			if (opt->flag&MWF_F_CIGAR)
				wf_cigar_push1(km, &c, 7, x1 - x0);
		} else if (x0 < x1 && y0 < y1) {
			if (x1 - x0 >= 10000 && y1 - y0 >= 10000 && mwf_ksim(km, x1 - x0, &ts[x0], y1 - y0, &qs[y0], opt->kmer) < 0.02) {
				if (opt->flag&MWF_F_CIGAR) {
					wf_cigar_push1(km, &c, 2, x1 - x0);
					wf_cigar_push1(km, &c, 1, y1 - y0);
				}
				r->s += opt->o2 * 2 + opt->e2 * ((x1 - x0) + (y1 - y0));
			} else {
				mwf_rst_t q;
				mwf_wfa_exact(km_wfa, opt, x1 - x0, &ts[x0], y1 - y0, &qs[y0], &q);
				if (opt->flag&MWF_F_CIGAR)
					wf_cigar_push(km, &c, q.n_cigar, q.cigar);
				r->s += q.s;
				kfree(km_wfa, q.cigar);
			}
		} else if (x0 < x1) {
			wf_cigar_push1(km, &c, 2, x1 - x0);
			r->s += opt->o2 + (x1 - x0) * opt->e2 < opt->o1 + (x1 - x0) * opt->e1? opt->o2 + (x1 - x0) * opt->e2 : opt->o1 + (x1 - x0) * opt->e1;
		} else if (y0 < y1) {
			wf_cigar_push1(km, &c, 1, y1 - y0);
			r->s += opt->o2 + (y1 - y0) * opt->e2 < opt->o1 + (y1 - y0) * opt->e1? opt->o2 + (y1 - y0) * opt->e2 : opt->o1 + (y1 - y0) * opt->e1;
		}
		x0 = x1, y0 = y1;
	}
	if (km_wfa == 0) kfree(km_wfa, a);
	km_destroy(km_wfa);
	r->n_cigar = c.n, r->cigar = c.cigar;
	r->cigar = (uint32_t*)krelocate(km, r->cigar, r->n_cigar * sizeof(*r->cigar));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2190
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x1dc7a
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x24a0
movq %rax, -0x88(%rbp)
jmp 0x1dc85
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x1dc85
movq -0x88(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %r8
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %r9d
movq -0x10(%rbp), %rax
movl 0x28(%rax), %r10d
leaq -0x34(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x1e0e0
movq %rax, -0x48(%rbp)
movl -0x34(%rbp), %edi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x24(%rbp), %ecx
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %r8d
movq -0x10(%rbp), %rax
movl 0x30(%rax), %r9d
callq 0x1e540
movl %eax, -0x34(%rbp)
movq 0x10(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x1e06e
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x1dd2e
movl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x1dd56
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x1dda8
movl -0x64(%rbp), %eax
subl -0x3c(%rbp), %eax
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jne 0x1dda8
movl -0x64(%rbp), %eax
subl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jg 0x1dda8
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1dda3
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
leaq -0x60(%rbp), %rsi
movl $0x7, %edx
callq 0x1e6d0
jmp 0x1e054
movl -0x3c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x1df09
movl -0x40(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x1df09
movl -0x64(%rbp), %eax
subl -0x3c(%rbp), %eax
cmpl $0x2710, %eax           # imm = 0x2710
jl 0x1de91
movl -0x68(%rbp), %eax
subl -0x40(%rbp), %eax
cmpl $0x2710, %eax           # imm = 0x2710
jl 0x1de91
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %esi
subl -0x3c(%rbp), %esi
movq -0x20(%rbp), %rdx
movslq -0x3c(%rbp), %rax
addq %rax, %rdx
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
movq -0x30(%rbp), %r8
movslq -0x40(%rbp), %rax
addq %rax, %r8
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %r9d
callq 0x1e7b0
movaps %xmm0, %xmm1
movsd 0x1ee68(%rip), %xmm0    # 0x3cc88
ucomisd %xmm1, %xmm0
jbe 0x1de91
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1de64
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
leaq -0x60(%rbp), %rsi
movl $0x2, %edx
callq 0x1e6d0
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
leaq -0x60(%rbp), %rsi
movl $0x1, %edx
callq 0x1e6d0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
shll %ecx
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movl -0x64(%rbp), %edx
subl -0x3c(%rbp), %edx
movl -0x68(%rbp), %esi
subl -0x40(%rbp), %esi
addl %esi, %edx
imull %edx, %eax
addl %eax, %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x1df04
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x64(%rbp), %edx
subl -0x3c(%rbp), %edx
movq -0x20(%rbp), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movl -0x68(%rbp), %r8d
subl -0x40(%rbp), %r8d
movq -0x30(%rbp), %r9
movslq -0x40(%rbp), %rax
addq %rax, %r9
leaq -0x80(%rbp), %rax
movq %rax, (%rsp)
callq 0x1d270
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1deec
movq -0x8(%rbp), %rdi
movl -0x7c(%rbp), %edx
movq -0x70(%rbp), %rcx
leaq -0x60(%rbp), %rsi
callq 0x1ea30
movl -0x80(%rbp), %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x2670
jmp 0x1e052
movl -0x3c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x1dfae
movq -0x8(%rbp), %rdi
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
leaq -0x60(%rbp), %rsi
movl $0x2, %edx
callq 0x1e6d0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl -0x64(%rbp), %edx
subl -0x3c(%rbp), %edx
movq -0x10(%rbp), %rsi
imull 0xc(%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x1df7e
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x8c(%rbp)
jmp 0x1df9b
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x64(%rbp), %ecx
subl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0xc(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x8c(%rbp)
movl -0x8c(%rbp), %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x1e050
movl -0x40(%rbp), %eax
cmpl -0x68(%rbp), %eax
jge 0x1e04e
movq -0x8(%rbp), %rdi
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
leaq -0x60(%rbp), %rsi
movl $0x1, %edx
callq 0x1e6d0
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
movl -0x68(%rbp), %edx
subl -0x40(%rbp), %edx
movq -0x10(%rbp), %rsi
imull 0xc(%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x1e023
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x90(%rbp)
jmp 0x1e040
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x68(%rbp), %ecx
subl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rdx
imull 0xc(%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %ecx
movq 0x10(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x1e050
jmp 0x1e052
jmp 0x1e054
movl -0x64(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x1dd0c
cmpq $0x0, -0x50(%rbp)
jne 0x1e082
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x2670
movq -0x50(%rbp), %rdi
callq 0x25f0
movl -0x5c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x58(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8(%rbp), %rdi
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movq 0x10(%rbp), %rax
movslq 0x4(%rax), %rdx
shlq $0x2, %rdx
callq 0x2bd0
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)