// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, %eax
movl %r8d, 0x28(%r9)
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movl %esi, 0x18(%r9)
movl %ecx, 0x24(%r9)
xorl %ecx, %ecx
movl %ecx, 0x1c(%r9)
leal (%r8,%rax), %r10d
cmpl %esi, %r10d
setl %bl
leal (%r8,%rsi), %r11d
subl %eax, %r11d
setl %r10b
orb %bl, %r10b
pxor %xmm0, %xmm0
movdqu %xmm0, (%r9)
movl %ecx, 0x10(%r9)
jne 0x93b3c
leal (%r8,%r8), %r10d
movdqa %xmm0, -0x28(%rsp)
movdqa %xmm0, -0x38(%rsp)
leal 0x1(%r8), %ebx
cmpl %esi, %ebx
cmovgel %esi, %ebx
movq $0x0, -0x18(%rsp)
movl $0x1, %ecx
movq %rcx, -0x40(%rsp)
movl $0x1, %ebp
movl %r8d, %ecx
shlq %cl, %rbp
testl %ebx, %ebx
jle 0x9396e
movl %ebx, %ecx
xorl %ebx, %ebx
leaq 0x1a62cf(%rip), %r14    # 0x239c20
movq %rbp, %r15
movzbl (%rdi,%rbx), %r12d
movzbl (%r14,%r12), %r12d
orq %r15, -0x38(%rsp,%r12,8)
addq %r15, %r15
incq %rbx
cmpq %rbx, %rcx
jne 0x93954
leal -0x1(%rax), %r14d
leal (%r8,%r8,2), %ecx
movl %ecx, -0x4c(%rsp)
movq $0x0, -0x18(%rsp)
movl %r10d, %ecx
orb $0x1, %cl
movq $-0x1, %rbx
shlq %cl, %rbx
leaq -0x1(%rbp), %r12
negq %rbp
xorq %rbx, %rbp
movl %r10d, %ecx
shlq %cl, -0x40(%rsp)
cmpl $0x2, %eax
movq %r8, -0x48(%rsp)
movl %r14d, -0x50(%rsp)
jl 0x93a95
movslq %r8d, %r10
movq %rsi, -0x8(%rsp)
movq %r8, %rax
movslq %esi, %r13
movl %r14d, %ecx
leaq (%rdi,%r10), %r8
incq %r8
incq %r10
xorl %ebx, %ebx
leaq 0x1a6244(%rip), %rsi    # 0x239c20
movzbl (%rdx,%rbx), %edi
movzbl (%rsi,%rdi), %edi
movq -0x38(%rsp,%rdi,8), %rdi
orq %r12, %rdi
movq %rdi, %r14
andq %rbp, %r14
addq %rbp, %r14
xorq %rbp, %r14
orq %rdi, %r14
testb $0x1, %r14b
jne 0x93a0d
cmpl -0x4c(%rsp), %eax
jge 0x93b3c
incl %eax
movdqa -0x38(%rsp), %xmm0
movdqa -0x28(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, -0x38(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, -0x28(%rsp)
leaq (%r10,%rbx), %rdi
cmpq %r13, %rdi
jge 0x93a51
movzbl (%r8,%rbx), %edi
movzbl (%rsi,%rdi), %edi
cmpq $0x3, %rdi
ja 0x93a51
movq -0x40(%rsp), %r15
orq %r15, -0x38(%rsp,%rdi,8)
movq %r14, %rdi
andq %rbp, %rdi
orq %r14, %rbp
notq %rbp
movq %r12, %r15
orq %rbp, %r15
shrq %r14
movq %r15, %r12
andq %r14, %r12
orq %r15, %r14
notq %r14
movq %r14, %rbp
orq %rdi, %rbp
incq %rbx
cmpq %rbx, %rcx
jne 0x939dc
movq -0x8(%rsp), %rsi
movq -0x48(%rsp), %r8
movl -0x50(%rsp), %r14d
jmp 0x93a9a
xorl %ecx, %ecx
movl %r8d, %eax
movzbl (%rdx,%rcx), %ecx
leaq 0x1a617b(%rip), %rdx    # 0x239c20
movzbl (%rdx,%rcx), %ecx
movq -0x38(%rsp,%rcx,8), %rdx
orq %r12, %rdx
movq %rdx, %rcx
andq %rbp, %rcx
addq %rbp, %rcx
xorq %rbp, %rcx
orq %rdx, %rcx
testb $0x1, %cl
jne 0x93ad7
cmpl -0x4c(%rsp), %eax
jge 0x93b3c
incl %eax
movq -0x48(%rsp), %r8
movl -0x50(%rsp), %r14d
movl %r14d, %edx
subl %r8d, %edx
decl %esi
cmpl %esi, %edx
jge 0x93b1f
movq %rcx, %rdi
andq %rbp, %rdi
orq %rcx, %rbp
notq %rbp
orq %rbp, %r12
shrq %rcx
movq %r12, %rdx
andq %rcx, %rdx
orq %r12, %rcx
notq %rcx
orq %rdi, %rcx
movl %ecx, %edi
andl $0x1, %edi
addl %edi, %eax
shrq %rcx
movl %edx, %edi
andl $0x1, %edi
subl %edi, %eax
shrq %rdx
decl %r11d
jne 0x93b04
movl %esi, %edx
cmpl %esi, %edx
jne 0x93b3c
cmpl -0x48(%rsp), %eax
jg 0x93b3c
movq %rsi, %rcx
movl %eax, 0x2c(%r9)
movl %ecx, 0x14(%r9)
movl -0x50(%rsp), %eax
movl %eax, 0x20(%r9)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq