// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/anchor.cpp
// Function: hpc_minimizer_test(long, All_reads*, UC_Read*, long, long, long, long, long, long)
int64_t hpc_minimizer_test(int64_t id, All_reads *rref, UC_Read *bu, int64_t str_s, int64_t str_e, int64_t z, int64_t len, int64_t rev, int64_t step)
{
	if(z < 0 || z >= len) return 0;
	if(z == 0 && rev == 1) return 0;
	if(z == len - 1 && rev == 0) return 0;

	int64_t an, sc, ec, k, tn = 0; char c = 0, *a = NULL;
	if(z >= str_s && z < str_e) c = bu->seq[z-str_s];

	if(rev) {
		if(c != 0) {
			if(z > str_s) {
				a = bu->seq; an = z - str_s;
				for (k = an - 1; k >= 0 && a[k] == c; k--);
				tn += an - k - 1;
				if((k >= 0) || (z - tn == 0)) return tn;
				ec = str_s; 
			} else {
				ec = z; 
			}
		} else {
			ec = z + 1; 
		}

		sc = ec - step; if(sc < 0) sc = 0;
		if(ec <= 0 || ec > len || ec <= sc) return tn;

		UC_Read_resize((*bu), (str_e - str_s) + (step)); 
		a = bu->seq + str_e - str_s;

		while (1) {
			recover_UC_Read_sub_region(a, sc, ec - sc, 0, rref, id); an = ec - sc; 
			if(c == 0) c = a[--an];
			for (k = an - 1; k >= 0 && a[k] == c; k--);
			tn += an - k - 1;
			if((k >= 0) || (z - tn == 0)) return tn;
			ec = sc;
			sc = ec - step; if(sc < 0) sc = 0;
			if(ec <= 0 || ec > len || ec <= sc) return tn;
		}
	} else {
		if(c != 0) {
			if(z + 1 < str_e) {
				a = bu->seq + z + 1 - str_s; an = str_e - z - 1;
				for (k = 0; k < an && a[k] == c; k++);
				tn += k;
				if((k < an) || (z + tn + 1 == len)) return tn;
				sc = str_e; 
			} else {
				sc = z + 1; 
			}
		} else {
			sc = z; 
		}

		ec = sc + step; if(ec > len) ec = len;
		if(sc < 0 || sc >= len || sc >= ec) return tn;

		UC_Read_resize((*bu), (str_e - str_s) + (step)); 
		a = bu->seq + str_e - str_s;

		while (1) {
			// if(bu->size < (a - bu->seq) + (ec - sc)) {
			// 	fprintf(stderr, "-1-[M::%s]\tid::%ld\n", __func__, id);
			// }
			recover_UC_Read_sub_region(a, sc, ec - sc, 0, rref, id); an = ec - sc; 
			a = bu->seq + str_e - str_s;
			if(c == 0) {
				c = a[0]; a = a + 1; an--; 
			} 
			for (k = 0; k < an && a[k] == c; k++);
			tn += k;
			if((k < an) || (z + tn + 1 == len)) return tn;
			sc = ec;
			ec = sc + step; if(ec > len) ec = len;
			if(sc < 0 || sc >= len || sc >= ec) return tn;
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r15
movq %rcx, %r14
movq %rdi, %r9
movq 0x60(%rsp), %rdi
testq %r15, %r15
sets %al
cmpq %rdi, %r15
setge %cl
orb %al, %cl
jne 0x1314ec
movq 0x68(%rsp), %rcx
movq %rcx, %rax
xorq $0x1, %rax
orq %r15, %rax
je 0x1314ec
leaq -0x1(%rdi), %rax
xorq %r15, %rax
orq %rcx, %rax
jne 0x131500
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r13
movq %rsi, %r8
movq 0x70(%rsp), %r10
movq %r15, %r11
subq %r14, %r11
setl %al
cmpq %r13, %r15
setge %sil
orb %al, %sil
jne 0x13156e
movq (%rdx), %rax
movb (%rax,%r11), %bpl
testq %rcx, %rcx
je 0x1316c9
testb %bpl, %bpl
je 0x131577
cmpq %r14, %r15
jle 0x131836
movq %r11, %rcx
sarq $0x3f, %rcx
andq %r11, %rcx
movq $-0x1, %rbx
movq %r11, %r12
testq %r11, %r11
jle 0x131840
leaq -0x1(%r11), %rsi
incq %rbx
cmpb %bpl, -0x1(%rax,%r11)
movq %rsi, %r11
je 0x131552
jmp 0x1314ee
testq %rcx, %rcx
je 0x131708
leaq 0x1(%r15), %r11
xorl %ebp, %ebp
xorl %esi, %esi
movq %r11, %rax
subq %r10, %rax
xorl %r12d, %r12d
testq %rax, %rax
cmovgq %rax, %r12
testq %r10, %r10
jle 0x1316c1
testq %r11, %r11
jle 0x1316c1
cmpq %rdi, %r11
jg 0x1316c1
movq (%rdx), %rax
movq %r13, %rbx
subq %r14, %rbx
addq %r10, %rbx
cmpq %rbx, 0x10(%rdx)
movq %r8, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
jge 0x1315f9
movq %rax, %rdi
movq %rbx, %rsi
movq %r9, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %r11, (%rsp)
callq 0x2370
movq (%rsp), %r11
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %r8
movq 0x18(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, 0x10(%rcx)
leaq (%rax,%r13), %r10
subq %r14, %r10
notq %r14
addq %r13, %r14
addq %rax, %r14
movq %r11, %r13
subq %r12, %r13
movq %r10, %rdi
movq %r12, (%rsp)
movq %r12, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
movq %r9, %r12
movq %r10, %rbx
callq 0x32ef8
testb %bpl, %bpl
jne 0x131636
movb -0x1(%rbx,%r13), %bpl
decq %r13
movq 0x8(%rsp), %rcx
movq %rbx, %r10
movq %r13, %rax
sarq $0x3f, %rax
andq %r13, %rax
leaq -0x1(%rcx), %rbx
movq %r13, %rcx
movq 0x10(%rsp), %r8
movq %r12, %r9
movq 0x60(%rsp), %rsi
movq 0x70(%rsp), %rdi
movq (%rsp), %r11
testq %rcx, %rcx
jle 0x13167f
leaq -0x1(%rcx), %rdx
incq %rbx
cmpb %bpl, (%r14,%rcx)
movq %rdx, %rcx
je 0x131665
jmp 0x1314ee
subq %rax, %r13
movq 0x8(%rsp), %rbx
addq %r13, %rbx
cmpq %r15, %rbx
je 0x131852
movq %r11, %r12
subq %rdi, %r12
testq %r12, %r12
movl $0x0, %eax
cmovleq %rax, %r12
testq %r11, %r11
je 0x1314ee
movq %rbx, 0x8(%rsp)
cmpq %rsi, %r11
jle 0x131609
jmp 0x1314ee
movq %rsi, %rbx
jmp 0x1314ee
testb %bpl, %bpl
je 0x131708
leaq 0x1(%r15), %r11
cmpq %r13, %r11
jae 0x13170d
movq %r15, %rcx
notq %rcx
addq %r13, %rcx
jle 0x13185a
addq %r15, %rax
subq %r14, %rax
incq %rax
xorl %ebx, %ebx
cmpb %bpl, (%rax,%rbx)
jne 0x1314ee
incq %rbx
cmpq %rbx, %rcx
jne 0x1316f1
jmp 0x13185c
xorl %ebp, %ebp
movq %r15, %r11
xorl %ebx, %ebx
leaq (%r11,%r10), %rsi
cmpq %rdi, %rsi
cmovgeq %rdi, %rsi
cmpq %rdi, %r11
setl %al
cmpq %rsi, %r11
setl %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1314ee
movq (%rdx), %rdi
movq %r13, %r12
subq %r14, %r12
addq %r10, %r12
cmpq %r12, 0x10(%rdx)
movq %rdx, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %r9, 0x20(%rsp)
jge 0x131785
movq %rsi, (%rsp)
movq %r12, %rsi
movq %r11, 0x8(%rsp)
callq 0x2370
movq 0x8(%rsp), %r11
movq (%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %r9
movq 0x10(%rsp), %r8
movq %rax, %rdi
movq %rax, (%rcx)
movq %r12, 0x10(%rcx)
addq %r13, %rdi
subq %r14, %rdi
negq %r14
incq %r15
movq %rsi, (%rsp)
movq %rsi, %r12
subq %r11, %r12
movq %r11, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x32ef8
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq %r13, %rdi
addq %r14, %rdi
testb %bpl, %bpl
jne 0x1317c4
movb (%rdi), %bpl
incq %rdi
decq %r12
testq %r12, %r12
movq 0x10(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x60(%rsp), %rcx
movq 0x70(%rsp), %rdx
movq (%rsp), %rsi
jle 0x1317f3
xorl %eax, %eax
cmpb %bpl, (%rdi,%rax)
jne 0x13182e
incq %rax
cmpq %rax, %r12
jne 0x1317e3
jmp 0x1317f6
xorl %r12d, %r12d
addq %r12, %rbx
leaq (%r15,%rbx), %rax
cmpq %rcx, %rax
je 0x1314ee
leaq (%rsi,%rdx), %rax
cmpq %rcx, %rax
cmovgeq %rcx, %rax
cmpq %rcx, %rsi
jge 0x1314ee
movq %rsi, %r11
cmpq %rax, %rsi
movq %rax, %rsi
jl 0x131791
jmp 0x1314ee
addq %rax, %rbx
jmp 0x1314ee
xorl %esi, %esi
movq %r15, %r11
jmp 0x13157f
movq %r12, %rsi
subq %rcx, %rsi
movq %r14, %r11
cmpq %r15, %rsi
jne 0x13157f
movq %r15, %rbx
jmp 0x1314ee
xorl %ecx, %ecx
addq %rcx, %r11
movq %rcx, %rbx
cmpq %rdi, %r11
movq %r13, %r11
je 0x1314ee
jmp 0x13170f