// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/anchor.cpp
// Function: recalu_minimizer0(char*, unsigned long, unsigned long, long, unsigned long, tiny_queue_t*, unsigned long*, unsigned long*)
uint64_t recalu_minimizer0(char *s, uint64_t len, uint64_t is_hpc, int64_t mz_k, uint64_t mz_h, tiny_queue_t *tq, uint64_t *rpos, uint64_t *rspan)
{
	uint64_t k, l, shift1 = mz_k - 1, mask = (1ULL<<mz_k) - 1, kmer[4] = {0,0,0,0}, c, z, hs; int64_t mz_l, mz_span;
	(*rpos) = (*rspan) = (uint64_t)-1;
	if(is_hpc) {
		tq->front = tq->count = 0;
		for (k = 1, l = 0, mz_l = mz_span = 0; k <= len; ++k) {
        	if (k == len || seq_nt4_table[(uint8_t)s[k]] != seq_nt4_table[(uint8_t)s[l]]) {
				c = seq_nt4_table[(uint8_t)s[l]];
				if(c < 4) {
					kmer[0] = (kmer[0] << 1 | (c&1))  & mask;/**forward k-mer**/
					kmer[1] = (kmer[1] << 1 | (c>>1)) & mask;
					kmer[2] = kmer[2] >> 1 | (uint64_t)(1 - (c&1))  << shift1; /**reverse k-mer**/
					kmer[3] = kmer[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift1;
					if (kmer[1] == kmer[3]) continue; /** skip "symmetric k-mers" as we don't know it strand**/
					z = kmer[1] < kmer[3]? 0 : 1; /** strand**/
					mz_l++; mz_span += (k - l);
					tq_push(tq, k - l); if (tq->count > mz_k) mz_span -= tq_shift(tq);
					if(mz_l >= mz_k && mz_span < 256) {
						hs = yak_hash64_64(kmer[z<<1|0]) + yak_hash64_64(kmer[z<<1|1]);
						if(mz_h == hs) {
							(*rpos) = k - 1; (*rspan) = mz_span;
							return 1;
						}
					}
				} else {
					mz_l = mz_span = 0;
				}

				l = k;
			}
		}
	} else {
		for (k = 0, mz_l = mz_span = 0; k < len; ++k) {
			c = seq_nt4_table[(uint8_t)s[k]];
			if(c < 4) {
				kmer[0] = (kmer[0] << 1 | (c&1))  & mask;/**forward k-mer**/
				kmer[1] = (kmer[1] << 1 | (c>>1)) & mask;
				kmer[2] = kmer[2] >> 1 | (uint64_t)(1 - (c&1))  << shift1; /**reverse k-mer**/
				kmer[3] = kmer[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift1;
				if (kmer[1] == kmer[3]) continue; /** skip "symmetric k-mers" as we don't know it strand**/
				z = kmer[1] < kmer[3]? 0 : 1; /** strand**/
				mz_l++; mz_span++; if(mz_span > mz_k) mz_span = mz_k;
				if(mz_l >= mz_k) {
					hs = yak_hash64_64(kmer[z<<1|0]) + yak_hash64_64(kmer[z<<1|1]);
					if(mz_h == hs) {
						(*rpos) = k; (*rspan) = mz_span;
						return 1;
					}
				}
			} else {
				mz_l = mz_span = 0;
			}
		}
	}
	
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x48(%rsp)
movq %rdi, %rbx
movq 0x98(%rsp), %r8
movq 0x90(%rsp), %rdi
leaq -0x1(%rcx), %r10
pushq $-0x1
popq %rax
movq %rax, %r11
shlq %cl, %r11
xorq %rax, %r11
orq $-0x1, (%r8)
orq $-0x1, (%rdi)
testq %rdx, %rdx
movq %rcx, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rbx, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movq %r11, 0x20(%rsp)
je 0xea876
movq %r9, 0x18(%rsp)
andq $0x0, (%r9)
pushq $0x1
popq %rbp
leaq 0x10142f(%rip), %rdi    # 0x1ebb00
xorl %r15d, %r15d
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %eax, %eax
movq $0x0, 0x8(%rsp)
xorl %r9d, %r9d
cmpq %rsi, %rbp
ja 0xea980
jne 0xea6ff
movzbl (%rbx,%rax), %ecx
movb (%rdi,%rcx), %cl
jmp 0xea70f
movzbl (%rbx,%rbp), %edx
movzbl (%rbx,%rax), %ecx
movb (%rdi,%rcx), %cl
cmpb %cl, (%rdi,%rdx)
je 0xea76f
cmpb $0x3, %cl
ja 0xea760
movzbl %cl, %ecx
movq %r14, %rdx
movl %ecx, %r14d
addq %r13, %r13
shrl %ecx
orq %rcx, %r13
movq %r15, %r8
pushq $0x1
popq %r15
subq %rcx, %r15
andl $0x1, %r14d
leaq (%r14,%r12,2), %r12
andq %r11, %r12
andq %r11, %r13
shrq %rdx
xorq $0x1, %r14
movl %r10d, %ecx
shlq %cl, %r14
shlq %cl, %r15
orq %rdx, %r14
shrq %r8
orq %r8, %r15
cmpq %r15, %r13
jne 0xea777
movq %r13, %r15
jmp 0xea76f
movq %rbp, %rax
movq $0x0, 0x8(%rsp)
xorl %r9d, %r9d
incq %rbp
jmp 0xea6eb
movq %r12, 0x10(%rsp)
movq %r9, %r12
movl %ebp, %ecx
subl %eax, %ecx
movq 0x18(%rsp), %rdi
movslq 0x4(%rdi), %rdx
movq %rdx, %r8
incq %r8
movl %r8d, 0x4(%rdi)
movl (%rdi), %r9d
addl %edx, %r9d
andl $0x3f, %r9d
movl %ecx, 0x8(%rdi,%r9,4)
cmpq 0x40(%rsp), %r8
jle 0xea7d8
movq %rbp, %rcx
subq %rax, %rcx
addq %rcx, %r12
callq 0xea9b2
movq %r12, %r9
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %rsi
cltq
subq %rax, %r9
jmp 0xea7e1
movq %r12, %r9
subq %rax, %r9
addq %rbp, %r9
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, 0x8(%rsp)
cmpq 0x40(%rsp), %rcx
leaq 0x101306(%rip), %rdi    # 0x1ebb00
movq 0x10(%rsp), %r12
jl 0xea86e
cmpq $0xff, %r9
jg 0xea86e
movq %r12, %rax
movq %r9, %r12
cmpq %r15, %r13
movq %r14, %rdi
cmovbq %rax, %rdi
movq %r15, %rbx
cmovbq %r13, %rbx
callq 0xea9d4
movq %rax, 0x50(%rsp)
movq %rbx, %rdi
callq 0xea9d4
addq 0x50(%rsp), %rax
cmpq 0x48(%rsp), %rax
je 0xea991
movq %rbp, %rax
movq 0x38(%rsp), %rsi
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r10
movq 0x20(%rsp), %r11
movq %r12, %r9
leaq 0x10129c(%rip), %rdi    # 0x1ebb00
movq 0x10(%rsp), %r12
jmp 0xea76f
movq %rbp, %rax
jmp 0xea76f
leaq 0x101283(%rip), %rdi    # 0x1ebb00
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq $0x0, 0x8(%rsp)
xorl %r9d, %r9d
cmpq %rbp, %rsi
je 0xea980
movzbl (%rbx,%rbp), %eax
movzbl (%rdi,%rax), %eax
cmpq $0x3, %rax
ja 0xea8f7
movq %r14, %rdx
movl %eax, %r14d
addq %r15, %r15
shrl %eax
orq %rax, %r15
movq %r13, %r8
pushq $0x1
popq %r13
subq %rax, %r13
andl $0x1, %r14d
leaq (%r14,%r12,2), %r12
andq %r11, %r12
andq %r11, %r15
shrq %rdx
xorq $0x1, %r14
movl %r10d, %ecx
shlq %cl, %r14
shlq %cl, %r13
orq %rdx, %r14
shrq %r8
orq %r8, %r13
cmpq %r13, %r15
jne 0xea908
movq %r15, %r13
jmp 0xea903
movq $0x0, 0x8(%rsp)
xorl %r9d, %r9d
incq %rbp
jmp 0xea897
movq 0x8(%rsp), %rdx
incq %rdx
movq 0x40(%rsp), %rcx
cmpq %rcx, %r9
leaq 0x1(%r9), %r9
cmovgeq %rcx, %r9
movq %rdx, 0x8(%rsp)
cmpq %rcx, %rdx
jl 0xea903
cmpq %r13, %r15
movq %r14, %rdi
cmovbq %r12, %rdi
movq %r13, %rbx
cmovbq %r15, %rbx
movq %r9, 0x10(%rsp)
callq 0xea9d4
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
callq 0xea9d4
leaq 0x1011a7(%rip), %rdi    # 0x1ebb00
movq 0x10(%rsp), %r9
movq 0x20(%rsp), %r11
movq 0x28(%rsp), %r10
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %rsi
addq 0x18(%rsp), %rax
cmpq 0x48(%rsp), %rax
jne 0xea903
jmp 0xea997
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rbp
movq %r12, %r9
movq 0x90(%rsp), %rax
movq %rbp, (%rax)
movq 0x98(%rsp), %rax
movq %r9, (%rax)
pushq $0x1
popq %rax
jmp 0xea982