// File: 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
movq %rsp, %rbp
subq $0xc0, %rsp
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)
movq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rcx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x58(%rbp)
leaq -0x80(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movq 0x18(%rbp), %rax
movq $-0x1, (%rax)
movq 0x10(%rbp), %rax
movq $-0x1, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x1ad4f6
movq -0x38(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
movq $0x1, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
ja 0x1ad4f1
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
je 0x1ad2c9
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1dd53c(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movq -0x48(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
movl %ecx, %edx
leaq 0x1dd523(%rip), %rcx    # 0x38a7e0
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x1ad4de
movq -0x10(%rbp), %rax
movq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1dd502(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq %rax, -0x88(%rbp)
cmpq $0x4, -0x88(%rbp)
jae 0x1ad4c0
movq -0x80(%rbp), %rax
shlq %rax
movq -0x88(%rbp), %rcx
andq $0x1, %rcx
orq %rcx, %rax
andq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
shlq %rax
movq -0x88(%rbp), %rcx
shrq %rcx
orq %rcx, %rax
andq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
shrq %rax
movq -0x88(%rbp), %rcx
andq $0x1, %rcx
movl $0x1, %edx
subq %rcx, %rdx
movq -0x50(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
shrq %rax
movq -0x88(%rbp), %rcx
shrq %rcx
movl $0x1, %edx
subq %rcx, %rdx
movq -0x50(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x1ad394
jmp 0x1ad4e0
movq -0x78(%rbp), %rdx
movq -0x68(%rbp), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovbl %ecx, %eax
cltq
movq %rax, -0x90(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0x40(%rbp), %rax
subq -0x48(%rbp), %rax
addq -0xa8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rax
subq -0x48(%rbp), %rax
movl %eax, %esi
callq 0x1ad720
movq -0x38(%rbp), %rax
movslq 0x4(%rax), %rax
cmpq -0x28(%rbp), %rax
jle 0x1ad418
movq -0x38(%rbp), %rdi
callq 0x1ad760
movslq %eax, %rcx
movq -0xa8(%rbp), %rax
subq %rcx, %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x1ad4be
cmpq $0x100, -0xa8(%rbp) # imm = 0x100
jge 0x1ad4be
movq -0x90(%rbp), %rax
shlq %rax
orq $0x0, %rax
movq -0x80(%rbp,%rax,8), %rdi
callq 0x1ad7c0
movq %rax, -0xb0(%rbp)
movq -0x90(%rbp), %rax
shlq %rax
orq $0x1, %rax
movq -0x80(%rbp,%rax,8), %rdi
callq 0x1ad7c0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x98(%rbp), %rax
jne 0x1ad4bc
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x1ad706
jmp 0x1ad4be
jmp 0x1ad4d6
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x1ad4e0
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1ad277
jmp 0x1ad6fe
movq $0x0, -0x40(%rbp)
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jae 0x1ad6fc
movq -0x10(%rbp), %rax
movq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1dd2a9(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movq %rax, -0x88(%rbp)
cmpq $0x4, -0x88(%rbp)
jae 0x1ad6d3
movq -0x80(%rbp), %rax
shlq %rax
movq -0x88(%rbp), %rcx
andq $0x1, %rcx
orq %rcx, %rax
andq -0x58(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
shlq %rax
movq -0x88(%rbp), %rcx
shrq %rcx
orq %rcx, %rax
andq -0x58(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
shrq %rax
movq -0x88(%rbp), %rcx
andq $0x1, %rcx
movl $0x1, %edx
subq %rcx, %rdx
movq -0x50(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
shrq %rax
movq -0x88(%rbp), %rcx
shrq %rcx
movl $0x1, %edx
subq %rcx, %rdx
movq -0x50(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x78(%rbp), %rax
cmpq -0x68(%rbp), %rax
jne 0x1ad5ed
jmp 0x1ad6eb
movq -0x78(%rbp), %rdx
movq -0x68(%rbp), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovbl %ecx, %eax
cltq
movq %rax, -0x90(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0x28(%rbp), %rax
jle 0x1ad647
movq -0x28(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x28(%rbp), %rax
jl 0x1ad6d1
movq -0x90(%rbp), %rax
shlq %rax
orq $0x0, %rax
movq -0x80(%rbp,%rax,8), %rdi
callq 0x1ad7c0
movq %rax, -0xb8(%rbp)
movq -0x90(%rbp), %rax
shlq %rax
orq $0x1, %rax
movq -0x80(%rbp,%rax,8), %rdi
callq 0x1ad7c0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
cmpq -0x98(%rbp), %rax
jne 0x1ad6cf
movq -0x40(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0xa8(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq $0x1, -0x8(%rbp)
jmp 0x1ad706
jmp 0x1ad6d1
jmp 0x1ad6e9
movq $0x0, -0xa8(%rbp)
movq $0x0, -0xa0(%rbp)
jmp 0x1ad6eb
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1ad514
jmp 0x1ad6fe
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)