// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_extension_64_1_w_trace(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_extension_64_1_w_trace(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, bit_extz_t *ez)
{
	int32_t done = 1;//diff
	ez->cigar.n = 0; ez->nword = 1;//diff
	if(ez->err > thre) {//diff
		init_base_ed(*ez, thre, pn, tn); ez->ps = ez->ts = INT32_MAX; ez->pe = pn-1; ez->te = tn-1;
		if(pn > tn + thre) pn = tn + thre;
		else if(tn > pn + thre) tn = pn + thre;
		done = 0;//diff
	} else if(ez->err == 0) {//diff
        push_trace(&(ez->cigar), 0, ez->te+1-ez->ts); return;//diff
    } else {
        pn = ez->pe + 1 - ez->ps; tn = ez->te + 1 - ez->ts; //diff
    }

	int32_t i, err, tn0 = tn - 1, cut = thre+(thre<<1), bd, i_bd;
	int32_t poff, pe = pn-1, tmp_e = INT32_MAX, k, pidx = ez->pe, tidx = ez->te;
	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[pidx-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;

	ez->path.n=(ez->nword*tn*5);//diff
    kv_resize(w_sig, ez->path, ez->path.n); ez->path.n=0;//diff

	i = 0; mm = ((Word)1 << (thre<<1));
	// X = D0 = HN = HP = mm = 0;//for debug
	while (i < tn0) {
		// fprintf(stderr, "i::%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[tidx-i]);
		if (!(D0&(1ULL))) {
			++err; if (err>cut) return;
		}

		if(!done) {//diff
			poff = i-thre; k = i+thre-pe;/**poff:[i-thre, i+thre]**/
            if(k >= 0) {
                if(tmp_e == INT32_MAX) {
                    tmp_e = err;
                    for (k = 0; poff < pe; poff++, (k)++) {
                        tmp_e += ((VP>>k)&(1ULL)); tmp_e -= ((VN>>k)&(1ULL));
                    } 
                } else {
                    k = (thre<<1) - k; 
                    if(k >= 0) {
                        tmp_e += ((HP>>k)&(1ULL)); tmp_e -= ((HN>>k)&(1ULL)); 
                    }
                }
                if(tmp_e <= (*ez).thre && tmp_e < (*ez).err) {
					(*ez).err = tmp_e; (*ez).ps = pidx - pe; (*ez).ts = tidx-i;
                }
            }
        }
		// fprintf(stderr, "i::%d, tmp_e::%d, err::%d\n", i, tmp_e, err);

		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[pidx-i_bd]]; 
            if(c < 4) Peq[c] |= mm;
        }

		ez->path.a[ez->path.n++] = D0;//diff
        ez->path.a[ez->path.n++] = VP;//diff
        ez->path.a[ez->path.n++] = VN;//diff
        ez->path.a[ez->path.n++] = HP;//diff
        ez->path.a[ez->path.n++] = HN;//diff
	}
	ed_core_64(Peq, VP, VN, X, D0, HN, HP, (uint8_t)tstr[tidx-i]);
	if (!(D0&(1ULL))) {
		++err; if (err>cut) return;
	}
	ez->path.a[ez->path.n++] = D0;//diff
	ez->path.a[ez->path.n++] = VP;//diff
	ez->path.a[ez->path.n++] = VN;//diff
	ez->path.a[ez->path.n++] = HP;//diff
	ez->path.a[ez->path.n++] = HN;//diff

	int32_t site = tn - 1 - thre;/**up bound; site:[tn - 1 - thre, tn - 1 + thre]**/\
	if(!done) {//diff
		for (cut = pn - 1; site < cut; ) {
			err += VP&(1ULL); VP >>= 1; err -= VN&(1ULL); VN >>= 1; 
			site++;
			if(err <= thre && err < ez->err) {
				ez->err = err; ez->ps = pidx-site; ez->ts = tidx+1-tn;
			}
		}
		if(err <= thre && err < ez->err) {
			ez->err = err; ez->ps = pidx-site; ez->ts = tidx+1-tn;
		}
	}

	if((ez->te-ez->ts+1) != tn) {//diff
        ez->path.n /= tn; ez->path.n *= (ez->te+1-ez->ts);//diff
    }//diff

	poff = ez->ps; ez->ps = pidx - ez->pe; ez->pe = pidx - poff;//diff
	gen_trace(ez, thre, 0);//diff
	poff = ez->ps; ez->ps = pidx - ez->pe; ez->pe = pidx - poff;//diff
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %rbx
movl %r8d, %r12d
movl %ecx, %r9d
movq %rdx, 0x48(%rsp)
movq %rdi, 0x38(%rsp)
movq $0x0, 0xa8(%rbx)
movl $0x1, 0x30(%rbx)
movl 0x2c(%rbx), %ecx
cmpl %r8d, %ecx
jle 0x8d6e3
movl %r12d, 0x28(%rbx)
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, 0x2c(%rbx)
movl %esi, 0x18(%rbx)
movl %r9d, 0x24(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl %eax, 0x1c(%rbx)
movl %eax, 0x10(%rbx)
leal -0x1(%rsi), %eax
movl %eax, 0x14(%rbx)
leal -0x1(%r9), %eax
movl %eax, 0x20(%rbx)
leal (%r12,%r9), %eax
cmpl %esi, %eax
movl %ecx, 0x4(%rsp)
jge 0x8d704
movl %eax, %esi
jmp 0x8d70f
testl %ecx, %ecx
je 0x8dca8
movl %ecx, 0x4(%rsp)
movl 0x14(%rbx), %esi
movl 0x20(%rbx), %r9d
subl 0x10(%rbx), %esi
incl %esi
subl 0x1c(%rbx), %r9d
incl %r9d
jmp 0x8d70f
leal (%r12,%rsi), %eax
cmpl %r9d, %eax
cmovll %eax, %r9d
leal (%r12,%r12), %eax
movl %eax, (%rsp)
movslq 0x14(%rbx), %rax
movq %rax, 0x8(%rsp)
movslq 0x20(%rbx), %rax
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x70(%rsp)
leal 0x1(%r12), %eax
cmpl %esi, %eax
movq %rsi, 0x30(%rsp)
cmovgel %esi, %eax
movl $0x1, %r13d
movl %r12d, %ecx
shlq %cl, %r13
testl %eax, %eax
jle 0x8d795
movl %eax, %eax
movq 0x8(%rsp), %rcx
movq 0x38(%rsp), %rdx
addq %rdx, %rcx
negq %rax
xorl %edx, %edx
leaq 0x1a0298(%rip), %rsi    # 0x22da10
movq %r13, %rdi
movzbl (%rcx,%rdx), %r8d
movzbl (%rsi,%r8), %r8d
orq %rdi, 0x50(%rsp,%r8,8)
addq %rdi, %rdi
decq %rdx
cmpq %rdx, %rax
jne 0x8d77b
movl (%rsp), %eax
movl %eax, %ecx
orb $0x1, %cl
movq $-0x1, %r15
shlq %cl, %r15
movq $0x0, 0x70(%rsp)
movq %r13, %r14
negq %r14
leal (%r9,%r9,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
movq %r9, 0x28(%rsp)
jae 0x8d830
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0xc8(%rbx)
movq 0xd0(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x28(%rsp), %r9
movq %rax, 0xd0(%rbx)
leal -0x1(%r9), %esi
leal (%r12,%r12,2), %eax
movl %eax, 0x14(%rsp)
movq 0x30(%rsp), %rdx
leal -0x1(%rdx), %eax
decq %r13
movl $0x1, %edi
movl (%rsp), %ecx
shlq %cl, %rdi
movq %rdi, 0x90(%rsp)
xorq %r14, %r15
movq $0x0, 0xc0(%rbx)
xorl %r8d, %r8d
cmpl $0x2, %r9d
movl %eax, 0x10(%rsp)
movq %rsi, 0x78(%rsp)
jl 0x8dab5
movl %r12d, %ecx
subl %edx, %ecx
incl %ecx
movl %ecx, 0x24(%rsp)
movq 0x8(%rsp), %rcx
subl %eax, %ecx
movl %ecx, 0x20(%rsp)
movslq %r12d, %rdi
movslq %edx, %rcx
movq %rcx, 0xa0(%rsp)
cltq
movq %rax, 0x80(%rsp)
movl %esi, %eax
movq %rax, 0x98(%rsp)
movl %r12d, %r14d
negl %r14d
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorl %r8d, %r8d
leaq 0x1a0145(%rip), %rax    # 0x22da10
movq %rdi, 0x88(%rsp)
movq %rdi, %rsi
movq %r12, 0x40(%rsp)
movl %r12d, %edi
movq 0x18(%rsp), %r10
subq %r8, %r10
movq 0x48(%rsp), %rdx
movzbl (%rdx,%r10), %edx
movzbl (%rax,%rdx), %edx
movq 0x50(%rsp,%rdx,8), %rdx
orq %r13, %rdx
movq %rdx, %r12
andq %r15, %r12
addq %r15, %r12
xorq %r15, %r12
orq %rdx, %r12
testb $0x1, %r12b
jne 0x8d91d
cmpl 0x14(%rsp), %edi
jge 0x8dc96
incl %edi
movq %r12, %r9
andq %r15, %r9
orq %r12, %r15
notq %r15
movq %r13, %rbp
orq %r15, %rbp
movq %r12, %r15
shrq %r15
movq %rbp, %r13
andq %r15, %r13
orq %rbp, %r15
notq %r15
orq %r9, %r15
movl 0x4(%rsp), %edx
cmpl 0x40(%rsp), %edx
jle 0x8d9d4
movl 0x24(%rsp), %r11d
addl %r8d, %r11d
js 0x8d9d4
cmpl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
jne 0x8d99f
movq %r8, %rdx
subq 0x88(%rsp), %rdx
movl %edi, %ecx
cmpq 0x80(%rsp), %rdx
movl 0x10(%rsp), %eax
jge 0x8d9b5
xorl %r11d, %r11d
movl %edi, %ecx
btq %r11, %r15
adcl $0x0, %ecx
btq %r11, %r13
sbbl $0x0, %ecx
incq %r11
leal (%r11,%r14), %edx
cmpl %eax, %edx
jl 0x8d984
jmp 0x8d9b5
movl (%rsp), %edx
subl %r11d, %edx
js 0x8d9b5
btq %rdx, %r9
sbbl $0x0, %ecx
btq %rdx, %rbp
adcl $0x0, %ecx
cmpl 0x28(%rbx), %ecx
jg 0x8d9cd
cmpl 0x2c(%rbx), %ecx
jge 0x8d9cd
movl %ecx, 0x2c(%rbx)
movl 0x20(%rsp), %eax
movl %eax, 0x10(%rbx)
movl %r10d, 0x1c(%rbx)
leaq 0x1a003c(%rip), %rax    # 0x22da10
shrq 0x50(%rsp)
shrq 0x58(%rsp)
shrq 0x60(%rsp)
shrq 0x68(%rsp)
incq %rsi
cmpq 0xa0(%rsp), %rsi
jge 0x8da25
movq 0x8(%rsp), %rdx
subq %rsi, %rdx
movq 0x38(%rsp), %r10
movzbl (%r10,%rdx), %edx
movzbl (%rax,%rdx), %edx
cmpq $0x3, %rdx
ja 0x8da25
movq 0x90(%rsp), %rax
orq %rax, 0x50(%rsp,%rdx,8)
leaq 0x19ffeb(%rip), %rax    # 0x22da10
incq %r8
movq 0xc0(%rbx), %rdx
movq 0xd0(%rbx), %r10
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %r12, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %r15, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %r13, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %rbp, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %r9, (%r10,%rdx,8)
incq %r14
cmpq 0x98(%rsp), %r8
jne 0x8d8de
movq 0x40(%rsp), %r12
jmp 0x8dab8
movl %r12d, %edi
movq 0x18(%rsp), %rcx
subl %r8d, %ecx
movslq %ecx, %rcx
movq 0x48(%rsp), %rdx
movzbl (%rdx,%rcx), %ecx
leaq 0x19ff3d(%rip), %rdx    # 0x22da10
movzbl (%rdx,%rcx), %ecx
movq 0x50(%rsp,%rcx,8), %rcx
orq %r13, %rcx
movq %rcx, %r8
andq %r15, %r8
addq %r15, %r8
xorq %r15, %r8
orq %rcx, %r8
testb $0x1, %r8b
jne 0x8db00
cmpl 0x14(%rsp), %edi
jge 0x8dc96
incl %edi
movq %r8, %r9
andq %r15, %r9
orq %r8, %r15
notq %r15
orq %r15, %r13
movq %r8, %rcx
shrq %rcx
movq %r13, %rsi
andq %rcx, %rsi
orq %r13, %rcx
notq %rcx
orq %r9, %rcx
movq 0xc0(%rbx), %rdx
movq 0xd0(%rbx), %r10
leaq 0x1(%rdx), %r11
movq %r11, 0xc0(%rbx)
movq %r8, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r8
movq %r8, 0xc0(%rbx)
movq %rcx, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r8
movq %r8, 0xc0(%rbx)
movq %rsi, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r8
movq %r8, 0xc0(%rbx)
movq %r13, (%r10,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r8
movq %r8, 0xc0(%rbx)
movq %r9, (%r10,%rdx,8)
cmpl %r12d, 0x4(%rsp)
movq 0x28(%rsp), %r10
movq 0x78(%rsp), %rax
jle 0x8dc35
subl %r12d, %eax
cmpl 0x10(%rsp), %eax
jge 0x8dc11
movq 0x18(%rsp), %rdx
subl %r10d, %edx
incl %edx
movq 0x30(%rsp), %r11
negl %r11d
movq 0x8(%rsp), %r8
addl %r12d, %r8d
subl %r10d, %r8d
movl %ecx, %r9d
andl $0x1, %r9d
addl %r9d, %edi
movl %esi, %r9d
andl $0x1, %r9d
subl %r9d, %edi
cmpl %r12d, %edi
jg 0x8dbfc
cmpl 0x2c(%rbx), %edi
jge 0x8dbfc
movl %edi, 0x2c(%rbx)
movl %r8d, 0x10(%rbx)
movl %edx, 0x1c(%rbx)
shrq %rcx
shrq %rsi
incl %eax
leal (%r11,%rax), %r9d
decl %r8d
cmpl $-0x1, %r9d
jne 0x8dbd4
cmpl %r12d, %edi
jg 0x8dc35
cmpl 0x2c(%rbx), %edi
jge 0x8dc35
movl %edi, 0x2c(%rbx)
movq 0x8(%rsp), %rcx
subl %eax, %ecx
movl %ecx, 0x10(%rbx)
movq 0x18(%rsp), %rax
subl %r10d, %eax
incl %eax
movl %eax, 0x1c(%rbx)
movl 0x20(%rbx), %ecx
subl 0x1c(%rbx), %ecx
incl %ecx
cmpl %r10d, %ecx
je 0x8dc5f
movslq %r10d, %rsi
movq 0xc0(%rbx), %rax
xorl %edx, %edx
divq %rsi
movslq %ecx, %rcx
imulq %rax, %rcx
movq %rcx, 0xc0(%rbx)
movq 0x8(%rsp), %r14
movl %r14d, %eax
subl 0x14(%rbx), %eax
movl %r14d, %ecx
subl 0x10(%rbx), %ecx
movl %eax, 0x10(%rbx)
movl %ecx, 0x14(%rbx)
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x9c469
movl 0x14(%rbx), %eax
movl %r14d, %ecx
subl %eax, %ecx
subl 0x10(%rbx), %r14d
movl %ecx, 0x10(%rbx)
movl %r14d, 0x14(%rbx)
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x20(%rbx), %ebp
subl 0x1c(%rbx), %ebp
incl %ebp
cmpl $0x3fff, %ebp           # imm = 0x3FFF
jb 0x8dd23
movl $0x2, %r14d
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8dcf6
leaq (%rax,%rax), %rsi
testq %rax, %rax
cmoveq %r14, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw $0x3fff, (%rcx,%rax,2)  # imm = 0x3FFF
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
cmpl $0x3ffe, %ebp           # imm = 0x3FFE
ja 0x8dcbe
testl %ebp, %ebp
je 0x8dc96
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8dd68
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rax
movq 0xb8(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0xa8(%rbx)
movw %bp, (%rcx,%rax,2)
jmp 0x8dc96