// File: /workspace/github_cpp_makefile_star2_O3/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
movq %r8, -0x18(%rsp)
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r10
leaq -0x1(%rcx), %rax
movq %rax, -0x8(%rsp)
movq $-0x1, %rax
movq $-0x1, %r15
movq %rcx, -0x28(%rsp)
shlq %cl, %r15
xorq %rax, %r15
movq %rax, (%r8)
movq %rax, (%r10)
testq %rdx, %rdx
je 0x130332
movq $0x0, (%r9)
xorl %eax, %eax
testq %rsi, %rsi
je 0x130492
movq %r9, -0x10(%rsp)
movl $0x1, %edx
leaq 0x109b14(%rip), %rax    # 0x239c20
movq $0x0, -0x30(%rsp)
xorl %r10d, %r10d
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %r12d, %r12d
movq $0x0, -0x20(%rsp)
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpq %rdx, %rsi
jne 0x130140
movzbl (%rdi,%rbp), %ecx
movb (%rax,%rcx), %cl
jmp 0x130152
movzbl (%rdi,%rdx), %r9d
movzbl (%rdi,%rbp), %ecx
movb (%rax,%rcx), %cl
cmpb %cl, (%rax,%r9)
je 0x1301b6
cmpb $0x3, %cl
ja 0x1301a7
movzbl %cl, %ecx
movq %r8, %r9
movl %ecx, %r8d
addq %r11, %r11
shrl %ecx
orq %rcx, %r11
movq %r13, %rbx
movl $0x1, %r13d
subq %rcx, %r13
andl $0x1, %r8d
leaq (%r8,%r14,2), %r14
andq %r15, %r14
andq %r15, %r11
shrq %r9
xorq $0x1, %r8
movq -0x8(%rsp), %rcx
shlq %cl, %r8
shlq %cl, %r13
orq %r9, %r8
shrq %rbx
orq %rbx, %r13
cmpq %r13, %r11
jne 0x1301c7
movq %r11, %r13
jmp 0x1301b6
movq %rdx, %rbp
movq $0x0, -0x20(%rsp)
xorl %r12d, %r12d
incq %rdx
cmpq %rsi, %rdx
jbe 0x130132
jmp 0x130490
movl %edx, %r9d
subl %ebp, %r9d
leal 0x1(%r10), %ecx
movq -0x10(%rsp), %rax
movl %ecx, 0x4(%rax)
movq -0x30(%rsp), %rbx
addl %r10d, %ebx
andl $0x3f, %ebx
movl %r9d, 0x8(%rax,%rbx,4)
movslq %ecx, %r9
cmpq -0x28(%rsp), %r9
jle 0x130225
testl %ecx, %ecx
je 0x130234
movq -0x30(%rsp), %rax
movslq %eax, %rcx
leal 0x1(%rax), %r9d
movq -0x10(%rsp), %rax
movl %r9d, (%rax)
movslq 0x8(%rax,%rcx,4), %rcx
andl $0x3f, %r9d
movl %r9d, (%rax)
movl %r10d, 0x4(%rax)
movl %r9d, %eax
movq %rax, -0x30(%rsp)
jmp 0x13023e
subq %rbp, %r12
addq %rdx, %r12
leaq 0x1099ee(%rip), %rax    # 0x239c20
jmp 0x130254
movq $-0x1, %rcx
xorl %r10d, %r10d
leaq 0x1099db(%rip), %rax    # 0x239c20
movq %rdx, %r9
subq %rbp, %r9
addq %r9, %r12
subq %rcx, %r12
movl %r10d, %ecx
movq -0x20(%rsp), %rbp
incq %rbp
cmpq -0x28(%rsp), %rbp
movq %rbp, -0x20(%rsp)
jl 0x130327
cmpq $0xff, %r12
jg 0x130327
cmpq %r13, %r11
movq %r8, %r9
cmovbq %r14, %r9
movq %r9, %r10
notq %r10
movq %r13, %rbx
cmovbq %r11, %rbx
shlq $0x15, %r9
addq %r10, %r9
movq %r9, %r10
shrq $0x18, %r10
xorq %r9, %r10
imulq $0x109, %r10, %r9       # imm = 0x109
movq %r9, %r10
shrq $0xe, %r10
xorq %r9, %r10
leaq (%r10,%r10,4), %r9
leaq (%r10,%r9,4), %r9
movq %r9, %r10
shrq $0x1c, %r10
xorq %r9, %r10
movq %rbx, %r9
notq %r9
shlq $0x15, %rbx
addq %r9, %rbx
movq %rbx, %r9
shrq $0x18, %r9
xorq %rbx, %r9
imulq $0x109, %r9, %r9        # imm = 0x109
movq %r9, %rbx
shrq $0xe, %rbx
xorq %r9, %rbx
leaq (%rbx,%rbx,4), %r9
leaq (%rbx,%r9,4), %r9
movq %r9, %rbx
shrq $0x1c, %rbx
xorq %r9, %rbx
addq %r10, %rbx
movl $0x80000001, %eax       # imm = 0x80000001
imulq %rax, %rbx
cmpq -0x18(%rsp), %rbx
je 0x13049d
movl %ecx, %r10d
movq %rdx, %rbp
leaq 0x1098fe(%rip), %rax    # 0x239c20
jmp 0x1301b6
movl %ecx, %r10d
movq %rdx, %rbp
jmp 0x1301b6
testq %rsi, %rsi
je 0x130490
movl $0x80000001, %eax       # imm = 0x80000001
leaq 0x1098d9(%rip), %r8     # 0x239c20
xorl %r10d, %r10d
xorl %r13d, %r13d
xorl %r9d, %r9d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %edx, %edx
xorl %ebx, %ebx
movzbl (%rdi,%rdx), %ecx
movzbl (%r8,%rcx), %ecx
cmpq $0x3, %rcx
ja 0x1303bd
movq %r13, %r11
movl %ecx, %r13d
addq %r9, %r9
shrl %ecx
orq %rcx, %r9
movq %r10, %rbp
movl $0x1, %r10d
subq %rcx, %r10
andl $0x1, %r13d
leaq (,%rbx,2), %rbx
addq %r13, %rbx
andq %r15, %rbx
andq %r15, %r9
shrq %r11
xorq $0x1, %r13
movq -0x8(%rsp), %rcx
shlq %cl, %r13
shlq %cl, %r10
orq %r11, %r13
shrq %rbp
orq %rbp, %r10
cmpq %r10, %r9
jne 0x1303d0
movq %r9, %r10
jmp 0x1303c3
xorl %r14d, %r14d
xorl %r12d, %r12d
incq %rdx
cmpq %rdx, %rsi
jne 0x13035a
jmp 0x130490
incq %r14
movq -0x28(%rsp), %rcx
cmpq %rcx, %r12
leaq 0x1(%r12), %r12
cmovgeq %rcx, %r12
cmpq %rcx, %r14
jl 0x1303c3
cmpq %r10, %r9
movq %r13, %rcx
cmovbq %rbx, %rcx
movq %rcx, %r11
notq %r11
movq %r10, %rbp
cmovbq %r9, %rbp
shlq $0x15, %rcx
addq %r11, %rcx
movq %rcx, %r11
shrq $0x18, %r11
xorq %rcx, %r11
imulq $0x109, %r11, %rcx      # imm = 0x109
movq %rcx, %r11
shrq $0xe, %r11
xorq %rcx, %r11
leaq (%r11,%r11,4), %rcx
leaq (%r11,%rcx,4), %rcx
movq %rcx, %r11
shrq $0x1c, %r11
xorq %rcx, %r11
movq %rbp, %rcx
notq %rcx
shlq $0x15, %rbp
addq %rcx, %rbp
movq %rbp, %rcx
shrq $0x18, %rcx
xorq %rbp, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %rbp
shrq $0xe, %rbp
xorq %rcx, %rbp
leaq (,%rbp,4), %rcx
addq %rbp, %rcx
leaq (,%rcx,4), %rcx
addq %rbp, %rcx
movq %rcx, %rbp
shrq $0x1c, %rbp
xorq %rcx, %rbp
addq %r11, %rbp
imulq %rax, %rbp
cmpq -0x18(%rsp), %rbp
jne 0x1303c3
jmp 0x1304a0
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rdx
movq 0x38(%rsp), %rax
movq %rdx, (%rax)
movq 0x40(%rsp), %rax
movq %r12, (%rax)
movl $0x1, %eax
jmp 0x130492