// File: /workspace/github_cpp_makefile_star2_O2/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, %r14d
movl %r8d, 0x28(%r9)
movl $0x7fffffff, 0x2c(%r9)  # imm = 0x7FFFFFFF
movl %esi, 0x18(%r9)
movl %ecx, 0x24(%r9)
andl $0x0, 0x1c(%r9)
leal (%r8,%r14), %eax
cmpl %esi, %eax
setl %al
leal (%r8,%rsi), %ecx
cmpl %r14d, %ecx
setl %cl
orb %al, %cl
pxor %xmm0, %xmm0
movdqu %xmm0, (%r9)
andl $0x0, 0x10(%r9)
testb %cl, %cl
jne 0x5e7cb
movq %rdx, %rbp
andq $0x0, -0x18(%rsp)
leal (%r8,%r8), %r10d
leal 0x1(%r8), %eax
cmpl %esi, %eax
movq %rsi, -0x40(%rsp)
cmovgel %esi, %eax
movabsq $0x1, %rbx
movq %rbx, %r12
movl %r8d, %ecx
shlq %cl, %rbx
movdqa %xmm0, -0x28(%rsp)
movdqa %xmm0, -0x38(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0x18d50d(%rip), %r15    # 0x1ebb00
movq %rbx, %r11
cmpq %rcx, %rax
je 0x5e611
movzbl (%rdi,%rcx), %esi
movzbl (%r15,%rsi), %esi
orq %r11, -0x38(%rsp,%rsi,8)
addq %r11, %r11
incq %rcx
jmp 0x5e5f6
movq %r9, -0x8(%rsp)
decl %r14d
leal (%r8,%r8,2), %r9d
andq $0x0, -0x18(%rsp)
leaq -0x1(%rbx), %rdx
movl %r10d, %ecx
orb $0x1, %cl
movabsq $-0x1, %rax
shlq %cl, %rax
movl %r10d, %ecx
movq %r12, %rsi
shlq %cl, %rsi
negq %rbx
xorq %rax, %rbx
movslq %r8d, %r10
xorl %r12d, %r12d
testl %r14d, %r14d
movl $0x0, %r13d
movq %r14, -0x50(%rsp)
cmovgl %r14d, %r13d
movslq -0x40(%rsp), %rax
addq %r10, %rdi
incq %rdi
incq %r10
movq %r8, %rcx
movq %r8, -0x48(%rsp)
movq %rsi, %r8
cmpq %r12, %r13
je 0x5e725
movzbl (%rbp,%r12), %esi
movzbl (%r15,%rsi), %esi
movq -0x38(%rsp,%rsi,8), %rsi
orq %rdx, %rsi
movq %rsi, %r11
andq %rbx, %r11
addq %rbx, %r11
xorq %rbx, %r11
orq %rsi, %r11
testb $0x1, %r11b
jne 0x5e6b6
cmpl %r9d, %ecx
jge 0x5e7cb
incl %ecx
movdqa -0x38(%rsp), %xmm0
movdqa -0x28(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, -0x38(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, -0x28(%rsp)
leaq (%r10,%r12), %rsi
cmpq %rax, %rsi
jge 0x5e6f6
movzbl (%rdi,%r12), %esi
movzbl (%r15,%rsi), %esi
cmpq $0x4, %rsi
jae 0x5e6f6
orq %r8, -0x38(%rsp,%rsi,8)
movq %r11, %rsi
andq %rbx, %rsi
orq %r11, %rbx
notq %rbx
orq %rbx, %rdx
shrq %r11
movq %rdx, %r14
andq %r11, %r14
orq %rdx, %r11
notq %r11
orq %rsi, %r11
incq %r12
movq %r11, %rbx
movq %r14, %rdx
jmp 0x5e67a
movzbl (%rbp,%r13), %eax
movzbl (%r15,%rax), %eax
movq -0x38(%rsp,%rax,8), %rsi
orq %rdx, %rsi
movq %rsi, %rax
andq %rbx, %rax
addq %rbx, %rax
xorq %rbx, %rax
orq %rsi, %rax
testb $0x1, %al
jne 0x5e752
cmpl %r9d, %ecx
jge 0x5e7cb
incl %ecx
movq -0x50(%rsp), %rdi
movq -0x48(%rsp), %r9
movq %rax, %rsi
andq %rbx, %rsi
orq %rax, %rbx
notq %rbx
orq %rbx, %rdx
shrq %rax
movq %rdx, %r8
andq %rax, %r8
orq %rdx, %rax
notq %rax
orq %rsi, %rax
subl %r9d, %edi
movq -0x40(%rsp), %r9
leal -0x1(%r9), %esi
movl %edi, %r10d
cmpl %esi, %r10d
jge 0x5e7ad
movl %eax, %edx
andl $0x1, %edx
addl %ecx, %edx
shrq %rax
movl %r8d, %ecx
andl $0x1, %ecx
subl %ecx, %edx
shrq %r8
incl %r10d
movl %edx, %ecx
jmp 0x5e78c
cmpl %r9d, %edi
jge 0x5e7cb
cmpl -0x48(%rsp), %ecx
jg 0x5e7cb
movq -0x8(%rsp), %rdx
movl %ecx, 0x2c(%rdx)
movl %esi, 0x14(%rdx)
movq -0x50(%rsp), %rax
movl %eax, 0x20(%rdx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq