// File: chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_global_64_w(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_global_64_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;
    if((pn > tn + thre) || (tn > pn + thre)) return;
	int32_t i, err, tn0 = tn - 1, cut = thre+(thre<<1), bd, i_bd; 
	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));///for the incoming char/last char
	while (i < tn0) {
		// fprintf(stderr, "\ni::%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;
		}

		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;
			// fprintf(stderr, "c::%lu\n", c);
			// print_bit(Peq[c], (((thre<<1))+1), "Peq[c]");
		}
	}
	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**/\
    for (cut = pn - 1; site < cut; site++) {
        err += VP&(1ULL); VP >>= 1; err -= VN&(1ULL); VN >>= 1; 
    }

    if (site == cut && err <= thre) {
        ez->err = err; 
        ez->pe = pn-1; ez->te = tn-1;
    }
    return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %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)
movl -0xc(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jg 0xb7475
movl -0x1c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl -0x20(%rbp), %ecx
cmpl %ecx, %eax
jle 0xb747a
jmp 0xb78bf
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)
leaq -0x70(%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 0xb74bc
movl -0x3c(%rbp), %eax
movl %eax, -0xb0(%rbp)
jmp 0xb74c5
movl -0xc(%rbp), %eax
movl %eax, -0xb0(%rbp)
movl -0xb0(%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, -0xa8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0xb753d
movq -0xa8(%rbp), %rcx
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rdx
movzbl (%rax,%rdx), %eax
movl %eax, %edx
leaq 0x2d32cd(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rdx), %eax
orq -0x70(%rbp,%rax,8), %rcx
movq %rcx, -0x70(%rbp,%rax,8)
movq -0xa8(%rbp), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xb74ef
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x40(%rbp)
movq $0x0, -0x50(%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, -0x80(%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, -0x78(%rbp)
movq -0x80(%rbp), %rax
xorq -0x78(%rbp), %rax
movq %rax, -0x78(%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, -0xa8(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0xb7730
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d3209(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x70(%rbp,%rax,8), %rax
orq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
andq -0x78(%rbp), %rcx
addq %rcx, %rax
xorq -0x78(%rbp), %rax
orq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
andq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
orq -0x90(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
andq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movq -0x88(%rbp), %rcx
orq -0xa0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x90(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xb76aa
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xb76a8
jmp 0xb78bf
jmp 0xb76aa
movq -0x70(%rbp), %rax
shrq %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
shrq %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
shrq %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
shrq %rax
movq %rax, -0x58(%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 0xb772b
movq -0x8(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d30db(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq %rax, -0x48(%rbp)
cmpq $0x4, -0x48(%rbp)
jae 0xb7729
movq -0xa8(%rbp), %rcx
movq -0x48(%rbp), %rax
orq -0x70(%rbp,%rax,8), %rcx
movq %rcx, -0x70(%rbp,%rax,8)
jmp 0xb772b
jmp 0xb75b6
movq -0x18(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x2d309b(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x70(%rbp,%rax,8), %rax
orq -0x80(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
andq -0x78(%rbp), %rcx
addq %rcx, %rax
xorq -0x78(%rbp), %rax
orq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x78(%rbp), %rax
andq -0x90(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
orq -0x90(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x90(%rbp), %rax
shrq %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
andq -0xa0(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x98(%rbp), %rax
movq -0x88(%rbp), %rcx
orq -0xa0(%rbp), %rcx
xorq $-0x1, %rcx
orq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x90(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
jne 0xb7818
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jle 0xb7816
jmp 0xb78bf
jmp 0xb7818
movl -0x1c(%rbp), %eax
subl $0x1, %eax
subl -0x20(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0xac(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xb7886
movq -0x78(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x78(%rbp), %rax
shrq %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rcx
andq $0x1, %rcx
movslq -0x30(%rbp), %rax
subq %rcx, %rax
movl %eax, -0x30(%rbp)
movq -0x80(%rbp), %rax
shrq %rax
movq %rax, -0x80(%rbp)
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0xb7830
movl -0xac(%rbp), %eax
cmpl -0x38(%rbp), %eax
jne 0xb78bd
movl -0x30(%rbp), %eax
cmpl -0x20(%rbp), %eax
jg 0xb78bd
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x2c(%rax)
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)
jmp 0xb78bf
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)