// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_extension_64_0_w_trace(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_extension_64_0_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 = 0; ez->pe = ez->te = -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, poff, pe = pn-1, tmp_e = INT32_MAX, k;
	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[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[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).pe = pe; (*ez).te = i;
                }
				// fprintf(stderr, "i::%d, (*ez).err::%d, (*ez).pe::%d, (*ez).te::%d, thre::%d, err::%d, tmp_e::%d, poff::%d, k::%d, pe::%d\n", 
				// i, (*ez).err, (*ez).pe, (*ez).te, thre, err, tmp_e, i-thre, i+thre-pe, pe);
            }
        }

		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[i_bd]]; 
            if(c < 4) Peq[c] |= mm;
        }
		// if(((ez->path.n+5)>(ez->nword*tn*5))||((ez->path.n+5)>(ez->path.m))) {
		// 	fprintf(stderr, "[M::%s::] pn::%d, tn::%d\n", __func__, pn, tn);
		// }
		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[i]);
	if (!(D0&(1ULL))) {
		++err; if (err>cut) return;
	}
	// if(((ez->path.n+5)>(ez->nword*tn*5))||((ez->path.n+5)>(ez->path.m))) {
	// 	fprintf(stderr, "[M::%s::] pn::%d, tn::%d\n", __func__, pn, tn);
	// }
	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->pe = site; ez->te = tn-1;
			}
		}
		if(err <= thre && err < ez->err) {
			ez->err = err; ez->pe = site; ez->te = tn-1;
		}
	}

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, %rbx
movl %r8d, %r15d
movl %ecx, %r8d
movq %rdx, 0x38(%rsp)
movq $0x0, 0xa8(%r9)
movl $0x1, 0x30(%r9)
movl 0x2c(%r9), %ecx
cmpl %r15d, %ecx
jle 0x8d071
movl %r15d, 0x28(%rbx)
movl $0x7fffffff, 0x2c(%rbx) # imm = 0x7FFFFFFF
movl %esi, 0x18(%rbx)
movl %r8d, 0x24(%rbx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x1c(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %rax, 0x10(%rbx)
leal (%r15,%r8), %eax
cmpl %esi, %eax
movl %ecx, 0x10(%rsp)
jge 0x8d092
movl %eax, %esi
jmp 0x8d09d
testl %ecx, %ecx
je 0x8d587
movl %ecx, 0x10(%rsp)
movl 0x14(%rbx), %esi
movl 0x20(%rbx), %r8d
subl 0x10(%rbx), %esi
incl %esi
subl 0x1c(%rbx), %r8d
incl %r8d
jmp 0x8d09d
leal (%r15,%rsi), %eax
cmpl %r8d, %eax
cmovll %eax, %r8d
leal (%r15,%r15), %eax
movl %eax, 0xc(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x60(%rsp)
leal 0x1(%r15), %eax
cmpl %esi, %eax
cmovgel %esi, %eax
movl $0x1, %ebp
movl %r15d, %ecx
shlq %cl, %rbp
testl %eax, %eax
jle 0x8d0fb
movl %eax, %eax
xorl %ecx, %ecx
leaq 0x1a0932(%rip), %rdx    # 0x22da10
movq %rbp, %r9
movzbl (%rdi,%rcx), %r10d
movzbl (%rdx,%r10), %r10d
orq %r9, 0x40(%rsp,%r10,8)
addq %r9, %r9
incq %rcx
cmpq %rcx, %rax
jne 0x8d0e1
movq %rdi, 0x80(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
orb $0x1, %cl
movq $-0x1, %r13
shlq %cl, %r13
movq $0x0, 0x60(%rsp)
movq %rbp, %r14
negq %r14
leal (%r8,%r8,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
movq %r8, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
jae 0x8d1a9
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
callq 0x2370
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %r8
movq %rax, 0xd0(%rbx)
leal -0x1(%r8), %edi
leal (%r15,%r15,2), %eax
movl %eax, 0x14(%rsp)
leal -0x1(%rsi), %edx
decq %rbp
xorq %r14, %r13
movq $0x0, 0xc0(%rbx)
movl $0x1, %eax
movl 0xc(%rsp), %ecx
shlq %cl, %rax
movq %rax, 0x78(%rsp)
cmpl $0x2, %r8d
jl 0x8d3f4
movl %r15d, %eax
subl %esi, %eax
incl %eax
movl %eax, 0x1c(%rsp)
movslq %r15d, %rax
movslq %esi, %rcx
movq %rcx, 0x90(%rsp)
movslq %edx, %rcx
movq %rcx, 0x68(%rsp)
movl %edi, 0x18(%rsp)
movl %edi, %ecx
movq %rcx, 0x88(%rsp)
movl %r15d, %r14d
negl %r14d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r11d, %r11d
movq %rax, 0x70(%rsp)
movq %rax, %rdi
movq %r15, 0x30(%rsp)
movl %r15d, %esi
movq 0x38(%rsp), %rax
movzbl (%rax,%r11), %r8d
leaq 0x1a07ce(%rip), %rax    # 0x22da10
movzbl (%rax,%r8), %r8d
movq 0x40(%rsp,%r8,8), %r8
orq %rbp, %r8
movq %r8, %r15
andq %r13, %r15
addq %r13, %r15
xorq %r13, %r15
orq %r8, %r15
testb $0x1, %r15b
jne 0x8d270
cmpl 0x14(%rsp), %esi
jge 0x8d575
incl %esi
movq %r15, %r8
andq %r13, %r8
orq %r15, %r13
notq %r13
movq %rbp, %r12
orq %r13, %r12
movq %r15, %r13
shrq %r13
movq %r12, %rbp
andq %r13, %rbp
orq %r12, %r13
notq %r13
orq %r8, %r13
movl 0x10(%rsp), %eax
cmpl 0x30(%rsp), %eax
jle 0x8d313
movl 0x1c(%rsp), %r9d
addl %r11d, %r9d
js 0x8d313
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jne 0x8d2e5
movq %r11, %r9
subq 0x70(%rsp), %r9
movl %esi, %ecx
cmpq 0x68(%rsp), %r9
jge 0x8d2ff
xorl %r9d, %r9d
movl %esi, %ecx
btq %r9, %r13
adcl $0x0, %ecx
btq %r9, %rbp
sbbl $0x0, %ecx
incq %r9
leal (%r9,%r14), %r10d
cmpl %edx, %r10d
jl 0x8d2c9
jmp 0x8d2ff
movl 0xc(%rsp), %eax
movl %eax, %r10d
subl %r9d, %r10d
js 0x8d2ff
btq %r10, %r8
sbbl $0x0, %ecx
btq %r10, %r12
adcl $0x0, %ecx
cmpl 0x28(%rbx), %ecx
jg 0x8d313
cmpl 0x2c(%rbx), %ecx
jge 0x8d313
movl %ecx, 0x2c(%rbx)
movl %edx, 0x14(%rbx)
movl %r11d, 0x20(%rbx)
shrq 0x40(%rsp)
shrq 0x48(%rsp)
shrq 0x50(%rsp)
shrq 0x58(%rsp)
incq %rdi
cmpq 0x90(%rsp), %rdi
jge 0x8d35d
movq 0x80(%rsp), %rax
movzbl (%rax,%rdi), %r9d
leaq 0x1a06c8(%rip), %rax    # 0x22da10
movzbl (%rax,%r9), %r9d
cmpq $0x3, %r9
ja 0x8d35d
movq 0x78(%rsp), %rax
orq %rax, 0x40(%rsp,%r9,8)
incq %r11
movq 0xc0(%rbx), %r9
movq 0xd0(%rbx), %r10
leaq 0x1(%r9), %rax
movq %rax, 0xc0(%rbx)
movq %r15, (%r10,%r9,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r9
movq %r9, 0xc0(%rbx)
movq %r13, (%r10,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r9
movq %r9, 0xc0(%rbx)
movq %rbp, (%r10,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r9
movq %r9, 0xc0(%rbx)
movq %r12, (%r10,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r9
movq %r9, 0xc0(%rbx)
movq %r8, (%r10,%rax,8)
incq %r14
cmpq 0x88(%rsp), %r11
jne 0x8d231
movl %r11d, %eax
movq 0x30(%rsp), %r15
movl 0x18(%rsp), %edi
jmp 0x8d3f9
xorl %eax, %eax
movl %r15d, %esi
movl %edi, %r14d
movq 0x38(%rsp), %rcx
movzbl (%rcx,%rax), %eax
leaq 0x1a0604(%rip), %rcx    # 0x22da10
movzbl (%rcx,%rax), %eax
movq 0x40(%rsp,%rax,8), %rax
orq %rbp, %rax
movq %rax, %rdi
andq %r13, %rdi
addq %r13, %rdi
xorq %r13, %rdi
orq %rax, %rdi
testb $0x1, %dil
jne 0x8d439
cmpl 0x14(%rsp), %esi
jge 0x8d575
incl %esi
movq %rdi, %r8
andq %r13, %r8
orq %rdi, %r13
notq %r13
orq %r13, %rbp
movq %rdi, %rax
shrq %rax
movq %rbp, %rcx
andq %rax, %rcx
orq %rbp, %rax
notq %rax
orq %r8, %rax
movq 0xc0(%rbx), %r9
movq 0xd0(%rbx), %r10
leaq 0x1(%r9), %r11
movq %r11, 0xc0(%rbx)
movq %rdi, (%r10,%r9,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rax, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rcx, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rbp, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r8, (%r10,%rdi,8)
cmpl %r15d, 0x10(%rsp)
movq 0x28(%rsp), %r8
jle 0x8d53b
movl %r14d, %r10d
movl %r14d, %edi
subl %r15d, %edi
cmpl %edx, %edi
jge 0x8d527
movl %r8d, %edi
subl %r15d, %edi
movq 0x20(%rsp), %r9
movl %eax, %edx
andl $0x1, %edx
addl %edx, %esi
movl %ecx, %edx
andl $0x1, %edx
subl %edx, %esi
cmpl %r15d, %esi
jg 0x8d518
cmpl 0x2c(%rbx), %esi
jge 0x8d518
movl %esi, 0x2c(%rbx)
movl %edi, 0x14(%rbx)
movl %r10d, 0x20(%rbx)
shrq %rax
shrq %rcx
incl %edi
cmpl %edi, %r9d
jne 0x8d4f6
decl %edi
cmpl %r15d, %esi
jg 0x8d53b
cmpl 0x2c(%rbx), %esi
jge 0x8d53b
movl %esi, 0x2c(%rbx)
movl %edi, 0x14(%rbx)
movl %r10d, 0x20(%rbx)
movl 0x20(%rbx), %ecx
subl 0x1c(%rbx), %ecx
incl %ecx
cmpl %r8d, %ecx
je 0x8d565
movslq %r8d, %rsi
movq 0xc0(%rbx), %rax
xorl %edx, %edx
divq %rsi
movslq %ecx, %rcx
imulq %rax, %rcx
movq %rcx, 0xc0(%rbx)
movq %rbx, %rdi
movl %r15d, %esi
movl $0x1, %edx
callq 0x9c469
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%rbx), %ebp
subl 0x1c(%rbx), %ebp
incl %ebp
cmpl $0x3fff, %ebp           # imm = 0x3FFF
jb 0x8d602
movl $0x2, %r14d
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8d5d5
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw $0x3fff, (%rcx,%rax,2)  # imm = 0x3FFF
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
cmpl $0x3ffe, %ebp           # imm = 0x3FFE
ja 0x8d59d
testl %ebp, %ebp
je 0x8d575
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8d647
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw %bp, (%rcx,%rax,2)
jmp 0x8d575