// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_extension_64_1_w(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_extension_64_1_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 = 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;
	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;

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

		{
			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;
        }
	}
	ed_core_64(Peq, VP, VN, X, D0, HN, HP, (uint8_t)tstr[tidx-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->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;
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %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 $0x7fffffff, 0x1c(%rax) # imm = 0x7FFFFFFF
movq -0x28(%rbp), %rax
movl $0x7fffffff, 0x10(%rax) # imm = 0x7FFFFFFF
movl -0xc(%rbp), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x20(%rax)
movl -0xc(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0xbc27d
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0xc(%rbp)
jmp 0xbc295
movl -0x1c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0xbc293
movl -0xc(%rbp), %eax
addl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0xbc295
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
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x58(%rbp)
leaq -0x90(%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 0xbc2fe
movl -0x3c(%rbp), %eax
movl %eax, -0xd0(%rbp)
jmp 0xbc307
movl -0xc(%rbp), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%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, -0xc8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0xbc38a
movq -0xc8(%rbp), %rcx
movq -0x8(%rbp), %rax
movl -0x54(%rbp), %edx
subl -0x2c(%rbp), %edx
movslq %edx, %rdx
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0x2ce486(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rdx), %eax
orq -0x90(%rbp,%rax,8), %rcx
movq %rcx, -0x90(%rbp,%rax,8)
movq -0xc8(%rbp), %rax
shlq %rax
movq %rax, -0xc8(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xbc331
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
movq $0x0, -0x70(%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, -0xa0(%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, -0x98(%rbp)
movq -0xa0(%rbp), %rax
xorq -0x98(%rbp), %rax
movq %rax, -0x98(%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, -0xc8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xbc6e2
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
subl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2ce3a8(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x90(%rbp,%rax,8), %rax
orq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x98(%rbp), %rax
movq -0xa8(%rbp), %rcx
andq -0x98(%rbp), %rcx
addq %rcx, %rax
xorq -0x98(%rbp), %rax
orq -0xa8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
andq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
orq -0xb0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rax
shrq %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
andq -0xc0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xb8(%rbp), %rax
movq -0xa8(%rbp), %rcx
orq -0xc0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0xb0(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xbc529
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xbc527
jmp 0xbc8f2
jmp 0xbc529
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 0xbc645
cmpl $0x7fffffff, -0x4c(%rbp) # imm = 0x7FFFFFFF
jne 0xbc5b8
movl -0x30(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0xbc5b6
movq -0x98(%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 -0xa0(%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 0xbc55e
jmp 0xbc607
movl -0x20(%rbp), %eax
shll %eax
subl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
jl 0xbc605
movq -0xc0(%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 -0xb8(%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 0xbc607
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x28(%rcx), %eax
jg 0xbc643
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xbc643
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x54(%rbp), %ecx
subl -0x48(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x58(%rbp), %ecx
subl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0xbc645
movq -0x90(%rbp), %rax
shrq %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
shrq %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
shrq %rax
movq %rax, -0x78(%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 0xbc6dd
movq -0x8(%rbp), %rax
movl -0x54(%rbp), %ecx
subl -0x40(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2ce12f(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq %rax, -0x60(%rbp)
cmpq $0x4, -0x60(%rbp)
jae 0xbc6db
movq -0xc8(%rbp), %rcx
movq -0x60(%rbp), %rax
orq -0x90(%rbp,%rax,8), %rcx
movq %rcx, -0x90(%rbp,%rax,8)
jmp 0xbc6dd
jmp 0xbc412
movq -0x18(%rbp), %rax
movl -0x58(%rbp), %ecx
subl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2ce0e4(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x90(%rbp,%rax,8), %rax
orq -0xa0(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x98(%rbp), %rax
movq -0xa8(%rbp), %rcx
andq -0x98(%rbp), %rcx
addq %rcx, %rax
xorq -0x98(%rbp), %rax
orq -0xa8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x98(%rbp), %rax
andq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
orq -0xb0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xc0(%rbp)
movq -0xb0(%rbp), %rax
shrq %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
andq -0xc0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xb8(%rbp), %rax
movq -0xa8(%rbp), %rcx
orq -0xc0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0xb0(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xbc7ed
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xbc7eb
jmp 0xbc8f2
jmp 0xbc7ed
movl -0x1c(%rbp), %eax
subl $0x1, %eax
subl -0x20(%rbp), %eax
movl %eax, -0xcc(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0xcc(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xbc8b2
movq -0x98(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x98(%rbp), %rax
shrq %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0xa0(%rbp), %rax
shrq %rax
movq %rax, -0xa0(%rbp)
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xbc8ad
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xbc8ad
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x54(%rbp), %ecx
subl -0xcc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
subl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0xbc805
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xbc8f0
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x2c(%rcx), %eax
jge 0xbc8f0
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x54(%rbp), %ecx
subl -0xcc(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
subl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x1c(%rax)
jmp 0xbc8f2
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)