// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jl 0x1aed60
movq -0x38(%rbp), %rax
cmpq 0x10(%rbp), %rax
jl 0x1aed6d
movq $0x0, -0x8(%rbp)
jmp 0x1af369
cmpq $0x0, -0x38(%rbp)
jne 0x1aed88
cmpq $0x1, 0x18(%rbp)
jne 0x1aed88
movq $0x0, -0x8(%rbp)
jmp 0x1af369
movq -0x38(%rbp), %rax
movq 0x10(%rbp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jne 0x1aedad
cmpq $0x0, 0x18(%rbp)
jne 0x1aedad
movq $0x0, -0x8(%rbp)
jmp 0x1af369
movq $0x0, -0x60(%rbp)
movb $0x0, -0x61(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x1aedea
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jge 0x1aedea
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq -0x38(%rbp), %rcx
subq -0x28(%rbp), %rcx
movb (%rax,%rcx), %al
movb %al, -0x61(%rbp)
cmpq $0x0, 0x18(%rbp)
je 0x1af095
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
je 0x1aeeba
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x1aeeb0
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x38(%rbp), %rax
subq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0x71(%rbp)
jl 0x1aee57
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x61(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x1aee60
jmp 0x1aee70
jmp 0x1aee62
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1aee33
movq -0x40(%rbp), %rax
subq -0x58(%rbp), %rax
subq $0x1, %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x1aee99
movq -0x38(%rbp), %rax
subq -0x60(%rbp), %rax
cmpq $0x0, %rax
jne 0x1aeea6
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x1aeeb8
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x1aeec6
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
subq 0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jge 0x1aeee1
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x50(%rbp)
jle 0x1aeefc
movq -0x50(%rbp), %rax
cmpq 0x10(%rbp), %rax
jg 0x1aeefc
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x1aef09
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
jmp 0x1aef0b
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
subq -0x28(%rbp), %rcx
addq 0x20(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1aef5e
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
subq -0x28(%rbp), %rsi
addq 0x20(%rbp), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
subq -0x28(%rbp), %rcx
addq 0x20(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1aef60
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
xorl %ecx, %ecx
subq -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
subq -0x48(%rbp), %rdx
movq -0x18(%rbp), %r8
movq -0x10(%rbp), %r9
xorl %ecx, %ecx
callq 0x9a30
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
jne 0x1aefc6
movq -0x70(%rbp), %rax
movq -0x40(%rbp), %rcx
movq %rcx, %rdx
addq $-0x1, %rdx
movq %rdx, -0x40(%rbp)
movb -0x1(%rax,%rcx), %al
movb %al, -0x61(%rbp)
movq -0x40(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x58(%rbp)
movb %al, -0x72(%rbp)
jl 0x1aeff6
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x61(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x72(%rbp)
movb -0x72(%rbp), %al
testb $0x1, %al
jne 0x1aefff
jmp 0x1af00f
jmp 0x1af001
movq -0x58(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1aefd2
movq -0x40(%rbp), %rax
subq -0x58(%rbp), %rax
subq $0x1, %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
jge 0x1af038
movq -0x38(%rbp), %rax
subq -0x60(%rbp), %rax
cmpq $0x0, %rax
jne 0x1af045
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
movq -0x48(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
subq 0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jge 0x1af068
movq $0x0, -0x48(%rbp)
cmpq $0x0, -0x50(%rbp)
jle 0x1af083
movq -0x50(%rbp), %rax
cmpq 0x10(%rbp), %rax
jg 0x1af083
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jg 0x1af090
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
jmp 0x1aef78
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
je 0x1af175
movq -0x38(%rbp), %rax
addq $0x1, %rax
cmpq -0x30(%rbp), %rax
jge 0x1af167
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq -0x38(%rbp), %rax
addq $0x1, %rax
xorl %ecx, %ecx
subq -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
subq -0x38(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x73(%rbp)
jge 0x1af10f
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x61(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x73(%rbp)
movb -0x73(%rbp), %al
testb $0x1, %al
jne 0x1af118
jmp 0x1af128
jmp 0x1af11a
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1af0e8
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x1af150
movq -0x38(%rbp), %rax
addq -0x60(%rbp), %rax
addq $0x1, %rax
cmpq 0x10(%rbp), %rax
jne 0x1af15d
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
movq -0x30(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1af173
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x1af17d
movq -0x38(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq 0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq 0x10(%rbp), %rax
jle 0x1af19b
movq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jl 0x1af1b6
movq -0x48(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x1af1b6
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0x1af1c3
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
jmp 0x1af1c5
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
subq -0x28(%rbp), %rcx
addq 0x20(%rbp), %rcx
cmpq %rcx, %rax
jge 0x1af218
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x30(%rbp), %rsi
subq -0x28(%rbp), %rsi
addq 0x20(%rbp), %rsi
shlq $0x0, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x30(%rbp), %rcx
subq -0x28(%rbp), %rcx
addq 0x20(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1af21a
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
xorl %ecx, %ecx
subq -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
subq -0x48(%rbp), %rdx
movq -0x18(%rbp), %r8
movq -0x10(%rbp), %r9
xorl %ecx, %ecx
callq 0x9a30
movq -0x50(%rbp), %rax
subq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq -0x30(%rbp), %rax
xorl %ecx, %ecx
subq -0x28(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
jne 0x1af29f
movq -0x70(%rbp), %rax
movb (%rax), %al
movb %al, -0x61(%rbp)
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x40(%rbp), %rcx
movb %al, -0x74(%rbp)
jge 0x1af2ce
movq -0x70(%rbp), %rax
movq -0x58(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x61(%rbp), %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x74(%rbp)
movb -0x74(%rbp), %al
testb $0x1, %al
jne 0x1af2d7
jmp 0x1af2e7
jmp 0x1af2d9
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x1af2a7
movq -0x58(%rbp), %rax
addq -0x60(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jl 0x1af30f
movq -0x38(%rbp), %rax
addq -0x60(%rbp), %rax
addq $0x1, %rax
cmpq 0x10(%rbp), %rax
jne 0x1af319
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
addq 0x20(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq 0x10(%rbp), %rax
jle 0x1af33f
movq 0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
jl 0x1af35a
movq -0x48(%rbp), %rax
cmpq 0x10(%rbp), %rax
jge 0x1af35a
movq -0x48(%rbp), %rax
cmpq -0x50(%rbp), %rax
jl 0x1af364
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1af369
jmp 0x1af232
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)