// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %r9, %rbx
movl %r8d, %r13d
movq %rdx, 0x30(%rsp)
andq $0x0, 0xa8(%r9)
movl $0x1, 0x30(%r9)
movl 0x2c(%r9), %eax
cmpl %r8d, %eax
jle 0x5872c
movl %ecx, %r9d
movl %esi, %r11d
movl %eax, 0x8(%rsp)
movl %r13d, 0x28(%rbx)
movl $0x7fffffff, 0x2c(%rbx) # imm = 0x7FFFFFFF
movl %esi, 0x18(%rbx)
movl %ecx, 0x24(%rbx)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x1c(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rbx)
movq %rax, 0x10(%rbx)
leal (%r9,%r13), %eax
cmpl %esi, %eax
jge 0x58750
movl %eax, %r11d
jmp 0x5875b
testl %eax, %eax
je 0x58c2c
movl %eax, 0x8(%rsp)
movl 0x14(%rbx), %r11d
movl 0x20(%rbx), %r9d
subl 0x10(%rbx), %r11d
incl %r11d
subl 0x1c(%rbx), %r9d
incl %r9d
jmp 0x5875b
leal (%r11,%r13), %eax
cmpl %r9d, %eax
cmovll %eax, %r9d
leal -0x1(%r9), %r10d
andq $0x0, 0x60(%rsp)
leal (%r13,%r13,2), %eax
movl %eax, 0xc(%rsp)
pxor %xmm0, %xmm0
leal 0x1(%r13), %eax
cmpl %r11d, %eax
cmovgel %r11d, %eax
pushq $0x1
popq %r12
movq %r12, 0x28(%rsp)
movl %r13d, %ecx
shlq %cl, %r12
movdqa %xmm0, 0x50(%rsp)
movdqa %xmm0, 0x40(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0x19335a(%rip), %r8     # 0x1ebb00
movq %r12, %rdx
cmpq %rcx, %rax
je 0x587c4
movzbl (%rdi,%rcx), %esi
movzbl (%r8,%rsi), %esi
orq %rdx, 0x40(%rsp,%rsi,8)
addq %rdx, %rdx
incq %rcx
jmp 0x587a9
movq %rdi, 0x78(%rsp)
andq $0x0, 0x60(%rsp)
leal (,%r13,2), %eax
movq %rax, 0x20(%rsp)
leal 0x1(%rax), %ecx
pushq $-0x1
popq %r14
shlq %cl, %r14
movq %r12, %r15
negq %r15
movq %r9, 0x70(%rsp)
leal (%r9,%r9,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
movq %r13, 0x10(%rsp)
jae 0x5887e
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
movl %r10d, %ebp
movq %r11, %r13
callq 0x2370
movq %r13, %r11
leaq 0x193291(%rip), %r8     # 0x1ebb00
movl %ebp, %r10d
movq 0x10(%rsp), %r13
movq %rax, 0xd0(%rbx)
leal -0x1(%r11), %eax
andq $0x0, 0xc0(%rbx)
movq 0x20(%rsp), %rcx
shlq %cl, 0x28(%rsp)
decq %r12
xorq %r15, %r14
movl %r13d, %ecx
subl %r11d, %ecx
incl %ecx
movl %ecx, 0x1c(%rsp)
movslq %r13d, %rsi
movslq %r11d, %rcx
movq %rcx, 0x80(%rsp)
xorl %ecx, %ecx
testl %r10d, %r10d
movl $0x0, %edx
movl %r10d, 0x18(%rsp)
cmovgl %r10d, %edx
movq %rdx, 0x38(%rsp)
movl %r13d, %r10d
negl %r10d
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movl %r13d, %ebp
cmpq 0x38(%rsp), %rcx
je 0x58a9a
movq 0x30(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
movzbl (%r8,%rdx), %edx
movq 0x40(%rsp,%rdx,8), %rdx
orq %r12, %rdx
movq %rdx, %r15
andq %r14, %r15
addq %r14, %r15
xorq %r14, %r15
orq %rdx, %r15
testb $0x1, %r15b
jne 0x5891d
cmpl 0xc(%rsp), %ebp
jge 0x58bc1
incl %ebp
movl %ebp, %r8d
movq %r15, %rdx
andq %r14, %rdx
orq %r15, %r14
notq %r14
orq %r14, %r12
movq %r15, %r14
shrq %r14
movq %r12, %rbp
andq %r14, %rbp
orq %r12, %r14
notq %r14
orq %rdx, %r14
cmpl %r13d, 0x8(%rsp)
jle 0x589af
movl 0x1c(%rsp), %edi
addl %ecx, %edi
js 0x589af
cmpl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
jne 0x5897f
xorl %edi, %edi
movl %r8d, %r11d
leal (%r10,%rdi), %r13d
cmpl %eax, %r13d
jge 0x58999
btq %rdi, %r14
adcl $0x0, %r11d
btq %rdi, %rbp
sbbl $0x0, %r11d
incq %rdi
jmp 0x58961
movq 0x20(%rsp), %r13
subl %edi, %r13d
js 0x58999
btq %r13, %rdx
sbbl $0x0, %r11d
btq %r13, %r12
adcl $0x0, %r11d
cmpl 0x28(%rbx), %r11d
jg 0x589af
cmpl 0x2c(%rbx), %r11d
jge 0x589af
movl %r11d, 0x2c(%rbx)
movl %eax, 0x14(%rbx)
movl %ecx, 0x20(%rbx)
movdqa 0x40(%rsp), %xmm0
movdqa 0x50(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, 0x40(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, 0x50(%rsp)
incq %rsi
cmpq 0x80(%rsp), %rsi
jge 0x58a03
movq 0x78(%rsp), %rdi
movzbl (%rdi,%rsi), %edi
leaq 0x193112(%rip), %r9     # 0x1ebb00
movzbl (%r9,%rdi), %edi
cmpq $0x3, %rdi
ja 0x58a03
movq 0x28(%rsp), %r9
orq %r9, 0x40(%rsp,%rdi,8)
incq %rcx
movq 0xc0(%rbx), %rdi
movq 0xd0(%rbx), %r13
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r15, (%r13,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r14, (%r13,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rbp, (%r13,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r12, (%r13,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %rdx, (%r13,%rdi,8)
incq %r10
movq %rbp, %r12
movq 0x10(%rsp), %r13
movl %r8d, %ebp
leaq 0x19306b(%rip), %r8     # 0x1ebb00
jmp 0x588db
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movzbl (%rcx,%rdx), %edx
movzbl (%r8,%rdx), %edx
movq 0x40(%rsp,%rdx,8), %rdx
orq %r12, %rdx
movq %rdx, %rdi
andq %r14, %rdi
addq %r14, %rdi
xorq %r14, %rdi
orq %rdx, %rdi
testb $0x1, %dil
jne 0x58ad6
cmpl 0xc(%rsp), %ebp
jge 0x58bc1
incl %ebp
movq %rdi, %r8
andq %r14, %r8
orq %rdi, %r14
notq %r14
orq %r14, %r12
movq %rdi, %rdx
shrq %rdx
movq %r12, %r14
andq %rdx, %r14
orq %r12, %rdx
notq %rdx
orq %r8, %rdx
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 %rdx, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r14, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r12, (%r10,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r9
movq %r9, 0xc0(%rbx)
movq %r8, (%r10,%rdi,8)
movq 0x10(%rsp), %rsi
cmpl %esi, 0x8(%rsp)
movq 0x70(%rsp), %r9
movl 0x18(%rsp), %ecx
jle 0x58be6
movl %r9d, %edi
subl %esi, %edi
leal -0x1(%rdi), %r8d
cmpl %eax, %r8d
jge 0x58bd3
movl %edx, %r8d
andl $0x1, %r8d
addl %r8d, %ebp
movl %r14d, %r8d
andl $0x1, %r8d
subl %r8d, %ebp
cmpl %esi, %ebp
jg 0x58bb7
cmpl 0x2c(%rbx), %ebp
jge 0x58bb7
movl %ebp, 0x2c(%rbx)
movl %edi, 0x14(%rbx)
movl %ecx, 0x20(%rbx)
shrq %rdx
shrq %r14
incl %edi
jmp 0x58b88
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl %esi, %ebp
jg 0x58be6
cmpl 0x2c(%rbx), %ebp
jge 0x58be6
movl %ebp, 0x2c(%rbx)
movl %r8d, 0x14(%rbx)
movl %ecx, 0x20(%rbx)
movl 0x20(%rbx), %ecx
subl 0x1c(%rbx), %ecx
incl %ecx
cmpl %r9d, %ecx
je 0x58c10
movslq %r9d, %rdi
movq 0xc0(%rbx), %rax
xorl %edx, %edx
divq %rdi
movslq %ecx, %rcx
imulq %rax, %rcx
movq %rcx, 0xc0(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x65f7b
leaq 0xa8(%rbx), %rdi
movl 0x20(%rbx), %edx
subl 0x1c(%rbx), %edx
incl %edx
xorl %esi, %esi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x62885