// File: /workspace/github_cpp_makefile_star2_O3/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)
movq %rdi, %r13
movq $0x0, 0xa8(%r9)
movl $0x1, 0x30(%r9)
movl 0x2c(%r9), %eax
cmpl %r8d, %eax
jle 0x8bd79
movl %r8d, 0x28(%rbx)
movl $0x7fffffff, 0x2c(%rbx) # imm = 0x7FFFFFFF
movl %esi, 0x18(%rbx)
movl %ebp, 0x24(%rbx)
xorl %eax, %eax
movl %eax, 0x1c(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, (%rbx)
movl %eax, 0x10(%rbx)
jmp 0x8bd81
testl %eax, %eax
je 0x8c179
leal (%r8,%rbp), %eax
cmpl %esi, %eax
setl %al
leal (%r8,%rsi), %edx
subl %ebp, %edx
setl %cl
orb %al, %cl
jne 0x8c24b
movl %edx, 0x1c(%rsp)
leal (%r8,%r8), %r14d
pxor %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rsp)
leal 0x1(%r8), %eax
cmpl %esi, %eax
movq %rsi, 0x20(%rsp)
cmovgel %esi, %eax
movl $0x1, %r15d
movl %r8d, %ecx
shlq %cl, %r15
testl %eax, %eax
jle 0x8be02
movl %eax, %eax
xorl %ecx, %ecx
leaq 0x1ade3b(%rip), %rdx    # 0x239c20
movq %r15, %rsi
movzbl (%r13,%rcx), %edi
movzbl (%rdx,%rdi), %edi
orq %rsi, 0x30(%rsp,%rdi,8)
addq %rsi, %rsi
incq %rcx
cmpq %rcx, %rax
jne 0x8bde8
movl %r14d, %ecx
orb $0x1, %cl
movq $-0x1, %r12
shlq %cl, %r12
movq $0x0, 0x50(%rsp)
movq %r15, %rdx
negq %rdx
leal (%rbp,%rbp,4), %eax
cltq
movq %rax, 0xc0(%rbx)
cmpq %rax, 0xc8(%rbx)
jae 0x8bea5
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 %r8, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %r8
movq %rax, 0xd0(%rbx)
leal -0x1(%rbp), %eax
leal (%r8,%r8,2), %ecx
movl %ecx, 0x8(%rsp)
decq %r15
xorq %rdx, %r12
movq $0x0, 0xc0(%rbx)
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
movq %rdx, 0x58(%rsp)
cmpl $0x2, %ebp
movl %eax, 0x4(%rsp)
jl 0x8c03b
movslq %r8d, %r9
movslq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movl %eax, %esi
leaq (%r9,%r13), %rax
incq %rax
movq %rax, 0x60(%rsp)
incq %r9
movq %r8, %rax
xorl %r11d, %r11d
leaq 0x1add17(%rip), %r13    # 0x239c20
movl %eax, %ecx
movq 0x28(%rsp), %rax
movzbl (%rax,%r11), %eax
movzbl (%r13,%rax), %eax
movq 0x30(%rsp,%rax,8), %rax
orq %r15, %rax
movq %rax, %rbp
andq %r12, %rbp
addq %r12, %rbp
xorq %r12, %rbp
orq %rax, %rbp
testb $0x1, %bpl
jne 0x8bf44
cmpl 0x8(%rsp), %ecx
jge 0x8c24b
incl %ecx
movdqa 0x30(%rsp), %xmm0
movdqa 0x40(%rsp), %xmm1
psrlq $0x1, %xmm0
movdqa %xmm0, 0x30(%rsp)
psrlq $0x1, %xmm1
movdqa %xmm1, 0x40(%rsp)
leaq (%r9,%r11), %rax
cmpq 0x10(%rsp), %rax
jge 0x8bf91
movq 0x60(%rsp), %rax
movzbl (%rax,%r11), %eax
movzbl (%r13,%rax), %eax
cmpq $0x3, %rax
ja 0x8bf91
movq 0x58(%rsp), %rdx
orq %rdx, 0x30(%rsp,%rax,8)
movq %rbp, %rax
andq %r12, %rax
orq %rbp, %r12
notq %r12
movq %r15, %r14
orq %r12, %r14
movq %rbp, %r12
shrq %r12
movq %r14, %r15
andq %r12, %r15
orq %r14, %r12
notq %r12
orq %rax, %r12
incq %r11
movq 0xc0(%rbx), %rdx
movq 0xd0(%rbx), %rdi
leaq 0x1(%rdx), %r10
movq %r10, 0xc0(%rbx)
movq %rbp, (%rdi,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r10
movq %r10, 0xc0(%rbx)
movq %r12, (%rdi,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r10
movq %r10, 0xc0(%rbx)
movq %r15, (%rdi,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r10
movq %r10, 0xc0(%rbx)
movq %r14, (%rdi,%rdx,8)
movq 0xc0(%rbx), %rdx
leaq 0x1(%rdx), %r10
movq %r10, 0xc0(%rbx)
movq %rax, (%rdi,%rdx,8)
cmpq %r11, %rsi
jne 0x8bf0b
jmp 0x8c040
xorl %esi, %esi
movl %r8d, %ecx
movq 0x28(%rsp), %rax
movzbl (%rax,%rsi), %eax
leaq 0x1adbd0(%rip), %rdx    # 0x239c20
movzbl (%rdx,%rax), %eax
movq 0x30(%rsp,%rax,8), %rax
orq %r15, %rax
movq %rax, %rdi
andq %r12, %rdi
addq %r12, %rdi
xorq %r12, %rdi
orq %rax, %rdi
testb $0x1, %dil
jne 0x8c07d
cmpl 0x8(%rsp), %ecx
jge 0x8c24b
incl %ecx
movq %rdi, %rax
andq %r12, %rax
orq %rdi, %r12
notq %r12
orq %r12, %r15
movq %rdi, %rdx
shrq %rdx
movq %r15, %rsi
andq %rdx, %rsi
orq %r15, %rdx
notq %rdx
orq %rax, %rdx
movq 0xc0(%rbx), %r11
movq 0xd0(%rbx), %r9
leaq 0x1(%r11), %r10
movq %r10, 0xc0(%rbx)
movq %rdi, (%r9,%r11,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r10
movq %r10, 0xc0(%rbx)
movq %rdx, (%r9,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r10
movq %r10, 0xc0(%rbx)
movq %rsi, (%r9,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r10
movq %r10, 0xc0(%rbx)
movq %r15, (%r9,%rdi,8)
movq 0xc0(%rbx), %rdi
leaq 0x1(%rdi), %r10
movq %r10, 0xc0(%rbx)
movq %rax, (%r9,%rdi,8)
cmpl %r8d, 0x2c(%rbx)
movq 0x20(%rsp), %rdi
jle 0x8c164
movl 0x4(%rsp), %eax
subl %r8d, %eax
decl %edi
cmpl %edi, %eax
jge 0x8c14e
movl 0x1c(%rsp), %r9d
movl %edx, %eax
andl $0x1, %eax
addl %eax, %ecx
shrq %rdx
movl %esi, %eax
andl $0x1, %eax
subl %eax, %ecx
shrq %rsi
decl %r9d
jne 0x8c133
movl %edi, %eax
cmpl %edi, %eax
jne 0x8c164
cmpl %r8d, %ecx
jg 0x8c164
movl %ecx, 0x2c(%rbx)
movl %edi, 0x14(%rbx)
movl 0x4(%rsp), %eax
movl %eax, 0x20(%rbx)
movq %rbx, %rdi
movl %r8d, %esi
movl $0x1, %edx
callq 0x9cb86
jmp 0x8c24b
movl 0x20(%rbx), %ebp
subl 0x1c(%rbx), %ebp
incl %ebp
cmpl $0x3fff, %ebp           # imm = 0x3FFF
jb 0x8c1f0
movq 0xb8(%rbx), %rax
xorl %edx, %edx
movl $0x2, %r14d
cmpq 0xb0(%rbx), %rdx
jne 0x8c1cc
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
cmoveq %r14, %rsi
movq %rsi, 0xb0(%rbx)
addq %rsi, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0xa8(%rbx)
movw $0x3fff, (%rax,%rdx,2)  # imm = 0x3FFF
addl $0xffffc001, %ebp       # imm = 0xFFFFC001
movq %rcx, %rdx
cmpl $0x3ffe, %ebp           # imm = 0x3FFE
ja 0x8c198
jmp 0x8c1f2
xorl %ecx, %ecx
testl %ebp, %ebp
je 0x8c24b
cmpq 0xb0(%rbx), %rcx
jne 0x8c235
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0xb0(%rbx)
movq 0xb8(%rbx), %rdi
addq %rsi, %rsi
callq 0x2370
movq %rax, 0xb8(%rbx)
movq 0xa8(%rbx), %rcx
jmp 0x8c23c
movq 0xb8(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, 0xa8(%rbx)
movw %bp, (%rax,%rcx,2)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq