// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/anchor.cpp
// Function: recalu_minimizer0_adv(char*, unsigned long, unsigned long, long, unsigned long, unsigned long, tiny_queue_t*, unsigned long*, unsigned long*)
uint64_t recalu_minimizer0_adv(char *s, uint64_t len, uint64_t is_hpc, int64_t mz_k, uint64_t mz_h, uint64_t rev, 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(!rev) {
		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;
				}
			}
		}
	} else {
		uint8_t ch[5] = {3, 2, 1, 0, 5};
		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[len-k-1]] != seq_nt4_table[(uint8_t)s[len-l-1]]) {
					c = ch[seq_nt4_table[(uint8_t)s[len-l-1]]];
					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 = ch[seq_nt4_table[(uint8_t)s[len-k-1]]];
				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 0x48(%rsp), %rbp
movq 0x40(%rsp), %r8
leaq -0x1(%rcx), %rax
movq %rax, -0x10(%rsp)
movq $-0x1, %rax
movq $-0x1, %r10
movq %rcx, -0x30(%rsp)
shlq %cl, %r10
xorq %rax, %r10
movq %r10, -0x18(%rsp)
movq %rax, (%rbp)
movq %rax, (%r8)
testq %r9, %r9
movq %rsi, -0x38(%rsp)
je 0x12a6dc
testq %rdx, %rdx
je 0x12a90a
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
testq %rsi, %rsi
je 0x12abd9
leaq (%rdi,%rsi), %rbx
addq $-0x2, %rdi
movl $0x1, %edx
leaq 0x103595(%rip), %r13    # 0x22da10
leaq 0x104b1a(%rip), %r9     # 0x22ef9c
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r14d, %r14d
movq $0x0, -0x40(%rsp)
xorl %r8d, %r8d
xorl %r11d, %r11d
xorl %eax, %eax
movq %r11, %rcx
notq %rcx
cmpq %rdx, %rsi
je 0x12a4c5
movzbl (%rdi,%rsi), %r10d
movb (%r13,%r10), %r10b
movzbl (%rbx,%rcx), %r15d
cmpb (%r13,%r15), %r10b
movq -0x38(%rsp), %rsi
je 0x12a6c8
movzbl (%rbx,%rcx), %ecx
movzbl (%r13,%rcx), %ecx
cmpq $0x4, %rcx
jne 0x12a4e9
movq %rdx, %r11
xorl %r8d, %r8d
movq $0x0, -0x40(%rsp)
jmp 0x12a6c8
movzbl (%rcx,%r9), %ecx
movq %r12, %r10
movl %ecx, %r12d
addq %r14, %r14
shrl %ecx
orq %rcx, %r14
movq %rbp, %r15
movl $0x1, %ebp
subq %rcx, %rbp
andl $0x1, %r12d
leaq (%r12,%rax,2), %rax
movq -0x18(%rsp), %rcx
andq %rcx, %rax
andq %rcx, %r14
shrq %r10
xorq $0x1, %r12
movq -0x10(%rsp), %rcx
shlq %cl, %r12
shlq %cl, %rbp
orq %r10, %r12
shrq %r15
orq %r15, %rbp
cmpq %rbp, %r14
jne 0x12a544
movq -0x38(%rsp), %rsi
jmp 0x12a6c8
movq %r8, -0x8(%rsp)
movq %rax, -0x28(%rsp)
movq %r13, %r9
movq %rbx, %rax
movl %edx, %ebx
subl %r11d, %ebx
movq 0x38(%rsp), %r13
movslq 0x4(%r13), %r15
movq %r15, %rcx
incq %rcx
movl %ecx, 0x4(%r13)
movslq (%r13), %r10
leal (%r10,%r15), %r8d
andl $0x3f, %r8d
movl %ebx, 0x8(%r13,%r8,4)
cmpq -0x30(%rsp), %rcx
jle 0x12a5a6
testl %ecx, %ecx
je 0x12a5c3
leal 0x1(%r10), %r8d
movq 0x38(%rsp), %rbx
movl %r8d, (%rbx)
movslq 0x8(%rbx,%r10,4), %rcx
andl $0x3f, %r8d
movl %r8d, (%rbx)
movl %r15d, 0x4(%rbx)
jmp 0x12a5ca
movq -0x40(%rsp), %rcx
subq %r11, %rcx
addq %rdx, %rcx
movq %rcx, -0x40(%rsp)
movq %rax, %rbx
movq %r9, %r13
movq -0x38(%rsp), %rsi
jmp 0x12a5eb
movq $-0x1, %rcx
movq %rax, %rbx
movq %r9, %r13
movq -0x38(%rsp), %rsi
movq %rdx, %r8
subq %r11, %r8
movq -0x40(%rsp), %rax
addq %r8, %rax
subq %rcx, %rax
movq %rax, -0x40(%rsp)
leaq 0x1049aa(%rip), %r9     # 0x22ef9c
movq -0x8(%rsp), %r8
incq %r8
cmpq -0x30(%rsp), %r8
movq -0x28(%rsp), %rax
jl 0x12a6c5
cmpq $0xff, -0x40(%rsp)
jg 0x12a6c5
movq %r8, %r15
cmpq %rbp, %r14
movq %r12, %rcx
cmovbq %rax, %rcx
movq %rcx, %r8
notq %r8
movq %rbp, %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, %eax       # imm = 0x80000001
imulq %rax, %r10
cmpq -0x20(%rsp), %r10
je 0x12abe6
movq %rdx, %r11
movq -0x28(%rsp), %rax
movq %r15, %r8
jmp 0x12a6c8
movq %rdx, %r11
incq %rdx
decq %rdi
cmpq %rsi, %rdx
jbe 0x12a49b
jmp 0x12abd9
testq %rdx, %rdx
je 0x12aa7a
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
testq %rsi, %rsi
je 0x12abd9
movl $0x1, %edx
leaq 0x10330a(%rip), %rbx    # 0x22da10
xorl %r8d, %r8d
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %r9d, %r9d
xorl %r13d, %r13d
xorl %r11d, %r11d
xorl %r15d, %r15d
cmpq %rdx, %rsi
je 0x12a735
movzbl (%rdi,%rdx), %eax
movb (%rbx,%rax), %al
movzbl (%rdi,%r11), %ecx
cmpb (%rbx,%rcx), %al
je 0x12a8f9
movzbl (%rdi,%r11), %eax
movzbl (%rbx,%rax), %ecx
cmpq $0x3, %rcx
ja 0x12a7f7
movq %r12, %rax
movl %ecx, %r12d
addq %r14, %r14
shrl %ecx
orq %rcx, %r14
movq %r8, %r10
movl $0x1, %r8d
subq %rcx, %r8
andl $0x1, %r12d
leaq (%r12,%r15,2), %r15
movq -0x18(%rsp), %rcx
andq %rcx, %r15
andq %rcx, %r14
shrq %rax
xorq $0x1, %r12
movq -0x10(%rsp), %rcx
shlq %cl, %r12
shlq %cl, %r8
orq %rax, %r12
shrq %r10
orq %r10, %r8
cmpq %r8, %r14
je 0x12a8f9
movq %r13, -0x28(%rsp)
movq %r15, -0x40(%rsp)
movq %rbx, %r13
movl %edx, %r15d
subl %r11d, %r15d
movq 0x38(%rsp), %rbp
movslq 0x4(%rbp), %rcx
movq %rcx, %r10
incq %r10
movl %r10d, 0x4(%rbp)
movslq (%rbp), %rax
leal (%rax,%rcx), %ebx
andl $0x3f, %ebx
movl %r15d, 0x8(%rbp,%rbx,4)
cmpq -0x30(%rsp), %r10
jle 0x12a805
testl %r10d, %r10d
je 0x12a81a
leal 0x1(%rax), %r10d
movq 0x38(%rsp), %rbx
movl %r10d, (%rbx)
movslq 0x8(%rbx,%rax,4), %rax
andl $0x3f, %r10d
movl %r10d, (%rbx)
movl %ecx, 0x4(%rbx)
jmp 0x12a821
movq %rdx, %r11
xorl %r13d, %r13d
xorl %r9d, %r9d
jmp 0x12a8f9
subq %r11, %r9
addq %rdx, %r9
movq -0x38(%rsp), %rsi
movq %r13, %rbx
movq -0x40(%rsp), %r15
jmp 0x12a83a
movq $-0x1, %rax
movq -0x38(%rsp), %rsi
movq %r13, %rbx
movq -0x40(%rsp), %r15
movq %rdx, %rcx
subq %r11, %rcx
addq %rcx, %r9
subq %rax, %r9
movq -0x28(%rsp), %r13
incq %r13
cmpq -0x30(%rsp), %r13
jl 0x12a8f6
cmpq $0xff, %r9
jg 0x12a8f6
cmpq %r8, %r14
movq %r12, %rax
cmovbq %r15, %rax
movq %rax, %rcx
notq %rcx
movq %r8, %r10
cmovbq %r14, %r10
shlq $0x15, %rax
addq %rcx, %rax
movq %rax, %rcx
shrq $0x18, %rcx
xorq %rax, %rcx
imulq $0x109, %rcx, %rax      # imm = 0x109
movq %rax, %rcx
shrq $0xe, %rcx
xorq %rax, %rcx
leaq (%rcx,%rcx,4), %rax
leaq (%rcx,%rax,4), %rax
movq %rax, %rcx
shrq $0x1c, %rcx
xorq %rax, %rcx
movq %r10, %rax
notq %rax
shlq $0x15, %r10
addq %rax, %r10
movq %r10, %rax
shrq $0x18, %rax
xorq %r10, %rax
imulq $0x109, %rax, %rax      # imm = 0x109
movq %rax, %r10
shrq $0xe, %r10
xorq %rax, %r10
leaq (%r10,%r10,4), %rax
leaq (%r10,%rax,4), %rax
movq %rax, %r10
shrq $0x1c, %r10
xorq %rax, %r10
addq %rcx, %r10
movl $0x80000001, %eax       # imm = 0x80000001
imulq %rax, %r10
cmpq -0x20(%rsp), %r10
je 0x12abff
movq %rdx, %r11
incq %rdx
cmpq %rsi, %rdx
jbe 0x12a71b
jmp 0x12abd9
testq %rsi, %rsi
je 0x12abd9
movl $0x80000001, %eax       # imm = 0x80000001
addq %rsi, %rdi
decq %rdi
negq %rsi
leaq 0x1030e8(%rip), %r8     # 0x22da10
leaq 0x10466d(%rip), %rbx    # 0x22ef9c
xorl %edx, %edx
xorl %r11d, %r11d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r9d, %r9d
xorl %r13d, %r13d
xorl %r12d, %r12d
movzbl (%rdi,%rdx), %ecx
movzbl (%r8,%rcx), %ecx
cmpq $0x4, %rcx
jne 0x12a95c
xorl %r13d, %r13d
xorl %r9d, %r9d
jmp 0x12aa69
movzbl (%rcx,%rbx), %ecx
movq %rbp, %r10
movl %ecx, %ebp
addq %r14, %r14
shrl %ecx
orq %rcx, %r14
movq %r11, %r15
movl $0x1, %r11d
subq %rcx, %r11
andl $0x1, %ebp
leaq (,%r12,2), %r12
addq %rbp, %r12
movq -0x18(%rsp), %rcx
andq %rcx, %r12
andq %rcx, %r14
shrq %r10
xorq $0x1, %rbp
movq -0x10(%rsp), %rcx
shlq %cl, %rbp
shlq %cl, %r11
orq %r10, %rbp
shrq %r15
orq %r15, %r11
cmpq %r11, %r14
je 0x12aa69
incq %r13
movq -0x30(%rsp), %rcx
cmpq %rcx, %r9
leaq 0x1(%r9), %r9
cmovgeq %rcx, %r9
cmpq %rcx, %r13
jl 0x12aa69
cmpq %r11, %r14
movq %rbp, %rcx
cmovbq %r12, %rcx
movq %rcx, %r10
notq %r10
movq %r11, %r15
cmovbq %r14, %r15
shlq $0x15, %rcx
addq %r10, %rcx
movq %rcx, %r10
shrq $0x18, %r10
xorq %rcx, %r10
imulq $0x109, %r10, %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
movq %r15, %rcx
notq %rcx
shlq $0x15, %r15
addq %rcx, %r15
movq %r15, %rcx
shrq $0x18, %rcx
xorq %r15, %rcx
imulq $0x109, %rcx, %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
addq %r10, %r15
imulq %rax, %r15
cmpq -0x20(%rsp), %r15
je 0x12abfa
decq %rdx
cmpq %rdx, %rsi
jne 0x12a942
jmp 0x12abd9
testq %rsi, %rsi
je 0x12abd9
movl $0x80000001, %eax       # imm = 0x80000001
leaq 0x102f81(%rip), %r8     # 0x22da10
xorl %r11d, %r11d
xorl %r13d, %r13d
xorl %ebx, %ebx
xorl %r9d, %r9d
xorl %r12d, %r12d
xorl %edx, %edx
xorl %r14d, %r14d
movzbl (%rdi,%rdx), %ecx
movzbl (%r8,%rcx), %ecx
cmpq $0x3, %rcx
ja 0x12ab24
movq %r13, %r10
movl %ecx, %r13d
addq %rbx, %rbx
shrl %ecx
orq %rcx, %rbx
movq %r11, %r15
movl $0x1, %r11d
subq %rcx, %r11
andl $0x1, %r13d
leaq (,%r14,2), %r14
addq %r13, %r14
movq -0x18(%rsp), %rcx
andq %rcx, %r14
andq %rcx, %rbx
shrq %r10
xorq $0x1, %r13
movq -0x10(%rsp), %rcx
shlq %cl, %r13
shlq %cl, %r11
orq %r10, %r13
shrq %r15
orq %r15, %r11
cmpq %r11, %rbx
je 0x12ab1d
incq %r12
movq -0x30(%rsp), %rcx
cmpq %rcx, %r9
leaq 0x1(%r9), %r9
cmovgeq %rcx, %r9
cmpq %rcx, %r12
jge 0x12ab3b
movq -0x38(%rsp), %rsi
jmp 0x12ab2a
xorl %r12d, %r12d
xorl %r9d, %r9d
incq %rdx
cmpq %rdx, %rsi
jne 0x12aaa2
jmp 0x12abd9
cmpq %r11, %rbx
movq %r13, %rcx
cmovbq %r14, %rcx
movq %rcx, %r10
notq %r10
movq %r11, %r15
cmovbq %rbx, %r15
shlq $0x15, %rcx
addq %r10, %rcx
movq %rcx, %r10
shrq $0x18, %r10
xorq %rcx, %r10
imulq $0x109, %r10, %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
movq %r15, %rcx
notq %rcx
shlq $0x15, %r15
addq %rcx, %r15
movq %r15, %rcx
shrq $0x18, %rcx
xorq %r15, %rcx
imulq $0x109, %rcx, %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
addq %r10, %r15
imulq %rax, %r15
cmpq -0x20(%rsp), %r15
movq -0x38(%rsp), %rsi
jne 0x12ab2a
jmp 0x12ac07
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rdx
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rax
movq -0x40(%rsp), %r9
jmp 0x12ac0c
negq %rdx
jmp 0x12ac02
decq %rdx
movq 0x48(%rsp), %rbp
movq 0x40(%rsp), %rax
movq %rdx, (%rax)
movq %r9, (%rbp)
movl $0x1, %eax
jmp 0x12abdb