// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/./Levenshtein_distance.h
// Function: ed_band_cal_global_64_w_trace(char*, int, char*, int, int, bit_extz_t*)
inline void ed_band_cal_global_64_w_trace(char *pstr, int32_t pn, char *tstr, int32_t tn, int32_t thre, bit_extz_t *ez)
{	
	ez->cigar.n = 0; ez->nword = 1;//diff
	if(ez->err > thre) {//diff
		init_base_ed(*ez, thre, pn, tn); ez->ps = ez->ts = 0;//diff
	} else if(ez->err == 0) {//diff
		push_trace(&(ez->cigar), 0, ez->te+1-ez->ts); return;//diff
	}
	if((pn > tn + thre) || (tn > pn + thre)) return;
	int32_t i, err, tn0 = tn - 1, cut = thre+(thre<<1), bd, i_bd; 
	w_sig 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 = (((w_sig)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 = (((w_sig)1)<<(thre))-1; VP = (((w_sig)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 = ((w_sig)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;
		}
		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[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**/\
	if(ez->err > thre) {//diff
		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;
		}
	}
	///should update ez->path.n for extension
	gen_trace(ez, thre, 1);//diff
    return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, %rbx
movl %ecx, %ebp
movq %rdx, 0x28(%rsp)
movl %esi, %r9d
movq %rdi, %r13
movq $0x0, 0xa8(%rbx)
movl $0x1, 0x30(%rbx)
movl 0x2c(%rbx), %eax
cmpl %r8d, %eax
jle 0x8cb23
movl %r8d, 0x28(%rbx)
movl $0x7fffffff, 0x2c(%rbx) # imm = 0x7FFFFFFF
movl %r9d, 0x18(%rbx)
movl %ebp, 0x24(%rbx)
xorl %eax, %eax
movl %eax, 0x1c(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movl %eax, 0x10(%rbx)
jmp 0x8cb2b
testl %eax, %eax
je 0x8cf14
leal (%r8,%rbp), %eax
cmpl %r9d, %eax
setl %al
leal (%r8,%r9), %r15d
subl %ebp, %r15d
setl %cl
orb %al, %cl
jne 0x8cfed
leal (%r8,%r8), %r10d
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
leal 0x1(%r8), %eax
cmpl %r9d, %eax
cmovgel %r9d, %eax
movl $0x1, %r12d
movl %r8d, %ecx
shlq %cl, %r12
testl %eax, %eax
jle 0x8cba4
movl %eax, %eax
xorl %ecx, %ecx
leaq 0x1a0e89(%rip), %rdx    # 0x22da10
movq %r12, %rsi
movzbl (%r13,%rcx), %edi
movzbl (%rdx,%rdi), %edi
orq %rsi, 0x30(%rsp,%rdi,8)
addq %rsi, %rsi
incq %rcx
cmpq %rcx, %rax
jne 0x8cb8a
movl %r10d, %ecx
orb $0x1, %cl
movq $-0x1, %r14
shlq %cl, %r14
movq $0x0, 0x50(%rsp)
movq %r12, %rcx
negq %rcx
leal (%rbp,%rbp,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
jae 0x8cc5b
decq %rax
movq %rcx, 0x8(%rsp)
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
movl %r10d, 0x4(%rsp)
callq 0x2370
movq 0x8(%rsp), %rcx
movl 0x4(%rsp), %r10d
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movq %rax, 0xd0(%rbx)
leal -0x1(%rbp), %edx
leal (%r8,%r8,2), %eax
movl %eax, 0x4(%rsp)
decq %r12
xorq %rcx, %r14
movq $0x0, 0xc0(%rbx)
movl $0x1, %eax
movl %r10d, %ecx
shlq %cl, %rax
movq %rax, 0x60(%rsp)
cmpl $0x2, %ebp
movl %edx, 0x14(%rsp)
jl 0x8cddc
movq %r8, %rax
movslq %eax, %r8
movslq %r9d, %r9
movl %edx, %r10d
leaq (%r8,%r13), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
incq %r8
xorl %edi, %edi
movq %r12, %rbp
movl %eax, %ecx
movq 0x28(%rsp), %rax
movzbl (%rax,%rdi), %eax
leaq 0x1a0d4a(%rip), %rdx    # 0x22da10
movzbl (%rdx,%rax), %eax
movq 0x30(%rsp,%rax,8), %rdx
orq %rbp, %rdx
movq %rdx, %rax
andq %r14, %rax
addq %r14, %rax
xorq %r14, %rax
orq %rdx, %rax
testb $0x1, %al
jne 0x8ccf1
cmpl 0x4(%rsp), %ecx
jge 0x8cfed
incl %ecx
shrq 0x30(%rsp)
shrq 0x38(%rsp)
shrq 0x40(%rsp)
shrq 0x48(%rsp)
leaq (%r8,%rdi), %rdx
cmpq %r9, %rdx
jge 0x8cd32
movq 0x8(%rsp), %rdx
movzbl (%rdx,%rdi), %edx
leaq 0x1a0cf2(%rip), %rsi    # 0x22da10
movzbl (%rsi,%rdx), %edx
cmpq $0x3, %rdx
ja 0x8cd32
movq 0x60(%rsp), %rsi
orq %rsi, 0x30(%rsp,%rdx,8)
movq %rax, %rdx
andq %r14, %rdx
orq %rax, %r14
notq %r14
orq %r14, %rbp
movq %rax, %r14
shrq %r14
movq %rbp, %r12
andq %r14, %r12
orq %rbp, %r14
notq %r14
orq %rdx, %r14
incq %rdi
movq 0xc0(%rbx), %rsi
movq 0xd0(%rbx), %r11
leaq 0x1(%rsi), %r13
movq %r13, 0xc0(%rbx)
movq %rax, (%r11,%rsi,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %rsi
movq %rsi, 0xc0(%rbx)
movq %r14, (%r11,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %rsi
movq %rsi, 0xc0(%rbx)
movq %r12, (%r11,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %rsi
movq %rsi, 0xc0(%rbx)
movq %rbp, (%r11,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %rsi
movq %rsi, 0xc0(%rbx)
movq %rdx, (%r11,%rax,8)
movq %r12, %rbp
cmpq %rdi, %r10
jne 0x8ccb6
jmp 0x8cde1
xorl %edi, %edi
movl %r8d, %ecx
movq 0x28(%rsp), %rax
movzbl (%rax,%rdi), %eax
leaq 0x1a0c1f(%rip), %rdx    # 0x22da10
movzbl (%rdx,%rax), %eax
movq 0x30(%rsp,%rax,8), %rdx
orq %r12, %rdx
movq %rdx, %rax
andq %r14, %rax
addq %r14, %rax
xorq %r14, %rax
orq %rdx, %rax
testb $0x1, %al
jne 0x8ce1c
cmpl 0x4(%rsp), %ecx
jge 0x8cfed
incl %ecx
movq %rax, %rdi
andq %r14, %rdi
orq %rax, %r14
notq %r14
orq %r14, %r12
movq %rax, %rdx
shrq %rdx
movq %r12, %r11
andq %rdx, %r11
orq %r12, %rdx
notq %rdx
orq %rdi, %rdx
movq 0xc0(%rbx), %r8
movq 0xd0(%rbx), %r9
leaq 0x1(%r8), %r10
movq %r10, 0xc0(%rbx)
movq %rax, (%r9,%r8,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r8
movq %r8, 0xc0(%rbx)
movq %rdx, (%r9,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r8
movq %r8, 0xc0(%rbx)
movq %r11, (%r9,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r8
movq %r8, 0xc0(%rbx)
movq %r12, (%r9,%rax,8)
movq 0xc0(%rbx), %rax
leaq 0x1(%rax), %r8
movq %r8, 0xc0(%rbx)
movq %rdi, (%r9,%rax,8)
movq 0x20(%rsp), %rsi
cmpl %esi, 0x2c(%rbx)
movq 0x18(%rsp), %rdi
movl 0x14(%rsp), %r8d
jle 0x8cf02
movl %r8d, %eax
subl %esi, %eax
decl %edi
cmpl %edi, %eax
jge 0x8cef0
movl %edx, %eax
andl $0x1, %eax
addl %eax, %ecx
shrq %rdx
movl %r11d, %eax
andl $0x1, %eax
subl %eax, %ecx
shrq %r11
decl %r15d
jne 0x8ced4
movl %edi, %eax
cmpl %edi, %eax
jne 0x8cf02
cmpl %esi, %ecx
jg 0x8cf02
movl %ecx, 0x2c(%rbx)
movl %edi, 0x14(%rbx)
movl %r8d, 0x20(%rbx)
movq %rbx, %rdi
movl $0x1, %edx
callq 0x9c469
jmp 0x8cfed
movl 0x20(%rbx), %ebp
subl 0x1c(%rbx), %ebp
incl %ebp
cmpl $0x3fff, %ebp           # imm = 0x3FFF
jb 0x8cf8f
movl $0x2, %r14d
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8cf62
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 0x8cf2a
testl %ebp, %ebp
je 0x8cfed
movq 0xb0(%rbx), %rax
cmpq %rax, 0xa8(%rbx)
jne 0x8cfd0
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)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq