// File: /workspace/github_cpp_makefile_star2_O1/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, -0x20(%rsp)
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r10
leaq -0x1(%rcx), %rax
movq %rax, -0x8(%rsp)
movq $-0x1, %rax
movq $-0x1, %r11
movq %rcx, -0x28(%rsp)
shlq %cl, %r11
xorq %rax, %r11
movq %r11, -0x10(%rsp)
movq %rax, (%r8)
movq %rax, (%r10)
testq %rdx, %rdx
movq %rdi, -0x38(%rsp)
je 0x12a25a
movq $0x0, (%r9)
testq %rsi, %rsi
je 0x12a3c8
movl $0x1, %edx
leaq 0x1039c4(%rip), %r15    # 0x22da10
xorl %ebx, %ebx
xorl %eax, %eax
xorl %r14d, %r14d
movq $0x0, -0x30(%rsp)
xorl %r13d, %r13d
xorl %r8d, %r8d
xorl %r12d, %r12d
cmpq %rdx, %rsi
je 0x12a081
movzbl (%rdi,%rdx), %ecx
movb (%r15,%rcx), %cl
movzbl (%rdi,%r8), %r11d
cmpb (%r15,%r11), %cl
je 0x12a249
movzbl (%rdi,%r8), %ecx
movzbl (%r15,%rcx), %ecx
cmpq $0x3, %rcx
ja 0x12a0e5
movq %rax, %r11
movl %ecx, %eax
addq %r14, %r14
shrl %ecx
orq %rcx, %r14
movq %rbx, %rbp
movl $0x1, %ebx
subq %rcx, %rbx
andl $0x1, %eax
leaq (%rax,%r12,2), %r12
movq -0x10(%rsp), %rcx
andq %rcx, %r12
andq %rcx, %r14
shrq %r11
xorq $0x1, %rax
movq -0x8(%rsp), %rcx
shlq %cl, %rax
shlq %cl, %rbx
orq %r11, %rax
shrq %rbp
orq %rbp, %rbx
cmpq %rbx, %r14
jne 0x12a0f9
movq -0x38(%rsp), %rdi
jmp 0x12a249
movq %rdx, %r8
xorl %r13d, %r13d
movq $0x0, -0x30(%rsp)
jmp 0x12a249
movq %r13, -0x18(%rsp)
movq %r15, %r13
movl %edx, %r10d
subl %r8d, %r10d
movslq 0x4(%r9), %rbp
movq %rbp, %rcx
incq %rcx
movl %ecx, 0x4(%r9)
movslq (%r9), %r11
leal (%r11,%rbp), %r15d
andl $0x3f, %r15d
movl %r10d, 0x8(%r9,%r15,4)
cmpq -0x28(%rsp), %rcx
jle 0x12a149
testl %ecx, %ecx
je 0x12a163
leal 0x1(%r11), %r10d
movl %r10d, (%r9)
movslq 0x8(%r9,%r11,4), %rcx
andl $0x3f, %r10d
movl %r10d, (%r9)
movl %ebp, 0x4(%r9)
jmp 0x12a16a
movq -0x30(%rsp), %rcx
subq %r8, %rcx
addq %rdx, %rcx
movq %rcx, -0x30(%rsp)
movq %r13, %r15
movq -0x38(%rsp), %rdi
jmp 0x12a188
movq $-0x1, %rcx
movq %r13, %r15
movq -0x38(%rsp), %rdi
movq %rdx, %r10
subq %r8, %r10
movq -0x30(%rsp), %r8
addq %r10, %r8
subq %rcx, %r8
movq %r8, -0x30(%rsp)
movq -0x18(%rsp), %r13
incq %r13
cmpq -0x28(%rsp), %r13
jl 0x12a246
cmpq $0xff, -0x30(%rsp)
jg 0x12a246
cmpq %rbx, %r14
movq %rax, %rcx
cmovbq %r12, %rcx
movq %rcx, %r8
notq %r8
movq %rbx, %r10
cmovbq %r14, %r10
shlq $0x15, %rcx
addq %r8, %rcx
movq %rcx, %r8
shrq $0x18, %r8
xorq %rcx, %r8
imulq $0x109, %r8, %rcx       # imm = 0x109
movq %rcx, %r8
shrq $0xe, %r8
xorq %rcx, %r8
leaq (%r8,%r8,4), %rcx
leaq (%r8,%rcx,4), %rcx
movq %rcx, %r8
shrq $0x1c, %r8
xorq %rcx, %r8
movq %r10, %rcx
notq %rcx
shlq $0x15, %r10
addq %rcx, %r10
movq %r10, %rcx
shrq $0x18, %rcx
xorq %r10, %rcx
imulq $0x109, %rcx, %rcx      # imm = 0x109
movq %rcx, %r10
shrq $0xe, %r10
xorq %rcx, %r10
leaq (%r10,%r10,4), %rcx
leaq (%r10,%rcx,4), %rcx
movq %rcx, %r10
shrq $0x1c, %r10
xorq %rcx, %r10
addq %r8, %r10
movl $0x80000001, %ecx       # imm = 0x80000001
imulq %rcx, %r10
cmpq -0x20(%rsp), %r10
je 0x12a3d5
movq %rdx, %r8
incq %rdx
cmpq %rsi, %rdx
jbe 0x12a065
jmp 0x12a3c8
testq %rsi, %rsi
je 0x12a3c8
movl $0x80000001, %eax       # imm = 0x80000001
leaq 0x1037a1(%rip), %r11    # 0x22da10
xorl %r10d, %r10d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r8d, %r8d
xorl %edx, %edx
xorl %r14d, %r14d
movzbl (%rdi,%rdx), %ecx
movzbl (%r11,%rcx), %ecx
cmpq $0x3, %rcx
ja 0x12a305
movq %r13, %r15
movl %ecx, %r13d
addq %rbx, %rbx
shrl %ecx
orq %rcx, %rbx
movq %r10, %rbp
movl $0x1, %r10d
subq %rcx, %r10
andl $0x1, %r13d
leaq (,%r14,2), %r14
addq %r13, %r14
movq -0x10(%rsp), %rcx
andq %rcx, %r14
andq %rcx, %rbx
shrq %r15
xorq $0x1, %r13
movq -0x8(%rsp), %rcx
shlq %cl, %r13
shlq %cl, %r10
orq %r15, %r13
shrq %rbp
orq %rbp, %r10
cmpq %r10, %rbx
je 0x12a2fe
incq %r8
movq -0x28(%rsp), %rcx
cmpq %rcx, %r12
leaq 0x1(%r12), %r12
cmovgeq %rcx, %r12
cmpq %rcx, %r8
jge 0x12a31c
movq -0x38(%rsp), %rdi
jmp 0x12a30b
xorl %r8d, %r8d
xorl %r12d, %r12d
incq %rdx
cmpq %rdx, %rsi
jne 0x12a282
jmp 0x12a3c8
cmpq %r10, %rbx
movq %r13, %rcx
cmovbq %r14, %rcx
movq %rcx, %r15
notq %r15
movq %r10, %rbp
cmovbq %rbx, %rbp
shlq $0x15, %rcx
addq %r15, %rcx
movq %rcx, %r15
shrq $0x18, %r15
xorq %rcx, %r15
imulq $0x109, %r15, %rcx      # imm = 0x109
movq %rcx, %r15
shrq $0xe, %r15
xorq %rcx, %r15
leaq (%r15,%r15,4), %rcx
leaq (%r15,%rcx,4), %rcx
movq %rcx, %r15
shrq $0x1c, %r15
xorq %rcx, %r15
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 %r15, %rbp
imulq %rax, %rbp
cmpq -0x20(%rsp), %rbp
movq -0x38(%rsp), %rdi
jne 0x12a30b
jmp 0x12a3dd
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rdx
movq -0x30(%rsp), %r12
movq 0x38(%rsp), %rax
movq %rdx, (%rax)
movq 0x40(%rsp), %rax
movq %r12, (%rax)
movl $0x1, %eax
jmp 0x12a3ca