// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_semi_infi_w_absent_diag(char*, int, char*, int, int, int, int*, bit_extz_t*)
inline void ed_band_cal_semi_infi_w_absent_diag(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, int32_t abs_diag, int32_t *nword, bit_extz_t *ez)
{
	init_base_ed(*ez, thre, pn, tn); ez->ps = ez->pe = -1; ez->ts = 0; ez->te = tn-1;
	int32_t bd, i, err = abs_diag, i_bd, cut = thre+(thre<<1), tn0 = tn - 1, wz, wz1, Peq_i; w_sig c, ad, Peq_m;
	if((pn > tn + cut) || (tn > pn + cut)) return;

	if(nword) {
        ez->nword = (*nword);
    } else {
        bd = (((thre)<<1)+1); ez->nword = ((bd>>bitw)+(!!(bd&bitz)));
    }
    resize_bit_extz_t((*ez), (thre)); 
	wz = sizeof(*(ez->a))*(ez->nword);
	memset((ez->Peq[0]).a, 0, wz);
	memset((ez->Peq[1]).a, 0, wz);
	memset((ez->Peq[2]).a, 0, wz);
	memset((ez->Peq[3]).a, 0, wz);
	memset((ez->Peq[4]).a, 0, wz);
	memset((ez->VP).a, 0, wz);
	w_infi_set_bit_lsub(ez->VN, abs_diag, ez->nword); /**VN = (((Word)1)<<(abs_diag))-1; ;**/ 

	bd = ((thre<<1)+1)-abs_diag; bd = ((bd<=pn)?bd:pn); i_bd = abs_diag; 
    ed_init_core(i, bd, i_bd, pstr, ez->Peq);
    i_bd = (thre<<1)-abs_diag;

	memset((ez->Peq[4]).a, 0, wz);
	i = 0; 
    /**for the incoming char/last char; mm = ((Word)1 << (thre<<1))**/
    Peq_i = (((thre<<1))>>bitw); Peq_m = (((w_sig)1)<<(((thre<<1))&bitz));
	while (i < tn0) {
        ed_infi_core(ez->Peq, ez->VP, ez->VN, ez->X, ez->D0, ez->HN, ez->HP, (uint8_t)tstr[i], c, ad, wz, ez->nword);
        if (!(ez->D0.a[0]&(1ULL))) {
            ++err; if (err>cut) return;
        }
        
        ed_infi_post_Peq(ez->Peq, wz, wz1, ez->nword);
        ++i; ++i_bd; c = 4;
        if(i_bd < pn) c = seq_nt4_table[(uint8_t)pstr[i_bd]];
        if(c < 4) ez->Peq[c].a[Peq_i]|=Peq_m;
    }
	ed_infi_core(ez->Peq, ez->VP, ez->VN, ez->X, ez->D0, ez->HN, ez->HP, (uint8_t)tstr[i], c, ad, wz, ez->nword);
    if (!(ez->D0.a[0]&(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++) {
		bd = (i>>bitw); i_bd = (i&bitz);
		err += (((*ez).VP.a[bd]>>i_bd)&((w_sig)1));
		err -= (((*ez).VN.a[bd]>>i_bd)&((w_sig)1));
	}
    if ((err <= thre) && (err <= ez->err)) {
        ez->err = err; ez->pe = site;
    }
	site -= i;
	while (i < ai) {
		bd = (i>>bitw); i_bd = (i&bitz);
		err += (((*ez).VP.a[bd]>>i_bd)&((w_sig)1));
		err -= (((*ez).VN.a[bd]>>i_bd)&((w_sig)1));
        ++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
subq $0x88, %rsp
movl %r9d, 0xc(%rsp)
movq %rdx, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movq 0xc8(%rsp), %r12
movl %r8d, 0x28(%r12)
movl $0x7fffffff, 0x2c(%r12) # imm = 0x7FFFFFFF
movl %esi, 0x18(%r12)
movl %ecx, 0x24(%r12)
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq $-0x1, 0x10(%r12)
movl $0x0, 0x1c(%r12)
leal -0x1(%rcx), %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x20(%r12)
movq %r8, 0x18(%rsp)
leal (%r8,%r8,2), %edx
leal (%rdx,%rcx), %eax
cmpl %esi, %eax
setl %al
movq %rsi, 0x10(%rsp)
movq %rdx, 0x40(%rsp)
addl %esi, %edx
movq %rcx, 0x28(%rsp)
cmpl %ecx, %edx
setl %cl
orb %al, %cl
jne 0x98a07
movq 0xc0(%rsp), %rax
movq 0x18(%rsp), %r14
leal (%r14,%r14), %r13d
testq %rax, %rax
je 0x98268
movl (%rax), %ecx
jmp 0x98270
movl %r13d, %ecx
sarl $0x6, %ecx
incl %ecx
movq 0x10(%rsp), %r15
movl %ecx, 0x30(%r12)
cmpl %r14d, 0x3c(%r12)
jge 0x98396
movl %r13d, %eax
shrl $0x6, %eax
leal (%rax,%rax,2), %eax
leal 0xc(,%rax,4), %eax
movl %eax, 0x3c(%r12)
cmpl 0x38(%r12), %eax
jbe 0x98391
movq 0x40(%r12), %rdi
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x40(%r12)
movl 0x30(%r12), %ecx
movl 0x3c(%r12), %esi
movl $0xaaaaaaab, %edx       # imm = 0xAAAAAAAB
imulq %rsi, %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
shrq $0x23, %rdx
movl %edx, 0x3c(%r12)
movq %rax, 0x48(%r12)
andl $-0x8, %esi
leaq (%rax,%rsi), %rdi
movq %rdi, 0x50(%r12)
leal (%rdx,%rdx), %edi
leaq (%rax,%rdi,8), %r8
movq %r8, 0x58(%r12)
leal (%rdx,%rdx,2), %r8d
leaq (%rax,%r8,8), %r8
movq %r8, 0x60(%r12)
leal (,%rdx,4), %r8d
leaq (%rax,%r8,8), %r9
movq %r9, 0x68(%r12)
leal (%rdx,%rdx,4), %r9d
leaq (%rax,%r9,8), %r10
movq %r10, 0x70(%r12)
leal (%rdi,%rdi,2), %r10d
leaq (%rax,%r10,8), %r10
movq %r10, 0x78(%r12)
leal (,%rdx,8), %r10d
subl %edx, %r10d
leaq (%rax,%r10,8), %r10
movq %r10, 0x80(%r12)
leaq (%rax,%rsi,8), %rsi
movq %rsi, 0x88(%r12)
leal (%rdx,%rdx,8), %esi
leaq (%rax,%rsi,8), %rsi
movq %rsi, 0x90(%r12)
leal (%rdi,%rdi,4), %esi
leaq (%rax,%rsi,8), %rsi
movq %rsi, 0x98(%r12)
leal (%rdx,%r9,2), %esi
leaq (%rax,%rsi,8), %rax
movq %rax, 0xa0(%r12)
leal (%r8,%r8,2), %eax
movl %eax, 0x38(%r12)
movl %edx, 0x34(%r12)
movl %r14d, 0x3c(%r12)
shll $0x3, %ecx
movq 0x48(%r12), %rdi
movslq %ecx, %rbp
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x50(%r12), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x58(%r12), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x60(%r12), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x68(%r12), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x78(%r12), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movq 0x80(%r12), %rdi
movslq 0x30(%r12), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x20e0
movl 0xc(%rsp), %edx
movl %edx, %eax
sarl $0x6, %eax
movslq %eax, %rbx
cmpl $0x40, %edx
jb 0x9843d
movq 0x80(%r12), %rdi
leaq (,%rbx,8), %rdx
movl $0xff, %esi
callq 0x20e0
movl 0xc(%rsp), %edx
movl %edx, %ecx
andl $0x3f, %ecx
je 0x9845d
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq 0x80(%r12), %rcx
movq %rax, (%rcx,%rbx,8)
movl %r13d, %eax
orl $0x1, %eax
subl %edx, %eax
cmpl %r15d, %eax
cmovgel %r15d, %eax
testl %eax, %eax
movq 0x48(%rsp), %r10
jle 0x984b1
movl %eax, %eax
movl 0xc(%rsp), %edx
xorl %esi, %esi
leaq 0x1a179c(%rip), %rdi    # 0x239c20
leal (%rdx,%rsi), %ecx
movl $0x1, %r8d
shlq %cl, %r8
movzbl (%r10,%rsi), %r9d
movzbl (%rdi,%r9), %r9d
movq 0x48(%r12,%r9,8), %r9
sarl $0x6, %ecx
movslq %ecx, %rcx
orq %r8, (%r9,%rcx,8)
incq %rsi
cmpq %rsi, %rax
jne 0x98484
movq 0x68(%r12), %rdi
movq $0x0, 0x30(%rsp)
xorl %esi, %esi
movq %rbp, %rdx
callq 0x20e0
movl %r13d, %ecx
andb $0x3e, %cl
movl $0x1, %eax
shlq %cl, %rax
movq %rax, 0x60(%rsp)
movl 0x30(%r12), %ecx
cmpl $0x2, 0x28(%rsp)
jl 0x9877f
movl %r13d, %eax
sarl $0x6, %eax
movl 0xc(%rsp), %edx
subl %edx, %r13d
movq 0x90(%r12), %rsi
leal -0x1(%rcx), %edi
movslq %edi, %r8
movq %r8, 0x78(%rsp)
cltq
movq %rax, 0x58(%rsp)
movslq %r13d, %r10
movslq %r15d, %rax
movq %rax, 0x70(%rsp)
movl 0x20(%rsp), %eax
movq %rax, 0x30(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x68(%rsp)
movq $0x0, 0x38(%rsp)
movl %edx, %eax
testl %ecx, %ecx
jle 0x98690
movq %r10, 0x80(%rsp)
movq 0x50(%rsp), %rdx
movq 0x38(%rsp), %r8
movzbl (%rdx,%r8), %edx
leaq 0x1a16bf(%rip), %r8     # 0x239c20
movzbl (%r8,%rdx), %edx
movq 0x48(%r12,%rdx,8), %rdx
movq 0x78(%r12), %rbp
movq 0x80(%r12), %r14
movq 0x88(%r12), %rbx
movq 0x98(%r12), %r11
movq 0xa0(%r12), %r13
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%r14,%r15,8), %r10
orq (%rdx,%r15,8), %r10
movq %r10, (%rbx,%r15,8)
andq (%rbp,%r15,8), %r10
addq %r12, %r10
setb %r12b
movq %r10, (%rsi,%r15,8)
addq (%rbp,%r15,8), %r10
movq %r10, (%rsi,%r15,8)
movq (%rbp,%r15,8), %r8
cmpq %r8, %r10
setb %r9b
xorq %r8, %r10
movq %r10, (%rsi,%r15,8)
orq (%rbx,%r15,8), %r10
orb %r12b, %r9b
movq %r10, (%rsi,%r15,8)
andq (%rbp,%r15,8), %r10
movq %r10, (%r11,%r15,8)
movq (%rsi,%r15,8), %r8
orq (%rbp,%r15,8), %r8
notq %r8
movq %r8, (%r13,%r15,8)
orq (%r14,%r15,8), %r8
movzbl %r9b, %r12d
movq %r8, (%r13,%r15,8)
incq %r15
cmpq %r15, %rcx
jne 0x98596
testl %ecx, %ecx
movq 0xc8(%rsp), %r12
movq 0x80(%rsp), %r10
jle 0x98690
movq 0x88(%r12), %rdx
movq 0xa0(%r12), %r11
movq 0x78(%r12), %rbx
movq 0x80(%r12), %r14
movq 0x98(%r12), %r15
movq 0x68(%rsp), %r13
xorl %ebp, %ebp
movq -0x10(%rsi,%r13,8), %r8
shrq %r8
orq %rbp, %r8
movq %r8, -0x10(%rdx,%r13,8)
movq -0x10(%rsi,%r13,8), %rbp
andq -0x10(%r11,%r13,8), %r8
movq %r8, -0x10(%r14,%r13,8)
movq -0x10(%r11,%r13,8), %r8
orq -0x10(%rdx,%r13,8), %r8
notq %r8
movq %r8, -0x10(%rbx,%r13,8)
orq -0x10(%r15,%r13,8), %r8
shlq $0x3f, %rbp
movq %r8, -0x10(%rbx,%r13,8)
decq %r13
cmpq $0x1, %r13
jg 0x98648
testb $0x1, (%rsi)
jne 0x986a1
cmpl 0x40(%rsp), %eax
jge 0x98a07
incl %eax
movq 0x48(%r12), %rdx
movq 0x50(%r12), %r11
movq 0x58(%r12), %rbx
movq 0x60(%r12), %r14
cmpl $0x2, %ecx
jl 0x9870d
xorl %r15d, %r15d
movq (%rdx,%r15,8), %r8
movq 0x8(%rdx,%r15,8), %r9
shldq $0x3f, %r8, %r9
movq %r9, (%rdx,%r15,8)
movq (%r11,%r15,8), %r8
movq 0x8(%r11,%r15,8), %r9
shldq $0x3f, %r8, %r9
movq %r9, (%r11,%r15,8)
movq (%rbx,%r15,8), %r8
movq 0x8(%rbx,%r15,8), %r9
shldq $0x3f, %r8, %r9
movq %r9, (%rbx,%r15,8)
movq (%r14,%r15,8), %r8
movq 0x8(%r14,%r15,8), %r9
shldq $0x3f, %r8, %r9
movq %r9, (%r14,%r15,8)
incq %r15
cmpq %r15, %rdi
jne 0x986bd
movq 0x78(%rsp), %r8
shrq (%rdx,%r8,8)
shrq (%r11,%r8,8)
shrq (%rbx,%r8,8)
shrq (%r14,%r8,8)
incq %r10
cmpq 0x70(%rsp), %r10
jge 0x9875b
movq 0x48(%rsp), %rdx
movzbl (%rdx,%r10), %edx
leaq 0x1a14e3(%rip), %r8     # 0x239c20
movzbl (%r8,%rdx), %edx
cmpq $0x3, %rdx
ja 0x9875b
movq 0x48(%r12,%rdx,8), %rdx
movq 0x60(%rsp), %r8
movq 0x58(%rsp), %r9
orq %r8, (%rdx,%r9,8)
movq 0x38(%rsp), %r8
incq %r8
movq %r8, 0x38(%rsp)
cmpq 0x30(%rsp), %r8
jne 0x9853b
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r15
jmp 0x98783
movl 0xc(%rsp), %eax
testl %ecx, %ecx
jle 0x988d7
movq 0x50(%rsp), %rdx
movq 0x30(%rsp), %rsi
movzbl (%rdx,%rsi), %edx
leaq 0x1a1480(%rip), %rsi    # 0x239c20
movzbl (%rsi,%rdx), %edx
movq 0x48(%r12,%rdx,8), %rdx
movq 0x78(%r12), %rsi
movq 0x80(%r12), %rdi
movq 0x88(%r12), %r8
movq 0x90(%r12), %r9
movq 0x98(%r12), %r10
movq %r12, %r13
movq 0xa0(%r12), %r11
xorl %ebx, %ebx
xorl %r14d, %r14d
movq (%rdi,%rbx,8), %r15
orq (%rdx,%rbx,8), %r15
movq %r15, (%r8,%rbx,8)
andq (%rsi,%rbx,8), %r15
addq %r14, %r15
setb %bpl
movq %r15, (%r9,%rbx,8)
addq (%rsi,%rbx,8), %r15
movq %r15, (%r9,%rbx,8)
movq (%rsi,%rbx,8), %r14
cmpq %r14, %r15
setb %r12b
xorq %r14, %r15
movq %r15, (%r9,%rbx,8)
orq (%r8,%rbx,8), %r15
orb %bpl, %r12b
movq %r15, (%r9,%rbx,8)
andq (%rsi,%rbx,8), %r15
movq %r15, (%r10,%rbx,8)
movq (%r9,%rbx,8), %r15
orq (%rsi,%rbx,8), %r15
notq %r15
movq %r15, (%r11,%rbx,8)
orq (%rdi,%rbx,8), %r15
movzbl %r12b, %r14d
movq %r15, (%r11,%rbx,8)
incq %rbx
cmpq %rbx, %rcx
jne 0x987de
testl %ecx, %ecx
movq 0x18(%rsp), %r14
movq %r13, %r12
movq 0x10(%rsp), %r15
jle 0x988d7
movq 0x90(%r12), %rdx
movq 0x88(%r12), %rsi
movq 0xa0(%r12), %rdi
movq 0x78(%r12), %r8
movq 0x80(%r12), %r9
movq 0x98(%r12), %r10
incq %rcx
xorl %r11d, %r11d
movq -0x10(%rdx,%rcx,8), %rbx
shrq %rbx
orq %r11, %rbx
movq %rbx, -0x10(%rsi,%rcx,8)
movq -0x10(%rdx,%rcx,8), %r11
andq -0x10(%rdi,%rcx,8), %rbx
movq %rbx, -0x10(%r9,%rcx,8)
movq -0x10(%rdi,%rcx,8), %rbx
orq -0x10(%rsi,%rcx,8), %rbx
notq %rbx
movq %rbx, -0x10(%r8,%rcx,8)
orq -0x10(%r10,%rcx,8), %rbx
shlq $0x3f, %r11
movq %rbx, -0x10(%r8,%rcx,8)
decq %rcx
cmpq $0x1, %rcx
ja 0x9888d
jmp 0x988df
movq 0x90(%r12), %rdx
testb $0x1, (%rdx)
jne 0x988fa
cmpl 0x40(%rsp), %eax
jge 0x98a07
incl %eax
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %r15
movq 0x20(%rsp), %r9
movl 0xc(%rsp), %edi
movq 0x28(%rsp), %r8
subl %r8d, %r15d
addl %edi, %r15d
subl %edi, %r9d
sets %cl
testl %r15d, %r15d
setg %dl
andb %cl, %dl
xorl %ecx, %ecx
cmpb $0x1, %dl
jne 0x9896b
movq 0x78(%r12), %rdx
movq 0x80(%r12), %rsi
subl %r8d, %edi
incl %edi
xorl %ecx, %ecx
movl %edi, %r9d
movl %ecx, %edi
shrl $0x6, %edi
movq (%rdx,%rdi,8), %r8
btq %rcx, %r8
adcl $0x0, %eax
movq (%rsi,%rdi,8), %rdi
btq %rcx, %rdi
sbbl $0x0, %eax
movl %r9d, %edi
incl %ecx
leal -0x1(%rdi), %r9d
cmpl $0x1, %edi
je 0x98968
cmpl %r15d, %ecx
jl 0x9893a
negl %r9d
cmpl %r14d, %eax
jg 0x98981
cmpl 0x2c(%r12), %eax
jg 0x98981
movl %eax, 0x2c(%r12)
movl %r9d, 0x14(%r12)
movq %r9, %r13
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpl %r15d, %ecx
jge 0x989ee
movq 0x78(%r12), %rsi
movq 0x80(%r12), %rdi
leal -0x1(%r14), %r8d
leal 0x1(%r13), %r9d
movl %ecx, %r10d
movl %r10d, %r11d
shrl $0x6, %r11d
movq (%rsi,%r11,8), %rbx
btq %r10, %rbx
adcl $0x0, %eax
movq (%rdi,%r11,8), %r11
btq %r10, %r11
sbbl $0x0, %eax
cmpl %r14d, %eax
jg 0x989d9
cmpl 0x2c(%r12), %eax
jg 0x989d9
movl %eax, 0x2c(%r12)
movl %r9d, 0x14(%r12)
cmpl %r10d, %r8d
cmovel %eax, %edx
leal 0x1(%r10), %r11d
incl %r9d
movl %r11d, %r10d
cmpl %r15d, %r11d
jl 0x989a6
cmpl %r14d, %edx
jg 0x98a07
cmpl 0x2c(%r12), %edx
jne 0x98a07
subl %ecx, %r13d
addl 0x18(%rsp), %r13d
movl %r13d, 0x14(%r12)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq