// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/sketch.cpp
// Function: debug_pl(char const*, int, int, int, int, ha_mz1_v*, void const*, st_mt_t*)
void debug_pl(const char *str, int len, int w, int k, int is_hpc, ha_mz1_v *p, const void *hf, st_mt_t *mt)
{
	int i, l, dbi, dbcnt = 0, kmer_span = 0;
	tiny_queue_t tq;
	memset(&tq, 0, sizeof(tiny_queue_t));
	uint64_t shift1 = k - 1, mask = (1ULL<<k) - 1, kmer[4] = {0,0,0,0};
	
    for (i = l = dbi = 0; i < len; ++i) {
        int c = seq_nt4_table[(uint8_t)str[i]];
        if (c < 4) { // not an ambiguous base
            int z;
            if (is_hpc) {
                int skip_len = 1;
                if (i + 1 < len && seq_nt4_table[(uint8_t)str[i + 1]] == c) {
                    for (skip_len = 2; i + skip_len < len; ++skip_len)
                        if (seq_nt4_table[(uint8_t)str[i + skip_len]] != c)
                            break;
                    i += skip_len - 1; // put $i at the end of the current homopolymer run
                }
                tq_push(&tq, skip_len);
                kmer_span += skip_len;
                ///how many bases that are covered by this HPC k-mer
                ///kmer_span includes at most k HPC elements
                if (tq.count > k) kmer_span -= tq_shift(&tq);
            } else kmer_span = l + 1 < k? l + 1 : k; 
            ///kmer_span should be used for HPC k-mer
            ///non-HPC k-mer, kmer_span should be k
            ///kmer_span is used to calculate anchor pos on reverse complementary strand

            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
            ++l;

            if (l >= k && kmer_span < 256) {
                uint64_t y;
                int32_t cnt;
                y = yak_hash64_64(kmer[z<<1|0]) + yak_hash64_64(kmer[z<<1|1]);
                cnt = hf? ha_ft_cnt(hf, y) : 0;

				for (dbi = 0; dbi < (int32_t)mt->n; dbi++)
				{
					if(p->a[dbi].x == y && p->a[dbi].rid == cnt && p->a[dbi].pos == i && p->a[dbi].rev == z && p->a[dbi].span == kmer_span)
					{
						if(l != (int)mt->a[dbi]) fprintf(stderr, "ERROR\n");
						dbcnt++;
					}
				}
            }
        } else l = 0, tq.count = tq.front = 0, kmer_span = 0;
	}

	if(dbcnt != (int32_t)mt->n) fprintf(stderr, "ERROR\n");
	if(mt->n != p->n) fprintf(stderr, "ERROR\n");
	for (dbi = 1; dbi < (int32_t)mt->n; dbi++)
	{
		if(p->a[dbi].pos <= p->a[dbi-1].pos || (int)mt->a[dbi] <= (int)mt->a[dbi-1])
		{
			fprintf(stderr, "ERROR\n");
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movq %r9, %rbx
movl %r8d, 0x3c(%rsp)
movl %ecx, %r12d
movl %esi, %r15d
movq %rdi, %r13
movq 0x1e8(%rsp), %r14
leaq 0xa0(%rsp), %rdi
movl $0x108, %edx            # imm = 0x108
xorl %esi, %esi
callq 0x20e0
xorl %r8d, %r8d
movq %r14, %r10
movq %rbx, %r9
movq $-0x1, %r14
movq %r12, 0x28(%rsp)
movl %r12d, %ecx
shlq %cl, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movl %r15d, 0x8(%rsp)
testl %r15d, %r15d
movq %rbx, 0x10(%rsp)
jle 0x119db1
movq %r13, %rbx
movq 0x28(%rsp), %rax
decl %eax
cltq
movq %rax, 0x90(%rsp)
notq %r14
movq 0x40(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x30(%rsp)
movl 0xa0(%rsp), %ebp
movl 0xa4(%rsp), %eax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %r13
movl 0x8(%rsp), %eax
movq %rax, 0x98(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
xorl %r8d, %r8d
movl $0x0, 0x4(%rsp)
movq %rbx, 0x70(%rsp)
movq %r14, 0x68(%rsp)
movslq %r15d, %rdx
movzbl (%rbx,%rdx), %eax
leaq 0x11400c(%rip), %rcx    # 0x22da10
movzbl (%rcx,%rax), %eax
cmpl $0x3, %eax
ja 0x119aa5
cmpl $0x0, 0x3c(%rsp)
je 0x119acb
movq %rsi, %r12
leaq 0x1(%rdx), %rsi
movl $0x1, %ecx
cmpl 0x8(%rsp), %esi
jge 0x119ae4
movq %rdi, %r11
movzbl (%rbx,%rsi), %esi
leaq 0x113fd0(%rip), %rdi    # 0x22da10
cmpb %al, (%rdi,%rsi)
jne 0x119afb
leal 0x2(%r15), %esi
movl $0x2, %ecx
cmpl 0x8(%rsp), %esi
jge 0x119af5
movq %rbp, 0x18(%rsp)
movl %r8d, 0xc(%rsp)
movl 0x8(%rsp), %ecx
subl %r15d, %ecx
movl %r15d, %edi
movl $0x2, %esi
leal (%rdi,%rsi), %r8d
movslq %r8d, %r8
movzbl (%rbx,%r8), %r8d
leaq 0x113f88(%rip), %rbp    # 0x22da10
cmpb %al, (%rbp,%r8)
jne 0x119ae9
leaq (%rdx,%rsi), %r8
incq %r8
incq %rsi
cmpq 0x98(%rsp), %r8
jl 0x119a75
jmp 0x119aeb
movq $0x0, 0xa0(%rsp)
movq $0x0, 0x20(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x4(%rsp)
xorl %edi, %edi
jmp 0x119da3
movq %rdi, %r11
leal 0x1(%rdi), %ecx
movq 0x28(%rsp), %rdx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movl %ecx, 0x4(%rsp)
jmp 0x119b66
movq %rdi, %r11
jmp 0x119afb
movl %esi, %ecx
movl 0xc(%rsp), %r8d
movq 0x18(%rsp), %rbp
addl %ecx, %r15d
decl %r15d
movq 0x20(%rsp), %rdi
leal 0x1(%rdi), %edx
movl %edx, 0xa4(%rsp)
leal (%rdi,%rbp), %esi
andl $0x3f, %esi
movl %ecx, 0xa8(%rsp,%rsi,4)
addl %ecx, 0x4(%rsp)
cmpl 0x28(%rsp), %edi
jl 0x119b5c
testl %edx, %edx
je 0x119b53
movslq %ebp, %rcx
leal 0x1(%rbp), %esi
movl %esi, 0xa0(%rsp)
movl 0xa8(%rsp,%rcx,4), %ecx
andl $0x3f, %esi
movl %esi, 0xa0(%rsp)
movq 0x20(%rsp), %rdx
movl %edx, 0xa4(%rsp)
movl %esi, %ebp
jmp 0x119b58
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
subl %ecx, 0x4(%rsp)
movl %edx, %ecx
movq %rcx, 0x20(%rsp)
movq %r12, %rsi
movq %rsi, %rdx
movl %eax, %esi
andl $0x1, %esi
movq 0x78(%rsp), %rcx
leaq (%rsi,%rcx,2), %rcx
andq %r14, %rcx
movq %rcx, 0x78(%rsp)
movq %rcx, 0x40(%rsp)
movq 0x30(%rsp), %rdi
addq %rdi, %rdi
shrl %eax
orq %rax, %rdi
andq %r14, %rdi
xorl $0x1, %esi
movq 0x90(%rsp), %rcx
shlq %cl, %rsi
movq %rdi, 0x48(%rsp)
shrq %rdx
orq %rdx, %rsi
movq %rsi, 0x50(%rsp)
movq %r13, %rdx
movl $0x1, %r13d
subl %eax, %r13d
shlq %cl, %r13
shrq %rdx
orq %rdx, %r13
movq %r13, 0x58(%rsp)
movq %rdi, 0x30(%rsp)
cmpq %r13, %rdi
jne 0x119bde
movq %r11, %rdi
jmp 0x119da3
movq %r11, %rdi
incl %edi
cmpl 0x28(%rsp), %edi
jl 0x119da3
cmpl $0xff, 0x4(%rsp)
jg 0x119da3
movq %rbp, 0x18(%rsp)
xorl %eax, %eax
cmpq %r13, 0x30(%rsp)
setae %al
shll $0x4, %eax
movq 0x40(%rsp,%rax), %rcx
movq 0x48(%rsp,%rax), %rax
movq %rcx, %rdx
notq %rdx
shlq $0x15, %rcx
addq %rdx, %rcx
movq %rcx, %rdx
shrq $0x18, %rdx
xorq %rcx, %rdx
imulq $0x109, %rdx, %rcx      # imm = 0x109
movq %rcx, %rdx
shrq $0xe, %rdx
xorq %rcx, %rdx
leaq (%rdx,%rdx,4), %rcx
leaq (%rdx,%rcx,4), %rcx
movq %rcx, %rdx
shrq $0x1c, %rdx
xorq %rcx, %rdx
movq %rax, %rcx
notq %rcx
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
addq %rdx, %rcx
movq %rcx, %rbp
shlq $0x1f, %rbp
addq %rcx, %rbp
cmpq $0x0, 0x1e0(%rsp)
je 0x119cd7
movq %rdi, %rbx
movq 0x1e0(%rsp), %rdi
movq %rsi, %r12
movq %rbp, %rsi
movl %r8d, %r14d
callq 0x1149e5
movq %r12, %rsi
movl %r14d, %r8d
movq %rbx, %rdi
movq 0x1e8(%rsp), %r10
movq 0x10(%rsp), %r9
movl %eax, %r14d
jmp 0x119cda
xorl %r14d, %r14d
cmpl $0x0, (%r10)
jle 0x119d94
movl $0x8, %ebx
xorl %r12d, %r12d
movq 0x8(%r9), %rax
cmpq %rbp, -0x8(%rax,%rbx)
jne 0x119d45
movq (%rax,%rbx), %rax
movl %eax, %ecx
andl $0xfffffff, %ecx        # imm = 0xFFFFFFF
cmpl %r14d, %ecx
jne 0x119d45
movq %rax, %rcx
shrq $0x1c, %rcx
andl $0x7ffffff, %ecx        # imm = 0x7FFFFFF
cmpl %r15d, %ecx
jne 0x119d45
cmpq %r13, 0x30(%rsp)
setae %cl
btq $0x37, %rax
setae %dl
cmpb %dl, %cl
je 0x119d45
shrq $0x38, %rax
cmpl %eax, 0x4(%rsp)
jne 0x119d45
movq 0x10(%r10), %rax
cmpl (%rax,%r12,8), %edi
jne 0x119d56
incl %r8d
incq %r12
movslq (%r10), %rax
addq $0x10, %rbx
cmpq %rax, %r12
jl 0x119cec
jmp 0x119d94
movl %r8d, 0xc(%rsp)
movq %rsi, 0x88(%rsp)
movq %rdi, 0x80(%rsp)
callq 0x15535
movq 0x88(%rsp), %rsi
movl 0xc(%rsp), %r8d
movq 0x80(%rsp), %rdi
movq 0x1e8(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0x119d42
movq 0x70(%rsp), %rbx
movq 0x68(%rsp), %r14
movq 0x18(%rsp), %rbp
incl %r15d
cmpl 0x8(%rsp), %r15d
jl 0x1199f6
cmpl (%r10), %r8d
jne 0x119e3d
movl (%r9), %eax
cmpq %rax, (%r10)
jne 0x119e54
cmpl $0x2, (%r10)
jl 0x119e2b
movl $0x1, %ebx
movl $0x3, %r14d
movl $0x7ffffff, %ebp        # imm = 0x7FFFFFF
movq 0x8(%r9), %rax
movq -0x10(%rax,%r14,8), %rcx
movq (%rax,%r14,8), %rax
shrq $0x1c, %rax
andl %ebp, %eax
shrq $0x1c, %rcx
andl %ebp, %ecx
cmpl %ecx, %eax
jbe 0x119e17
movq 0x10(%r10), %rax
movl (%rax,%rbx,8), %ecx
cmpl -0x8(%rax,%rbx,8), %ecx
jle 0x119e17
incq %rbx
movslq (%r10), %rax
addq $0x2, %r14
cmpq %rax, %rbx
jl 0x119ddc
jmp 0x119e2b
callq 0x15589
movq 0x1e8(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0x119e06
addq $0x1a8, %rsp            # imm = 0x1A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x15551
movq 0x1e8(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0x119dba
callq 0x1556d
movq 0x1e8(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0x119dc6