// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_extension_64_0_w(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_extension_64_0_w(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, bit_extz_t *ez)
{
	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;
	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;

	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;
		}

		{
			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, 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[i_bd]]; 
            if(c < 4) Peq[c] |= mm;
        }
	}
	ed_core_64(Peq, VP, VN, X, D0, HN, HP, (uint8_t)tstr[i]);
	if (!(D0&(1ULL))) {
		++err; if (err>cut) return;
	}

	int32_t site = tn - 1 - thre;/**up bound; site:[tn - 1 - thre, tn - 1 + thre]**/\
    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;
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movl -0x20(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x28(%rbp), %rax
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movl -0xc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x18(%rax)
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x1c(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x28(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movl -0xc(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0xb98a9
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0xb98c1
movl -0x1c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0xb98bf
movl -0xc(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xb98c1
movl -0x1c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x20(%rbp), %eax
movl -0x20(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x48(%rbp)
movl $0x7fffffff, -0x4c(%rbp) # imm = 0x7FFFFFFF
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2100
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0xb9913
movl -0x3c(%rbp), %eax
movl %eax, -0xc0(%rbp)
jmp 0xb991c
movl -0xc(%rbp), %eax
movl %eax, -0xc0(%rbp)
movl -0xc0(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x40(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0xb9994
movq -0xb8(%rbp), %rcx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0x2d0e76(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rdx), %eax
orq -0x80(%rbp,%rax,8), %rcx
movq %rcx, -0x80(%rbp,%rax,8)
movq -0xb8(%rbp), %rax
shlq %rax
movq %rax, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb9946
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
movq $0x0, -0x60(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x90(%rbp)
movl -0x20(%rbp), %eax
shll %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rax
xorq -0x88(%rbp), %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x20(%rbp), %eax
shll %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, -0xb8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xb9cc7
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d0da3(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x80(%rbp,%rax,8), %rax
orq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rax
movq -0x98(%rbp), %rcx
andq -0x88(%rbp), %rcx
addq %rcx, %rax
xorq -0x88(%rbp), %rax
orq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rax
andq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
orq -0xa0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rax
shrq %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
andq -0xb0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
orq -0xb0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xb9b2b
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xb9b29
jmp 0xb9ec3
jmp 0xb9b2b
movl -0x2c(%rbp), %eax
subl -0x20(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x2c(%rbp), %eax
addl -0x20(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0xb9c41
cmpl $0x7fffffff, -0x4c(%rbp) # imm = 0x7FFFFFFF
jne 0xb9bba
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0xb9bb8
movq -0x88(%rbp), %rax
movl -0x50(%rbp), %ecx
shrq %cl, %rax
movq %rax, %rcx
andq $0x1, %rcx
movslq -0x4c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x4c(%rbp)
movq -0x90(%rbp), %rax
movl -0x50(%rbp), %ecx
shrq %cl, %rax
movq %rax, %rcx
andq $0x1, %rcx
movslq -0x4c(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x4c(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0xb9b60
jmp 0xb9c09
movl -0x20(%rbp), %eax
shll %eax
subl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0xb9c07
movq -0xb0(%rbp), %rax
movl -0x50(%rbp), %ecx
shrq %cl, %rax
movq %rax, %rcx
andq $0x1, %rcx
movslq -0x4c(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x4c(%rbp)
movq -0xa8(%rbp), %rax
movl -0x50(%rbp), %ecx
shrq %cl, %rax
movq %rax, %rcx
andq $0x1, %rcx
movslq -0x4c(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x4c(%rbp)
jmp 0xb9c09
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0xb9c3f
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xb9c3f
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xb9c41
movq -0x80(%rbp), %rax
shrq %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
shrq %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
shrq %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
shrq %rax
movq %rax, -0x68(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0xb9cc2
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d0b44(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq %rax, -0x58(%rbp)
cmpq $0x4, -0x58(%rbp)
jae 0xb9cc0
movq -0xb8(%rbp), %rcx
movq -0x58(%rbp), %rax
orq -0x80(%rbp,%rax,8), %rcx
movq %rcx, -0x80(%rbp,%rax,8)
jmp 0xb9cc2
jmp 0xb9a1c
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d0b04(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x80(%rbp,%rax,8), %rax
orq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x88(%rbp), %rax
movq -0x98(%rbp), %rcx
andq -0x88(%rbp), %rcx
addq %rcx, %rax
xorq -0x88(%rbp), %rax
orq -0x98(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x88(%rbp), %rax
andq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x90(%rbp), %rax
movq -0x88(%rbp), %rcx
orq -0xa0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xa0(%rbp), %rax
shrq %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
andq -0xb0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xa8(%rbp), %rax
movq -0x98(%rbp), %rcx
orq -0xb0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0xa0(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xb9dca
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xb9dc8
jmp 0xb9ec3
jmp 0xb9dca
movl -0x1c(%rbp), %eax
subl $0x1, %eax
subl -0x20(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xb9e89
movq -0x88(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x88(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x90(%rbp), %rax
shrq %rax
movq %rax, -0x90(%rbp)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xb9e84
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xb9e84
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0xbc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xb9de2
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xb9ec1
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xb9ec1
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0xbc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x20(%rax)
jmp 0xb9ec3
addq $0xc0, %rsp
popq %rbp
retq
nopl (%rax)