// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_semi_64_w_absent_diag(char*, int, char*, int, int, int, bit_extz_t*)
inline void ed_band_cal_semi_64_w_absent_diag(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, int32_t abs_diag, bit_extz_t *ez)
{
	init_base_ed(*ez, thre, pn, tn); ez->ps = ez->pe = -1; ez->ts = 0; ez->te = tn-1;
	Word c, Peq[5] = {0}, VP = 0, VN, X, D0, HN, HP, mm;
	int32_t bd, i, err = abs_diag, i_bd, last_high = (thre<<1), tn0 = tn - 1, cut = thre+last_high;
	if((pn > tn + cut) || (tn > pn + cut)) return;

	bd = ((thre<<1)+1)-abs_diag; bd = ((bd<=pn)?bd:pn); i_bd = abs_diag; 
	for (i = 0, mm = (((Word)1)<<i_bd); i < bd; i++) {
        Peq[seq_nt4_table[(uint8_t)pstr[i]]] |= mm; mm <<= 1;
    }
	i_bd = (thre<<1)-abs_diag; VN = (((Word)1)<<(abs_diag))-1; 

	i = 0; Peq[4] = 0; mm = ((Word)1 << (thre<<1));///for the incoming char/last char**
	while (i < tn0) {
		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; c = 4;
		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 - abs_diag;/**up bound**/
    /**in most cases, ai = (thre<<1)**/
    int32_t ai = pn - tn + abs_diag, uge = INT32_MAX; i = 0;
	for (i = 0; site < 0 && i < ai; i++, site++) {
		err += ((VP >> i)&(1ULL)); err -= ((VN >> i)&(1ULL));
	}
    if ((err <= thre) && (err <= ez->err)) {
        ez->err = err; ez->pe = site;
    }
    site -= i;
    while (i < ai) {
        err += ((VP >> i)&(1ULL)); err -= ((VN >> i)&(1ULL)); ++i;
        if ((err <= thre) && (err <= ez->err)) {
            ez->err = err; ez->pe = site + i;
        }
        if(i == thre) uge = err;
    }
    
    if((uge <= thre) && (uge == ez->err)) ez->pe = site + thre;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x38(%rsp), %rax
movl %r8d, 0x28(%rax)
movl $0x7fffffff, 0x2c(%rax) # imm = 0x7FFFFFFF
movl %esi, 0x18(%rax)
movl %ecx, 0x24(%rax)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rax)
movq $-0x1, 0x10(%rax)
movl $0x0, 0x1c(%rax)
leal -0x1(%rcx), %r10d
movq %r10, -0x48(%rsp)
movl %r10d, 0x20(%rax)
movdqa %xmm0, -0x18(%rsp)
movdqa %xmm0, -0x28(%rsp)
movq $0x0, -0x8(%rsp)
movq %r8, -0x50(%rsp)
leal (%r8,%r8,2), %r8d
leal (%r8,%rcx), %eax
cmpl %esi, %eax
setl %al
movq %rsi, -0x40(%rsp)
movq %r8, -0x30(%rsp)
addl %esi, %r8d
movq %rcx, %rsi
cmpl %esi, %r8d
setl %cl
orb %al, %cl
jne 0x8b756
movq -0x50(%rsp), %rax
leal (%rax,%rax), %r10d
movl %r10d, %r8d
orl $0x1, %r8d
subl %r9d, %r8d
movq -0x40(%rsp), %rbp
cmpl %ebp, %r8d
cmovgel %ebp, %r8d
movl $0x1, %eax
movq %rax, -0x38(%rsp)
movl $0x1, %r14d
movl %r9d, %ecx
shlq %cl, %r14
testl %r8d, %r8d
jle 0x8b506
movl %r8d, %ecx
xorl %r8d, %r8d
leaq 0x1ae737(%rip), %r11    # 0x239c20
movq %r14, %rbx
movzbl (%rdi,%r8), %eax
movzbl (%r11,%rax), %eax
orq %rbx, -0x28(%rsp,%rax,8)
addq %rbx, %rbx
incq %r8
cmpq %r8, %rcx
jne 0x8b4ec
decq %r14
movq $0x0, -0x8(%rsp)
movl %r10d, %ecx
shlq %cl, -0x38(%rsp)
cmpl $0x2, %esi
jl 0x8b5fd
subl %r9d, %r10d
movslq %r10d, %r13
movslq %ebp, %rbp
movl -0x48(%rsp), %r10d
leaq (%rdi,%r13), %rbx
incq %rbx
incq %r13
xorl %r11d, %r11d
leaq 0x1ae6db(%rip), %r8     # 0x239c20
xorl %r12d, %r12d
movl %r9d, %ecx
movzbl (%rdx,%r11), %eax
movzbl (%r8,%rax), %eax
movq -0x28(%rsp,%rax,8), %rax
orq %r14, %rax
movq %rax, %rdi
andq %r12, %rdi
addq %r12, %rdi
xorq %r12, %rdi
orq %rax, %rdi
testb $0x1, %dil
jne 0x8b57e
cmpl -0x30(%rsp), %ecx
jge 0x8b756
incl %ecx
movdqa -0x28(%rsp), %xmm0
movdqa -0x18(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, -0x28(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, -0x18(%rsp)
leaq (%r11,%r13), %rax
cmpq %rbp, %rax
jge 0x8b5c3
movzbl (%rbx,%r11), %eax
movzbl (%r8,%rax), %eax
cmpq $0x3, %rax
ja 0x8b5c3
movq -0x38(%rsp), %r15
orq %r15, -0x28(%rsp,%rax,8)
movq %rdi, %rax
andq %r12, %rax
orq %rdi, %r12
notq %r12
movq %r14, %r15
orq %r12, %r15
shrq %rdi
movq %r15, %r14
andq %rdi, %r14
orq %r15, %rdi
notq %rdi
movq %rdi, %r12
orq %rax, %r12
incq %r11
cmpq %r11, %r10
jne 0x8b54b
movq -0x40(%rsp), %rbp
jmp 0x8b606
xorl %r10d, %r10d
movl %r9d, %ecx
xorl %r12d, %r12d
movzbl (%rdx,%r10), %eax
leaq 0x1ae60e(%rip), %rdx    # 0x239c20
movzbl (%rdx,%rax), %eax
movq -0x28(%rsp,%rax,8), %rax
orq %r14, %rax
movq %rax, %rdx
andq %r12, %rdx
addq %r12, %rdx
xorq %r12, %rdx
orq %rax, %rdx
testb $0x1, %dl
jne 0x8b64a
cmpl -0x30(%rsp), %ecx
jge 0x8b756
incl %ecx
movq -0x48(%rsp), %r13
movq -0x40(%rsp), %rbp
jmp 0x8b64f
movq -0x48(%rsp), %r13
movq %rdx, %rax
andq %r12, %rax
orq %rdx, %r12
notq %r12
orq %r12, %r14
shrq %rdx
movq %r14, %rdi
andq %rdx, %rdi
orq %r14, %rdx
notq %rdx
orq %rax, %rdx
subl %esi, %ebp
addl %r9d, %ebp
subl %r9d, %r13d
sets %al
testl %ebp, %ebp
movq %rsi, %r11
setg %sil
andb %al, %sil
xorl %r10d, %r10d
cmpb $0x1, %sil
jne 0x8b6c1
movl %ebp, %r8d
subl %r11d, %r9d
xorl %r10d, %r10d
movq 0x38(%rsp), %r15
movq %r10, %rax
btq %r10, %rdx
adcl $0x0, %ecx
btq %r10, %rdi
sbbl $0x0, %ecx
incq %r10
cmpl %eax, %r9d
je 0x8b6bc
cmpq %r8, %r10
jb 0x8b69e
addl %r10d, %r13d
jmp 0x8b6c6
movq 0x38(%rsp), %r15
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpl -0x50(%rsp), %ecx
jg 0x8b6e1
movl %ecx, 0x2c(%r15)
movl %r13d, 0x14(%r15)
movl %ecx, %eax
cmpl %ebp, %r10d
jge 0x8b736
movl -0x50(%rsp), %r9d
movl %r10d, %ebx
movslq %ebp, %rsi
movq %r9, %r11
decq %r11
movq %r13, %r12
leal 0x1(%r13), %ebp
btq %rbx, %rdx
adcl $0x0, %ecx
btq %rbx, %rdi
sbbl $0x0, %ecx
cmpl %r9d, %ecx
jg 0x8b71f
cmpl %eax, %ecx
jg 0x8b71f
movl %ecx, 0x2c(%r15)
movl %ebp, 0x14(%r15)
movl %ecx, %eax
cmpq %rbx, %r11
cmovel %ecx, %r8d
leaq 0x1(%rbx), %r14
incl %ebp
movq %r14, %rbx
cmpq %rsi, %r14
jl 0x8b6fe
jmp 0x8b739
movq %r13, %r12
cmpl -0x50(%rsp), %r8d
jg 0x8b756
cmpl %eax, %r8d
jne 0x8b756
subl %r10d, %r12d
addl -0x50(%rsp), %r12d
movq 0x38(%rsp), %rax
movl %r12d, 0x14(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq