// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_extension_64_1_w_trace(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_extension_64_1_w_trace(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, bit_extz_t *ez)
{
	int32_t done = 1;//diff
	ez->cigar.n = 0; ez->nword = 1;//diff
	if(ez->err > thre) {//diff
		init_base_ed(*ez, thre, pn, tn); ez->ps = ez->ts = INT32_MAX; ez->pe = pn-1; ez->te = tn-1;
		if(pn > tn + thre) pn = tn + thre;
		else if(tn > pn + thre) tn = pn + thre;
		done = 0;//diff
	} else if(ez->err == 0) {//diff
        push_trace(&(ez->cigar), 0, ez->te+1-ez->ts); return;//diff
    } else {
        pn = ez->pe + 1 - ez->ps; tn = ez->te + 1 - ez->ts; //diff
    }

	int32_t i, err, tn0 = tn - 1, cut = thre+(thre<<1), bd, i_bd;
	int32_t poff, pe = pn-1, tmp_e = INT32_MAX, k, pidx = ez->pe, tidx = ez->te;
	Word c, Peq[5] = {0}, VP, VN, X, D0, HN, HP, mm;

	bd = thre+1; bd = ((bd<=pn)?bd:pn); i_bd = thre;
	for (i = 0, mm = (((Word)1)<<i_bd); i < bd; i++) {
        Peq[seq_nt4_table[(uint8_t)pstr[pidx-i]]] |= mm; mm <<= 1;
    }	
	bd = thre+1, i_bd = thre; Peq[4] = 0; err = thre;
	VN = (((Word)1)<<(thre))-1; VP = (((Word)1)<<((thre<<1)+1))-1; VP ^= VN;

	ez->path.n=(ez->nword*tn*5);//diff
    kv_resize(w_sig, ez->path, ez->path.n); ez->path.n=0;//diff

	i = 0; mm = ((Word)1 << (thre<<1));
	// X = D0 = HN = HP = mm = 0;//for debug
	while (i < tn0) {
		// fprintf(stderr, "i::%d\n", i);
		// prt_vector(Peq, VP, VN, X, D0, HN, HP, ((thre<<1)+1));
		ed_core_64(Peq, VP, VN, X, D0, HN, HP, (uint8_t)tstr[tidx-i]);
		if (!(D0&(1ULL))) {
			++err; if (err>cut) return;
		}

		if(!done) {//diff
			poff = i-thre; k = i+thre-pe;/**poff:[i-thre, i+thre]**/
            if(k >= 0) {
                if(tmp_e == INT32_MAX) {
                    tmp_e = err;
                    for (k = 0; poff < pe; poff++, (k)++) {
                        tmp_e += ((VP>>k)&(1ULL)); tmp_e -= ((VN>>k)&(1ULL));
                    } 
                } else {
                    k = (thre<<1) - k; 
                    if(k >= 0) {
                        tmp_e += ((HP>>k)&(1ULL)); tmp_e -= ((HN>>k)&(1ULL)); 
                    }
                }
                if(tmp_e <= (*ez).thre && tmp_e < (*ez).err) {
					(*ez).err = tmp_e; (*ez).ps = pidx - pe; (*ez).ts = tidx-i;
                }
            }
        }
		// fprintf(stderr, "i::%d, tmp_e::%d, err::%d\n", i, tmp_e, err);

		Peq[0] >>= 1; Peq[1] >>= 1; Peq[2] >>= 1; Peq[3] >>= 1;
		++i; ++i_bd;
        if(i_bd < pn) {
            c = seq_nt4_table[(uint8_t)pstr[pidx-i_bd]]; 
            if(c < 4) Peq[c] |= mm;
        }

		ez->path.a[ez->path.n++] = D0;//diff
        ez->path.a[ez->path.n++] = VP;//diff
        ez->path.a[ez->path.n++] = VN;//diff
        ez->path.a[ez->path.n++] = HP;//diff
        ez->path.a[ez->path.n++] = HN;//diff
	}
	ed_core_64(Peq, VP, VN, X, D0, HN, HP, (uint8_t)tstr[tidx-i]);
	if (!(D0&(1ULL))) {
		++err; if (err>cut) return;
	}
	ez->path.a[ez->path.n++] = D0;//diff
	ez->path.a[ez->path.n++] = VP;//diff
	ez->path.a[ez->path.n++] = VN;//diff
	ez->path.a[ez->path.n++] = HP;//diff
	ez->path.a[ez->path.n++] = HN;//diff

	int32_t site = tn - 1 - thre;/**up bound; site:[tn - 1 - thre, tn - 1 + thre]**/\
	if(!done) {//diff
		for (cut = pn - 1; site < cut; ) {
			err += VP&(1ULL); VP >>= 1; err -= VN&(1ULL); VN >>= 1; 
			site++;
			if(err <= thre && err < ez->err) {
				ez->err = err; ez->ps = pidx-site; ez->ts = tidx+1-tn;
			}
		}
		if(err <= thre && err < ez->err) {
			ez->err = err; ez->ps = pidx-site; ez->ts = tidx+1-tn;
		}
	}

	if((ez->te-ez->ts+1) != tn) {//diff
        ez->path.n /= tn; ez->path.n *= (ez->te+1-ez->ts);//diff
    }//diff

	poff = ez->ps; ez->ps = pidx - ez->pe; ez->pe = pidx - poff;//diff
	gen_trace(ez, thre, 0);//diff
	poff = ez->ps; ez->ps = pidx - ez->pe; ez->pe = pidx - poff;//diff
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %rbx
movq %rdx, 0x48(%rsp)
andq $0x0, 0xa8(%r9)
movq %rdi, 0x40(%rsp)
movl $0x1, 0x30(%r9)
movl 0x2c(%r9), %eax
cmpl %r8d, %eax
jle 0x58ccd
movl %ecx, %r10d
movl %eax, 0x4(%rsp)
movl %r8d, 0x28(%rbx)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0x2c(%rbx)
movl %esi, 0x18(%rbx)
movl %ecx, 0x24(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rbx)
movl %eax, 0x1c(%rbx)
movl %eax, 0x10(%rbx)
leal -0x1(%rsi), %r9d
movl %r9d, 0x14(%rbx)
leal -0x1(%r10), %r11d
movl %r11d, 0x20(%rbx)
leal (%r8,%r10), %eax
cmpl %esi, %eax
jge 0x58cfa
movl %eax, %esi
jmp 0x58d05
testl %eax, %eax
je 0x5924e
movl %eax, 0x4(%rsp)
movl 0x10(%rbx), %eax
movl 0x14(%rbx), %r9d
negl %eax
leal (%r9,%rax), %esi
incl %esi
movl 0x20(%rbx), %r11d
movl 0x1c(%rbx), %eax
negl %eax
leal (%r11,%rax), %r10d
incl %r10d
jmp 0x58d05
leal (%r8,%rsi), %eax
cmpl %r10d, %eax
cmovll %eax, %r10d
leal -0x1(%r10), %ebp
leal (%r8,%r8,2), %eax
movl %eax, 0xc(%rsp)
pxor %xmm0, %xmm0
movdqa %xmm0, 0x60(%rsp)
andq $0x0, 0x70(%rsp)
leal 0x1(%r8), %eax
cmpl %esi, %eax
cmovgel %esi, %eax
movdqa %xmm0, 0x50(%rsp)
pushq $0x1
popq %r12
movq %r12, 0x38(%rsp)
movl %r8d, %ecx
shlq %cl, %r12
movslq %r9d, %rdi
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
negq %rax
movq 0x40(%rsp), %rdx
movq %rdi, 0x90(%rsp)
addq %rdi, %rdx
movq %r12, %r15
leaq 0x192d9a(%rip), %r14    # 0x1ebb00
cmpq %rcx, %rax
je 0x58d81
movzbl (%rdx,%rcx), %edi
movzbl (%r14,%rdi), %edi
orq %r15, 0x50(%rsp,%rdi,8)
addq %r15, %r15
decq %rcx
jmp 0x58d66
movl %ebp, 0x8(%rsp)
andq $0x0, 0x70(%rsp)
leal (%r8,%r8), %eax
movq %rax, 0x30(%rsp)
leal 0x1(%rax), %ecx
pushq $-0x1
popq %r14
shlq %cl, %r14
movq %rsi, 0x10(%rsp)
leal -0x1(%rsi), %r15d
movq %r12, %r13
negq %r13
movq %r10, 0x80(%rsp)
leal (%r10,%r10,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
movq %r8, 0x20(%rsp)
movq %r11, 0x18(%rsp)
jae 0x58e3f
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0xc8(%rbx)
movq 0xd0(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
movq %r9, %rbp
callq 0x2370
movq 0x18(%rsp), %r11
movq %rbp, %r9
movq 0x20(%rsp), %r8
movq %rax, 0xd0(%rbx)
decq %r12
xorq %r13, %r14
andq $0x0, 0xc0(%rbx)
movq 0x30(%rsp), %rcx
shlq %cl, 0x38(%rsp)
movl %r8d, %eax
movq 0x10(%rsp), %rcx
subl %ecx, %eax
incl %eax
movl %eax, 0x2c(%rsp)
movq %r9, 0x88(%rsp)
movl %r9d, %eax
subl %r15d, %eax
movl %eax, 0x28(%rsp)
movslq %r8d, %rsi
movslq %r11d, %rax
movq %rax, 0xa0(%rsp)
movslq %ecx, %rax
movq %rax, 0x98(%rsp)
xorl %r10d, %r10d
movl 0x8(%rsp), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x10(%rsp)
movl %r8d, %r11d
negl %r11d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %r8d, %edx
cmpq 0x10(%rsp), %r10
je 0x59080
movq 0xa0(%rsp), %rdi
subq %r10, %rdi
movq 0x48(%rsp), %rcx
movzbl (%rcx,%rdi), %ecx
leaq 0x192c24(%rip), %r8     # 0x1ebb00
movzbl (%r8,%rcx), %ecx
movq 0x50(%rsp,%rcx,8), %rcx
orq %r12, %rcx
movq %rcx, %r13
andq %r14, %r13
addq %r14, %r13
xorq %r14, %r13
orq %rcx, %r13
testb $0x1, %r13b
jne 0x58f0a
cmpl 0xc(%rsp), %edx
jge 0x5923c
incl %edx
movq %r13, %rcx
andq %r14, %rcx
orq %r13, %r14
notq %r14
orq %r14, %r12
movq %r13, %r14
shrq %r14
movq %r12, %rbp
andq %r14, %rbp
orq %r12, %r14
notq %r14
orq %rcx, %r14
movl 0x4(%rsp), %r8d
cmpl 0x20(%rsp), %r8d
jle 0x58f9d
movl 0x2c(%rsp), %r9d
addl %r10d, %r9d
js 0x58f9d
cmpl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
jne 0x58f6c
xorl %r9d, %r9d
movl %edx, %eax
leal (%r11,%r9), %r8d
cmpl %r15d, %r8d
jge 0x58f84
btq %r9, %r14
adcl $0x0, %eax
btq %r9, %rbp
sbbl $0x0, %eax
incq %r9
jmp 0x58f50
movq 0x30(%rsp), %r8
subl %r9d, %r8d
js 0x58f84
btq %r8, %rcx
sbbl $0x0, %eax
btq %r8, %r12
adcl $0x0, %eax
cmpl 0x28(%rbx), %eax
jg 0x58f9d
cmpl 0x2c(%rbx), %eax
jge 0x58f9d
movl %eax, 0x2c(%rbx)
movl 0x28(%rsp), %r8d
movl %r8d, 0x10(%rbx)
movl %edi, 0x1c(%rbx)
movdqa 0x50(%rsp), %xmm0
movdqa 0x60(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, 0x50(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, 0x60(%rsp)
incq %rsi
cmpq 0x98(%rsp), %rsi
jge 0x58ffd
movq 0x90(%rsp), %rdi
subq %rsi, %rdi
movq 0x40(%rsp), %r8
movzbl (%r8,%rdi), %edi
leaq 0x192b18(%rip), %r8     # 0x1ebb00
movzbl (%r8,%rdi), %edi
cmpq $0x3, %rdi
ja 0x58ffd
movq 0x38(%rsp), %r8
orq %r8, 0x50(%rsp,%rdi,8)
incq %r10
movq 0xc0(%rbx), %rdi
movq 0xd0(%rbx), %r8
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r13, (%r8,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r14, (%r8,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rbp, (%r8,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r12, (%r8,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rcx, (%r8,%rdi,8)
incq %r11
movq %rbp, %r12
jmp 0x58eb6
movq 0x18(%rsp), %r11
movl %r11d, %eax
subl 0x10(%rsp), %eax
cltq
movq 0x48(%rsp), %rcx
movzbl (%rcx,%rax), %eax
leaq 0x192a62(%rip), %rcx    # 0x1ebb00
movzbl (%rcx,%rax), %eax
movq 0x50(%rsp,%rax,8), %rax
orq %r12, %rax
movq %rax, %rsi
andq %r14, %rsi
addq %r14, %rsi
xorq %r14, %rsi
orq %rax, %rsi
testb $0x1, %sil
jne 0x590d0
cmpl 0xc(%rsp), %edx
jge 0x5923c
incl %edx
movq 0x18(%rsp), %r11
movq %rsi, %rdi
andq %r14, %rdi
orq %rsi, %r14
notq %r14
orq %r14, %r12
movq %rsi, %rax
shrq %rax
movq %r12, %rcx
andq %rax, %rcx
orq %r12, %rax
notq %rax
orq %rdi, %rax
movq 0xc0(%rbx), %r8
movq 0xd0(%rbx), %r9
leaq 0x1(%r8), %r10
movq %r10, 0xc0(%rbx)
movq %rsi, (%r9,%r8,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rax, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rcx, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %r12, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rdi, (%r9,%rsi,8)
movq 0x20(%rsp), %rsi
cmpl %esi, 0x4(%rsp)
movq 0x88(%rsp), %r9
movq 0x80(%rsp), %r10
jle 0x591e2
movl 0x8(%rsp), %ebp
subl %esi, %ebp
subl %r10d, %r11d
incl %r11d
leal (%r9,%rsi), %r8d
subl %r10d, %r8d
cmpl %r15d, %ebp
jge 0x591cb
movl %eax, %edi
andl $0x1, %edi
addl %edi, %edx
movl %ecx, %edi
andl $0x1, %edi
subl %edi, %edx
cmpl %esi, %edx
jg 0x591be
cmpl 0x2c(%rbx), %edx
jge 0x591be
movl %edx, 0x2c(%rbx)
movl %r8d, 0x10(%rbx)
movl %r11d, 0x1c(%rbx)
shrq %rax
shrq %rcx
decl %r8d
incl %ebp
jmp 0x59197
cmpl %esi, %edx
jg 0x591e2
cmpl 0x2c(%rbx), %edx
jge 0x591e2
movl %edx, 0x2c(%rbx)
incl %r8d
movl %r8d, 0x10(%rbx)
movl %r11d, 0x1c(%rbx)
movl 0x20(%rbx), %ecx
subl 0x1c(%rbx), %ecx
incl %ecx
cmpl %r10d, %ecx
je 0x5920c
movslq %r10d, %rdi
movq 0xc0(%rbx), %rax
xorl %edx, %edx
divq %rdi
movslq %ecx, %rcx
imulq %rax, %rcx
movq %rcx, 0xc0(%rbx)
movl %r9d, %eax
subl 0x14(%rbx), %eax
movl %r9d, %ecx
subl 0x10(%rbx), %ecx
movl %eax, 0x10(%rbx)
movl %ecx, 0x14(%rbx)
movq %rbx, %rdi
xorl %edx, %edx
movq %r9, %r14
callq 0x65f7b
movl %r14d, %eax
subl 0x14(%rbx), %eax
subl 0x10(%rbx), %r14d
movl %eax, 0x10(%rbx)
movl %r14d, 0x14(%rbx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa8(%rbx), %rdi
movl 0x20(%rbx), %edx
subl 0x1c(%rbx), %edx
incl %edx
xorl %esi, %esi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x62885