// File: /workspace/github_cpp_makefile_star2_O3/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), %r15
movq 0x40(%rsp), %r8
leaq -0x1(%rcx), %rax
movq %rax, -0x10(%rsp)
movq $-0x1, %rax
movq $-0x1, %r10
movq %rcx, -0x28(%rsp)
shlq %cl, %r10
xorq %rax, %r10
movq %r10, -0x18(%rsp)
movq %rax, (%r15)
movq %rax, (%r8)
testq %r9, %r9
je 0x130796
testq %rdx, %rdx
je 0x1309e2
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
xorl %eax, %eax
testq %rsi, %rsi
je 0x130cd1
leaq (%rdi,%rsi), %r13
addq $-0x2, %rdi
movl $0x1, %edx
leaq 0x1096e6(%rip), %r12    # 0x239c20
movq $0x0, -0x38(%rsp)
xorl %r8d, %r8d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %eax, %eax
movq $0x0, -0x40(%rsp)
movq $0x0, -0x30(%rsp)
xorl %r10d, %r10d
xorl %r9d, %r9d
movq %r13, -0x8(%rsp)
movq %r10, %rcx
notq %rcx
cmpq %rdx, %rsi
je 0x13058d
movzbl (%rdi,%rsi), %ebx
movb (%r12,%rbx), %bl
movzbl (%r13,%rcx), %r15d
cmpb (%r12,%r15), %bl
je 0x130782
movzbl (%r13,%rcx), %ecx
movzbl (%r12,%rcx), %ecx
cmpq $0x4, %rcx
jne 0x1305b8
movq %rdx, %r10
movq $0x0, -0x30(%rsp)
movq $0x0, -0x40(%rsp)
jmp 0x130782
leaq 0x10abed(%rip), %r11    # 0x23b1ac
movzbl (%rcx,%r11), %ecx
movq %r14, %rbx
movl %ecx, %r14d
addq %rax, %rax
shrl %ecx
orq %rcx, %rax
movq %rbp, %r15
movl $0x1, %ebp
subq %rcx, %rbp
andl $0x1, %r14d
leaq (%r14,%r9,2), %r9
movq -0x18(%rsp), %rcx
andq %rcx, %r9
andq %rcx, %rax
shrq %rbx
xorq $0x1, %r14
movq -0x10(%rsp), %rcx
shlq %cl, %r14
shlq %cl, %rbp
orq %rbx, %r14
shrq %r15
orq %r15, %rbp
cmpq %rbp, %rax
jne 0x130618
movq %rax, %rbp
jmp 0x130782
movq %r12, %r11
movl %edx, %ebx
subl %r10d, %ebx
leal 0x1(%r8), %ecx
movq 0x38(%rsp), %r12
movl %ecx, 0x4(%r12)
movq -0x38(%rsp), %r15
addl %r8d, %r15d
andl $0x3f, %r15d
movl %ebx, 0x8(%r12,%r15,4)
movslq %ecx, %rbx
cmpq -0x28(%rsp), %rbx
jle 0x130678
testl %ecx, %ecx
je 0x13068d
movq -0x38(%rsp), %rbx
movslq %ebx, %rcx
incl %ebx
movq 0x38(%rsp), %r15
movl %ebx, (%r15)
movslq 0x8(%r15,%rcx,4), %rcx
andl $0x3f, %ebx
movl %ebx, (%r15)
movq %r8, %r13
movl %r13d, 0x4(%r15)
movq %rbx, -0x38(%rsp)
jmp 0x130697
movq -0x40(%rsp), %r8
subq %r10, %r8
addq %rdx, %r8
movq %r8, -0x40(%rsp)
movq %r11, %r12
jmp 0x1306b3
movq $-0x1, %rcx
xorl %r13d, %r13d
movq %r11, %r12
movq %rdx, %rbx
subq %r10, %rbx
movq -0x40(%rsp), %r8
addq %rbx, %r8
subq %rcx, %r8
movq %r8, -0x40(%rsp)
movl %r13d, %ecx
movq -0x30(%rsp), %r11
incq %r11
movq %r11, -0x30(%rsp)
cmpq -0x28(%rsp), %r11
movq -0x8(%rsp), %r13
jl 0x13077c
cmpq $0xff, -0x40(%rsp)
jg 0x13077c
cmpq %rbp, %rax
movq %r14, %r10
cmovbq %r9, %r10
movq %r10, %r11
notq %r11
movq %rbp, %rbx
cmovbq %rax, %rbx
shlq $0x15, %r10
addq %r11, %r10
movq %r10, %r11
shrq $0x18, %r11
xorq %r10, %r11
imulq $0x109, %r11, %r10      # imm = 0x109
movq %r10, %r11
shrq $0xe, %r11
xorq %r10, %r11
leaq (%r11,%r11,4), %r10
leaq (%r11,%r10,4), %r10
movq %r10, %r11
shrq $0x1c, %r11
xorq %r10, %r11
movq %rbx, %r10
notq %r10
shlq $0x15, %rbx
addq %r10, %rbx
movq %rbx, %r10
shrq $0x18, %r10
xorq %rbx, %r10
imulq $0x109, %r10, %r10      # imm = 0x109
movq %r10, %rbx
shrq $0xe, %rbx
xorq %r10, %rbx
leaq (%rbx,%rbx,4), %r10
leaq (%rbx,%r10,4), %r10
movq %r10, %rbx
shrq $0x1c, %rbx
xorq %r10, %rbx
addq %r11, %rbx
movl $0x80000001, %r10d      # imm = 0x80000001
imulq %r10, %rbx
cmpq -0x20(%rsp), %rbx
je 0x130cdc
movl %ecx, %r8d
movq %rdx, %r10
incq %rdx
decq %rdi
cmpq %rsi, %rdx
jbe 0x13056a
jmp 0x130ccf
testq %rdx, %rdx
je 0x130b66
movq 0x38(%rsp), %rax
movq $0x0, (%rax)
xorl %eax, %eax
testq %rsi, %rsi
je 0x130cd1
movl $0x1, %edx
leaq 0x10945e(%rip), %r12    # 0x239c20
movq $0x0, -0x38(%rsp)
xorl %r11d, %r11d
xorl %eax, %eax
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %r9d, %r9d
xorl %r15d, %r15d
xorl %r10d, %r10d
xorl %ebp, %ebp
cmpq %rdx, %rsi
jne 0x1307f0
movzbl (%rdi,%r10), %ecx
movb (%r12,%rcx), %cl
jmp 0x130808
movzbl (%rdi,%rdx), %r8d
movzbl (%rdi,%r10), %ecx
movb (%r12,%rcx), %cl
cmpb %cl, (%r12,%r8)
je 0x1309d1
cmpb $0x3, %cl
ja 0x130862
movzbl %cl, %ecx
movq %rbx, %r8
movl %ecx, %ebx
addq %r14, %r14
shrl %ecx
orq %rcx, %r14
movq %rax, %r13
movl $0x1, %eax
subq %rcx, %rax
andl $0x1, %ebx
leaq (%rbx,%rbp,2), %rbp
movq -0x18(%rsp), %rcx
andq %rcx, %rbp
andq %rcx, %r14
shrq %r8
xorq $0x1, %rbx
movq -0x10(%rsp), %rcx
shlq %cl, %rbx
shlq %cl, %rax
orq %r8, %rbx
shrq %r13
orq %r13, %rax
cmpq %rax, %r14
jne 0x130870
movq %r14, %rax
jmp 0x1309d1
movq %rdx, %r10
xorl %r15d, %r15d
xorl %r9d, %r9d
jmp 0x1309d1
movq %rbp, -0x30(%rsp)
movq %r15, -0x40(%rsp)
movq %r12, %r15
movl %edx, %r8d
subl %r10d, %r8d
leal 0x1(%r11), %ecx
movq 0x38(%rsp), %r12
movl %ecx, 0x4(%r12)
movq -0x38(%rsp), %r13
addl %r11d, %r13d
andl $0x3f, %r13d
movl %r8d, 0x8(%r12,%r13,4)
movslq %ecx, %r8
cmpq -0x28(%rsp), %r8
jle 0x1308d8
testl %ecx, %ecx
je 0x1308ed
movq -0x38(%rsp), %r8
movslq %r8d, %rcx
incl %r8d
movl %r8d, (%r12)
movslq 0x8(%r12,%rcx,4), %rcx
andl $0x3f, %r8d
movl %r8d, (%r12)
movl %r11d, 0x4(%r12)
movq %r8, -0x38(%rsp)
jmp 0x1308f7
subq %r10, %r9
addq %rdx, %r9
movq %r15, %r12
movq -0x40(%rsp), %r15
movq -0x30(%rsp), %rbp
jmp 0x130913
movq $-0x1, %rcx
xorl %r11d, %r11d
movq %r15, %r12
movq -0x30(%rsp), %rbp
movq %rdx, %r8
subq %r10, %r8
addq %r8, %r9
subq %rcx, %r9
movl %r11d, %ecx
movq -0x40(%rsp), %r15
incq %r15
cmpq -0x28(%rsp), %r15
jl 0x1309cb
cmpq $0xff, %r9
jg 0x1309cb
cmpq %rax, %r14
movq %rbx, %r8
cmovbq %rbp, %r8
movq %r8, %r10
notq %r10
movq %rax, %r11
cmovbq %r14, %r11
shlq $0x15, %r8
addq %r10, %r8
movq %r8, %r10
shrq $0x18, %r10
xorq %r8, %r10
imulq $0x109, %r10, %r8       # imm = 0x109
movq %r8, %r10
shrq $0xe, %r10
xorq %r8, %r10
leaq (%r10,%r10,4), %r8
leaq (%r10,%r8,4), %r8
movq %r8, %r10
shrq $0x1c, %r10
xorq %r8, %r10
movq %r11, %r8
notq %r8
shlq $0x15, %r11
addq %r8, %r11
movq %r11, %r8
shrq $0x18, %r8
xorq %r11, %r8
imulq $0x109, %r8, %r8        # imm = 0x109
movq %r8, %r11
shrq $0xe, %r11
xorq %r8, %r11
leaq (%r11,%r11,4), %r8
leaq (%r11,%r8,4), %r8
movq %r8, %r11
shrq $0x1c, %r11
xorq %r8, %r11
addq %r10, %r11
movl $0x80000001, %r8d       # imm = 0x80000001
imulq %r8, %r11
cmpq -0x20(%rsp), %r11
je 0x130cf5
movl %ecx, %r11d
movq %rdx, %r10
incq %rdx
cmpq %rsi, %rdx
jbe 0x1307e0
jmp 0x130ccf
testq %rsi, %rsi
je 0x130ccf
movl $0x80000001, %eax       # imm = 0x80000001
addq %rsi, %rdi
decq %rdi
negq %rsi
leaq 0x109220(%rip), %r8     # 0x239c20
leaq 0x10a7a5(%rip), %r10    # 0x23b1ac
xorl %edx, %edx
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r11d, %r11d
xorl %r9d, %r9d
xorl %r12d, %r12d
xorl %r14d, %r14d
movzbl (%rdi,%rdx), %ecx
movzbl (%r8,%rcx), %ecx
cmpq $0x4, %rcx
jne 0x130a34
xorl %r12d, %r12d
xorl %r9d, %r9d
jmp 0x130b55
movzbl (%rcx,%r10), %ecx
movq %r13, %r15
movl %ecx, %r13d
addq %r11, %r11
shrl %ecx
orq %rcx, %r11
movq %rbx, %rbp
movl $0x1, %ebx
subq %rcx, %rbx
andl $0x1, %r13d
leaq (,%r14,2), %r14
addq %r13, %r14
movq -0x18(%rsp), %rcx
andq %rcx, %r14
andq %rcx, %r11
shrq %r15
xorq $0x1, %r13
movq -0x10(%rsp), %rcx
shlq %cl, %r13
shlq %cl, %rbx
orq %r15, %r13
shrq %rbp
orq %rbp, %rbx
cmpq %rbx, %r11
jne 0x130a94
movq %r11, %rbx
jmp 0x130b55
incq %r12
movq -0x28(%rsp), %rcx
cmpq %rcx, %r9
leaq 0x1(%r9), %r9
cmovgeq %rcx, %r9
cmpq %rcx, %r12
jl 0x130b55
cmpq %rbx, %r11
movq %r13, %rcx
cmovbq %r14, %rcx
movq %rcx, %r15
notq %r15
movq %rbx, %rbp
cmovbq %r11, %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
je 0x130cf0
decq %rdx
cmpq %rdx, %rsi
jne 0x130a1a
jmp 0x130ccf
testq %rsi, %rsi
je 0x130ccf
movl $0x80000001, %eax       # imm = 0x80000001
leaq 0x1090a5(%rip), %r8     # 0x239c20
xorl %r11d, %r11d
xorl %r12d, %r12d
xorl %r10d, %r10d
xorl %r9d, %r9d
xorl %r14d, %r14d
xorl %edx, %edx
xorl %ebx, %ebx
movzbl (%rdi,%rdx), %ecx
movzbl (%r8,%rcx), %ecx
cmpq $0x3, %rcx
ja 0x130bef
movq %r12, %r13
movl %ecx, %r12d
addq %r10, %r10
shrl %ecx
orq %rcx, %r10
movq %r11, %rbp
movl $0x1, %r11d
subq %rcx, %r11
andl $0x1, %r12d
leaq (%r12,%rbx,2), %rbx
movq -0x18(%rsp), %rcx
andq %rcx, %rbx
andq %rcx, %r10
shrq %r13
xorq $0x1, %r12
movq -0x10(%rsp), %rcx
shlq %cl, %r12
shlq %cl, %r11
orq %r13, %r12
shrq %rbp
orq %rbp, %r11
cmpq %r11, %r10
jne 0x130c02
movq %r10, %r11
jmp 0x130bf5
xorl %r14d, %r14d
xorl %r9d, %r9d
incq %rdx
cmpq %rdx, %rsi
jne 0x130b8e
jmp 0x130ccf
incq %r14
movq -0x28(%rsp), %rcx
cmpq %rcx, %r9
leaq 0x1(%r9), %r9
cmovgeq %rcx, %r9
cmpq %rcx, %r14
jl 0x130bf5
cmpq %r11, %r10
movq %r12, %rcx
cmovbq %rbx, %rcx
movq %rcx, %r13
notq %r13
movq %r11, %rbp
cmovbq %r10, %rbp
shlq $0x15, %rcx
addq %r13, %rcx
movq %rcx, %r13
shrq $0x18, %r13
xorq %rcx, %r13
imulq $0x109, %r13, %rcx      # imm = 0x109
movq %rcx, %r13
shrq $0xe, %r13
xorq %rcx, %r13
leaq (,%r13,4), %rcx
addq %r13, %rcx
leaq (,%rcx,4), %rcx
addq %r13, %rcx
movq %rcx, %r13
shrq $0x1c, %r13
xorq %rcx, %r13
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 %r13, %rbp
imulq %rax, %rbp
cmpq -0x20(%rsp), %rbp
jne 0x130bf5
jmp 0x130cfd
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decq %rdx
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %rax
movq -0x40(%rsp), %r9
jmp 0x130d02
negq %rdx
jmp 0x130cf8
decq %rdx
movq 0x48(%rsp), %r15
movq 0x40(%rsp), %rax
movq %rdx, (%rax)
movq %r9, (%r15)
movl $0x1, %eax
jmp 0x130cd1