// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq %rcx, %r13
movq %rdi, %r10
movq 0x70(%rsp), %rdi
testq %r9, %r9
sets %al
cmpq %rdi, %r9
setge %cl
orb %al, %cl
jne 0x12b42a
movq 0x78(%rsp), %rax
movq %rax, %rcx
xorq $0x1, %rcx
orq %r9, %rcx
je 0x12b42a
leaq -0x1(%rdi), %rcx
xorq %r9, %rcx
orq %rax, %rcx
jne 0x12b43b
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %rcx
subq %r13, %rcx
setl %bl
cmpq %r8, %r9
setge %r11b
orb %bl, %r11b
jne 0x12b459
movq (%rdx), %r11
movb (%r11,%rcx), %bl
jmp 0x12b45b
xorl %ebx, %ebx
movq 0x80(%rsp), %r11
testq %rax, %rax
movq %rsi, 0x28(%rsp)
movq %r10, 0x20(%rsp)
movq %r8, 0x8(%rsp)
movq %rdx, 0x18(%rsp)
je 0x12b4d7
testb %bl, %bl
je 0x12b522
movq %r9, %rax
subq %r13, %rax
movq %rsi, %r8
jle 0x12b52d
movq (%rdx), %rdx
movq %rax, %r14
sarq $0x3f, %r14
andq %rax, %r14
movq %rax, %rsi
movq %rsi, %rcx
testq %rsi, %rsi
jle 0x12b4bb
leaq -0x1(%rcx), %rsi
cmpb %bl, -0x1(%rdx,%rcx)
je 0x12b4a3
incq %rsi
movq %rsi, %r14
testq %rcx, %rcx
setg %cl
subq %r14, %rax
cmpq %r9, %rax
sete %dl
orb %cl, %dl
movq %r13, %r12
jne 0x12b42c
jmp 0x12b532
testb %bl, %bl
je 0x12b67f
leaq 0x1(%r9), %r14
cmpq %r8, %r14
jge 0x12b686
movq %r9, %r15
notq %r15
addq %r8, %r15
testq %r15, %r15
jle 0x12b7d8
movq (%rdx), %rcx
addq %r9, %rcx
subq %r13, %rcx
incq %rcx
xorl %eax, %eax
cmpb %bl, (%rcx,%rax)
jne 0x12b42c
incq %rax
cmpq %rax, %r15
jne 0x12b50c
jmp 0x12b7db
leaq 0x1(%r9), %r12
xorl %eax, %eax
movq %rsi, %r8
jmp 0x12b532
xorl %eax, %eax
movq %r9, %r12
movq %r12, %rcx
subq %r11, %rcx
xorl %r14d, %r14d
testq %rcx, %rcx
cmovgq %rcx, %r14
testq %r11, %r11
jle 0x12b42c
testq %r12, %r12
jle 0x12b42c
cmpq %rdi, %r12
jg 0x12b42c
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %rcx
movq %rcx, %r15
subq %r13, %r15
addq %r11, %r15
movq 0x18(%rsp), %rdx
cmpq %r15, 0x10(%rdx)
jge 0x12b5a7
movq (%rdx), %rdi
movq %r15, %rsi
movq %r9, %rbp
callq 0x2370
movq 0x20(%rsp), %r10
movq 0x28(%rsp), %r8
movq %rbp, %r9
movq 0x18(%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %rax, (%rdx)
movq %r15, 0x10(%rdx)
movq (%rdx), %rax
leaq (%rax,%rcx), %rdx
subq %r13, %rdx
movq %rdx, 0x8(%rsp)
notq %r13
addq %rcx, %r13
addq %rax, %r13
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r9, %r15
movq %r12, %rbp
movq %r14, %r12
subq %r14, %rbp
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
xorl %ecx, %ecx
movq %r10, %r9
callq 0x337f7
testb %bl, %bl
jne 0x12b5f9
movb -0x1(%r14,%rbp), %bl
decq %rbp
movq %rbp, %rcx
sarq $0x3f, %rcx
andq %rbp, %rcx
movq %rbp, %rdx
movq %r15, %r9
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r10
movq 0x70(%rsp), %rsi
movq 0x80(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rdx, %r11
testq %rdx, %rdx
jle 0x12b63e
leaq -0x1(%r11), %rdx
cmpb %bl, (%r13,%r11)
je 0x12b625
incq %rdx
movq %rdx, %rcx
subq %rcx, %rbp
addq %rbp, %rax
testq %r11, %r11
jg 0x12b42c
cmpq %r9, %rax
je 0x12b42c
movq %r12, %r14
subq %rdi, %r14
testq %r14, %r14
movl $0x0, %ecx
cmovleq %rcx, %r14
testq %r12, %r12
je 0x12b42c
cmpq %rsi, %r12
jle 0x12b5c4
jmp 0x12b42c
xorl %eax, %eax
movq %r9, %r14
jmp 0x12b688
xorl %eax, %eax
movq %rsi, %r8
leaq (%r14,%r11), %rbp
cmpq %rdi, %rbp
cmovgeq %rdi, %rbp
cmpq %rdi, %r14
setl %dl
cmpq %rbp, %r14
setl %cl
andb %dl, %cl
cmpb $0x1, %cl
jne 0x12b42c
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r15
subq %r13, %r15
addq %r11, %r15
movq 0x18(%rsp), %r12
cmpq %r15, 0x10(%r12)
jge 0x12b6f2
movq (%r12), %rdi
movq %r15, %rsi
movq %r9, 0x30(%rsp)
callq 0x2370
movq 0x20(%rsp), %r10
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
movq %rax, (%r12)
movq %r15, 0x10(%r12)
movq (%r12), %rdi
addq 0x8(%rsp), %rdi
subq %r13, %rdi
negq %r13
incq %r9
movq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movq %r9, %r12
movq %rbp, %r15
subq %r14, %r15
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
movq %r10, %r9
callq 0x337f7
movq 0x18(%rsp), %rax
movq (%rax), %rdi
addq 0x8(%rsp), %rdi
addq %r13, %rdi
testb %bl, %bl
jne 0x12b743
movb (%rdi), %bl
incq %rdi
decq %r15
testq %r15, %r15
setg %cl
movq %r12, %r9
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r10
movq 0x70(%rsp), %rdx
movq 0x80(%rsp), %rsi
jle 0x12b785
cmpb %bl, (%rdi)
jne 0x12b785
movl $0x1, %r11d
movq %r11, %rcx
cmpq %r11, %r15
je 0x12b78a
leaq 0x1(%rcx), %r11
cmpb %bl, (%rdi,%rcx)
je 0x12b76f
decq %r11
jmp 0x12b78d
xorl %r11d, %r11d
jmp 0x12b793
movq %r15, %r11
cmpq %r15, %rcx
setl %cl
movq 0x10(%rsp), %rax
addq %r11, %rax
testb %cl, %cl
jne 0x12b42c
leaq (%r9,%rax), %rcx
cmpq %rdx, %rcx
je 0x12b42c
leaq (%rsi,%rbp), %rcx
cmpq %rdx, %rcx
cmovgeq %rdx, %rcx
cmpq %rdx, %rbp
jge 0x12b42c
movq %rbp, %r14
cmpq %rcx, %rbp
movq %rcx, %rbp
jl 0x12b709
jmp 0x12b42c
xorl %r15d, %r15d
leaq (%r9,%r15), %rcx
incq %rcx
movq %r8, %r14
movq %r15, %rax
cmpq %rdi, %rcx
movq %rsi, %r8
je 0x12b42c
jmp 0x12b68b