// File: /workspace/github_cpp_makefile_star2_O2/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
movl %r9d, -0x4c(%rsp)
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)
orq $-0x1, 0x10(%rax)
andl $0x0, 0x1c(%rax)
leal -0x1(%rcx), %ebx
movl %ebx, 0x20(%rax)
movdqa %xmm0, -0x28(%rsp)
movdqa %xmm0, -0x38(%rsp)
andq $0x0, -0x18(%rsp)
movq %r8, -0x48(%rsp)
leal (%r8,%r8,2), %r15d
leal (%r15,%rcx), %eax
cmpl %esi, %eax
setl %al
movq %rsi, -0x40(%rsp)
addl %r15d, %esi
movq %rcx, -0x8(%rsp)
cmpl %ecx, %esi
setl %cl
orb %al, %cl
jne 0x57c23
movq -0x48(%rsp), %r8
leal (%r8,%r8), %r10d
movl %r10d, %eax
orl $0x1, %eax
movl -0x4c(%rsp), %ecx
subl %ecx, %eax
movq -0x40(%rsp), %rsi
cmpl %esi, %eax
cmovgel %esi, %eax
movabsq $0x1, %rsi
movq %rsi, %r12
shlq %cl, %r12
movl %r8d, %ecx
movq %rcx, -0x10(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0x1940fa(%rip), %rbp    # 0x1ebb00
movq %r12, %r8
cmpq %rcx, %rax
je 0x57a26
movzbl (%rdi,%rcx), %r9d
movzbl (%rbp,%r9), %r9d
orq %r8, -0x38(%rsp,%r9,8)
addq %r8, %r8
incq %rcx
jmp 0x57a09
movl %r10d, %eax
movl -0x4c(%rsp), %r14d
subl %r14d, %eax
andq $0x0, -0x18(%rsp)
movl %r10d, %ecx
shlq %cl, %rsi
decq %r12
movslq %eax, %r10
movslq -0x40(%rsp), %r11
xorl %r9d, %r9d
testl %ebx, %ebx
movl $0x0, %r8d
cmovgl %ebx, %r8d
leaq (%rdi,%r10), %rax
incq %rax
incq %r10
movl %r14d, %ecx
xorl %r14d, %r14d
cmpq %r9, %r8
je 0x57b12
movzbl (%rdx,%r9), %edi
movzbl (%rbp,%rdi), %edi
movq -0x38(%rsp,%rdi,8), %r13
orq %r12, %r13
movq %r13, %rdi
andq %r14, %rdi
addq %r14, %rdi
xorq %r14, %rdi
orq %r13, %rdi
testb $0x1, %dil
jne 0x57aa2
cmpl %r15d, %ecx
jge 0x57c23
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,%r9), %r13
cmpq %r11, %r13
jge 0x57ae3
movzbl (%rax,%r9), %r13d
movzbl (%rbp,%r13), %r13d
cmpq $0x3, %r13
ja 0x57ae3
orq %rsi, -0x38(%rsp,%r13,8)
movq %rdi, %r13
andq %r14, %r13
orq %rdi, %r14
notq %r14
orq %r14, %r12
shrq %rdi
movq %r12, %r14
andq %rdi, %r14
orq %r12, %rdi
notq %rdi
orq %r13, %rdi
incq %r9
movq %r14, %r12
movq %rdi, %r14
jmp 0x57a67
movzbl (%rdx,%r8), %eax
movzbl (%rbp,%rax), %eax
movq -0x38(%rsp,%rax,8), %rax
orq %r12, %rax
movq %rax, %rdx
andq %r14, %rdx
addq %r14, %rdx
xorq %r14, %rdx
orq %rax, %rdx
testb $0x1, %dl
jne 0x57b43
cmpl %r15d, %ecx
jge 0x57c23
incl %ecx
movq %rdx, %rax
andq %r14, %rax
orq %rdx, %r14
notq %r14
orq %r14, %r12
shrq %rdx
movq %r12, %rdi
andq %rdx, %rdi
orq %r12, %rdx
notq %rdx
orq %rax, %rdx
movl -0x4c(%rsp), %eax
subl %eax, %ebx
movq -0x8(%rsp), %r14
movq -0x40(%rsp), %rsi
subl %r14d, %esi
addl %eax, %esi
movslq %esi, %rsi
xorl %r10d, %r10d
movq 0x38(%rsp), %r11
movq -0x10(%rsp), %r15
movl %ebx, %eax
addl %r10d, %eax
jns 0x57ba8
cmpq %rsi, %r10
jge 0x57ba8
btq %r10, %rdx
adcl $0x0, %ecx
btq %r10, %rdi
sbbl $0x0, %ecx
incq %r10
jmp 0x57b89
addq %r10, %rbx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
cmpl -0x48(%rsp), %ecx
jg 0x57bc7
movl %ecx, 0x2c(%r11)
movl %ebx, 0x14(%r11)
movl %ecx, %r8d
subl %r10d, %ebx
movq %r15, %r9
decq %r9
subl -0x4c(%rsp), %r14d
cmpq %rsi, %r10
jge 0x57c0c
btq %r10, %rdx
adcl $0x0, %ecx
btq %r10, %rdi
sbbl $0x0, %ecx
cmpl %r15d, %ecx
jg 0x57c01
cmpl %r8d, %ecx
jg 0x57c01
movl %ecx, 0x2c(%r11)
leal (%r14,%r10), %r8d
movl %r8d, 0x14(%r11)
movl %ecx, %r8d
cmpq %r10, %r9
cmovel %ecx, %eax
incq %r10
jmp 0x57bd5
cmpl -0x48(%rsp), %eax
jg 0x57c23
cmpl %r8d, %eax
jne 0x57c23
addl -0x48(%rsp), %ebx
movq 0x38(%rsp), %rax
movl %ebx, 0x14(%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq