// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdx, 0x28(%rsp)
andq $0x0, 0xa8(%r9)
movq %rdi, %rbp
movl $0x1, 0x30(%r9)
movl 0x2c(%r9), %eax
cmpl %r8d, %eax
jle 0x582a8
movl %r8d, 0x28(%rbx)
movl $0x7fffffff, 0x2c(%rbx) # imm = 0x7FFFFFFF
movl %esi, 0x18(%rbx)
movl %ecx, 0x24(%rbx)
andl $0x0, 0x1c(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rbx)
andl $0x0, 0x10(%rbx)
jmp 0x582b0
testl %eax, %eax
je 0x58663
leal (%r8,%rcx), %eax
cmpl %esi, %eax
setl %al
leal (%r8,%rsi), %edx
cmpl %ecx, %edx
setl %dl
orb %al, %dl
jne 0x586a6
movq %rcx, %rdi
andq $0x0, 0x50(%rsp)
leal (%r8,%r8), %r13d
pxor %xmm0, %xmm0
leal 0x1(%r8), %eax
cmpl %esi, %eax
cmovgel %esi, %eax
pushq $0x1
popq %r12
movq %r12, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movl %r8d, %ecx
shlq %cl, %r12
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
leaq 0x1937ee(%rip), %r14    # 0x1ebb00
movq %r12, %rdx
cmpq %rcx, %rax
je 0x58332
movzbl (%rbp,%rcx), %r8d
movzbl (%r14,%r8), %r8d
orq %rdx, 0x30(%rsp,%r8,8)
addq %rdx, %rdx
incq %rcx
jmp 0x58315
movq %rsi, 0x8(%rsp)
andq $0x0, 0x50(%rsp)
movl %r13d, %ecx
orb $0x1, %cl
pushq $-0x1
popq %r15
shlq %cl, %r15
movq %r12, %rdx
negq %rdx
movq %rdi, %rcx
movl %ecx, %eax
decl %ecx
movq %rcx, 0x10(%rsp)
leal (%rax,%rax,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
jae 0x583d3
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
movq %rdx, (%rsp)
callq 0x2370
movq (%rsp), %rdx
movq %rax, 0xd0(%rbx)
movq 0x18(%rsp), %rax
leal (%rax,%rax,2), %ecx
movl %ecx, (%rsp)
andq $0x0, 0xc0(%rbx)
movl %r13d, %ecx
shlq %cl, 0x20(%rsp)
decq %r12
xorq %rdx, %r15
movslq %eax, %rcx
xorl %esi, %esi
movq 0x10(%rsp), %rdx
testl %edx, %edx
movl $0x0, %edi
cmovgl %edx, %edi
movslq 0x8(%rsp), %r8
leaq (%rcx,%rbp), %rdx
incq %rdx
movq %rdx, 0x60(%rsp)
incq %rcx
cmpq %rsi, %rdi
je 0x5854f
movq 0x28(%rsp), %rdx
movzbl (%rdx,%rsi), %r10d
movzbl (%r14,%r10), %r10d
movq 0x30(%rsp,%r10,8), %r11
orq %r12, %r11
movq %r11, %r10
andq %r15, %r10
addq %r15, %r10
xorq %r15, %r10
orq %r11, %r10
testb $0x1, %r10b
jne 0x5845c
cmpl (%rsp), %eax
jge 0x586a6
incl %eax
movdqa 0x30(%rsp), %xmm0
movdqa 0x40(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, 0x30(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, 0x40(%rsp)
leaq (%rcx,%rsi), %r11
cmpq %r8, %r11
jge 0x584a6
movq 0x60(%rsp), %rdx
movzbl (%rdx,%rsi), %r11d
movzbl (%r14,%r11), %r11d
cmpq $0x3, %r11
ja 0x584a6
movq 0x20(%rsp), %rdx
orq %rdx, 0x30(%rsp,%r11,8)
movq %r10, %r11
andq %r15, %r11
orq %r10, %r15
notq %r15
orq %r15, %r12
movq %r10, %r15
shrq %r15
movq %r12, %rbp
andq %r15, %rbp
orq %r12, %r15
notq %r15
orq %r11, %r15
movq 0xc0(%rbx), %rdx
movq 0xd0(%rbx), %r13
leaq 0x1(%rdx), %r9
movq %r9, 0xc0(%rbx)
movq %r10, (%r13,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r9
movq %r9, 0xc0(%rbx)
movq %r15, (%r13,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r9
movq %r9, 0xc0(%rbx)
movq %rbp, (%r13,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r9
movq %r9, 0xc0(%rbx)
movq %r12, (%r13,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r9
movq %r9, 0xc0(%rbx)
movq %r11, (%r13,%rdx,8)
incq %rsi
movq %rbp, %r12
jmp 0x5841c
movq 0x28(%rsp), %rcx
movzbl (%rcx,%rdi), %ecx
movzbl (%r14,%rcx), %ecx
movq 0x30(%rsp,%rcx,8), %rcx
orq %r12, %rcx
movq %rcx, %rsi
andq %r15, %rsi
addq %r15, %rsi
xorq %r15, %rsi
orq %rcx, %rsi
testb $0x1, %sil
jne 0x58585
cmpl (%rsp), %eax
jge 0x586a6
incl %eax
movq %rsi, %rdi
andq %r15, %rdi
orq %rsi, %r15
notq %r15
orq %r15, %r12
movq %rsi, %rcx
shrq %rcx
movq %r12, %rdx
andq %rcx, %rdx
orq %r12, %rcx
notq %rcx
orq %rdi, %rcx
movq 0xc0(%rbx), %r8
movq 0xd0(%rbx), %r9
leaq 0x1(%r8), %r10
movq %r10, 0xc0(%rbx)
movq %rsi, (%r9,%r8,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rcx, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rdx, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %r12, (%r9,%rsi,8)
movq 0xc0(%rbx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, 0xc0(%rbx)
movq %rdi, (%r9,%rsi,8)
movq 0x18(%rsp), %rsi
cmpl %esi, 0x2c(%rbx)
movq 0x10(%rsp), %r11
jle 0x5869b
movl %r11d, %edi
subl %esi, %edi
movq 0x8(%rsp), %r14
leal -0x1(%r14), %r10d
movl %edi, %r8d
cmpl %r10d, %r8d
jge 0x58687
movl %ecx, %r9d
andl $0x1, %r9d
addl %eax, %r9d
shrq %rcx
movl %edx, %eax
andl $0x1, %eax
subl %eax, %r9d
shrq %rdx
incl %r8d
movl %r9d, %eax
jmp 0x5863e
leaq 0xa8(%rbx), %rdi
movl 0x20(%rbx), %edx
subl 0x1c(%rbx), %edx
incl %edx
xorl %esi, %esi
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x62885
cmpl %r14d, %edi
jge 0x5869b
cmpl %esi, %eax
jg 0x5869b
movl %eax, 0x2c(%rbx)
movl %r10d, 0x14(%rbx)
movl %r11d, 0x20(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x65f7b
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq