// File: /workspace/github_cpp_makefile_star2_O2/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 $0x198, %rsp            # imm = 0x198
movq %r9, 0x8(%rsp)
movl %r8d, 0x44(%rsp)
movl %ecx, %r15d
movl %esi, %r14d
movq %rdi, 0x68(%rsp)
movq 0x1d8(%rsp), %rbx
leaq 0x90(%rsp), %rdi
xorl %r13d, %r13d
movl $0x108, %edx            # imm = 0x108
xorl %esi, %esi
callq 0x20e0
movq %rbx, %r8
leal -0x1(%r15), %eax
cltq
movq %rax, 0x60(%rsp)
pushq $-0x1
popq %rax
movl %r15d, %ecx
shlq %cl, %rax
notq %rax
movq %rax, 0x58(%rsp)
movl %r14d, 0x1c(%rsp)
movslq %r14d, %r9
leaq 0x11009e(%rip), %r10    # 0x1ebb00
pushq $0x1
popq %r11
movq $0x0, 0x50(%rsp)
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r12d, %r12d
movl $0x0, 0x14(%rsp)
xorl %ebx, %ebx
xorl %r14d, %r14d
movq %r15, 0x38(%rsp)
movq %r9, 0x28(%rsp)
movl 0x1c(%rsp), %eax
subl %r14d, %eax
jle 0xdbd75
movslq %r14d, %rcx
movq 0x68(%rsp), %rsi
movzbl (%rsi,%rcx), %edx
movzbl (%r10,%rdx), %r15d
cmpl $0x3, %r15d
ja 0xdbaf2
cmpl $0x0, 0x44(%rsp)
je 0xdbb0a
leaq 0x1(%rcx), %rdx
cmpl 0x1c(%rsp), %edx
jge 0xdbb05
movzbl (%rsi,%rdx), %edx
cmpb %r15b, (%r10,%rdx)
jne 0xdbb05
movq %rbp, 0x30(%rsp)
movq %rdi, %rbp
addq %rcx, %rsi
pushq $0x2
popq %rdx
leaq (%rcx,%rdx), %rdi
cmpq %r9, %rdi
jge 0xdbb21
movzbl (%rsi,%rdx), %edi
cmpb %r15b, (%r10,%rdi)
jne 0xdbb1f
incq %rdx
jmp 0xdbada
andq $0x0, 0x90(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
jmp 0xdbd6d
movl %r11d, %eax
jmp 0xdbb2f
leal 0x1(%rbx), %r12d
movq 0x38(%rsp), %rax
cmpl %eax, %r12d
cmovgel %eax, %r12d
jmp 0xdbba0
movl %edx, %eax
addl %eax, %r14d
decl %r14d
movq %rbp, %rdi
movq 0x30(%rsp), %rbp
movl 0x94(%rsp), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x94(%rsp)
movl 0x90(%rsp), %edx
addl %ecx, %edx
andl $0x3f, %edx
movl %eax, 0x98(%rsp,%rdx,4)
addl %eax, %r12d
cmpl 0x38(%rsp), %ecx
jl 0xdbba0
movq %rbx, 0x20(%rsp)
movl %r12d, %ebx
movq %rbp, %r12
movq %rdi, %rbp
leaq 0x90(%rsp), %rdi
callq 0xdbe6e
movq %rbp, %rdi
movq %r12, %rbp
movl %ebx, %r12d
movq 0x20(%rsp), %rbx
pushq $0x1
popq %r11
leaq 0x10ff70(%rip), %r10    # 0x1ebb00
movq 0x28(%rsp), %r9
movq 0x1d8(%rsp), %r8
subl %eax, %r12d
movq 0x50(%rsp), %rax
movl %r15d, %edx
andl $0x1, %edx
leaq (%rdx,%rbp,2), %rbp
movq 0x58(%rsp), %rcx
andq %rcx, %rbp
movq %rbp, 0x70(%rsp)
addq %rdi, %rdi
shrl %r15d
orq %r15, %rdi
andq %rcx, %rdi
xorl $0x1, %edx
movq 0x60(%rsp), %rcx
shlq %cl, %rdx
movq %rdi, 0x78(%rsp)
shrq %rax
orq %rax, %rdx
movq %rdx, 0x50(%rsp)
movq %rdx, 0x80(%rsp)
movq %r13, %rax
movl %r11d, %r13d
subl %r15d, %r13d
shlq %cl, %r13
shrq %rax
orq %rax, %r13
movq %r13, 0x88(%rsp)
cmpq %r13, %rdi
jne 0xdbc12
movq %rdi, %r13
jmp 0xdbd6d
incl %ebx
cmpl 0x38(%rsp), %ebx
jl 0xdbd6d
cmpl $0xff, %r12d
jg 0xdbd6d
movq %rbx, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
xorl %ebx, %ebx
movq %rdi, 0x48(%rsp)
cmpq %r13, %rdi
setae %bl
shll $0x4, %ebx
movq 0x70(%rsp,%rbx), %rdi
callq 0xdbe90
movq %rax, %r15
movq 0x78(%rsp,%rbx), %rdi
callq 0xdbe90
movq %rax, %rbp
addq %r15, %rbp
movq 0x1d0(%rsp), %rdi
testq %rdi, %rdi
movl %r12d, 0x18(%rsp)
je 0xdbc81
movq %rbp, %rsi
callq 0xd5bc2
movl %eax, %r15d
jmp 0xdbc84
xorl %r15d, %r15d
movq 0x8(%rsp), %rsi
movq 0x1d8(%rsp), %r8
pushq $0x8
popq %rbx
xorl %r12d, %r12d
movq 0x28(%rsp), %r9
leaq 0x10fe5d(%rip), %r10    # 0x1ebb00
pushq $0x1
popq %r11
movq 0x48(%rsp), %rdi
movslq (%r8), %rax
cmpq %rax, %r12
jge 0xdbd5e
movq 0x8(%rsi), %rax
cmpq %rbp, -0x8(%rax,%rbx)
jne 0xdbd15
movq (%rax,%rbx), %rax
movl %eax, %ecx
andl $0xfffffff, %ecx        # imm = 0xFFFFFFF
cmpl %r15d, %ecx
jne 0xdbd15
movq %rax, %rcx
shrq $0x1c, %rcx
andl $0x7ffffff, %ecx        # imm = 0x7FFFFFF
cmpl %r14d, %ecx
jne 0xdbd15
cmpq %r13, %rdi
setae %cl
btq $0x37, %rax
setae %dl
cmpb %dl, %cl
je 0xdbd15
shrq $0x38, %rax
cmpl %eax, 0x18(%rsp)
jne 0xdbd15
movq 0x10(%r8), %rax
movq 0x20(%rsp), %rcx
cmpl (%rax,%r12,8), %ecx
jne 0xdbd1e
incl 0x14(%rsp)
incq %r12
addq $0x10, %rbx
jmp 0xdbcac
movq 0x1772bb(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x10f055(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x48(%rsp), %rdi
pushq $0x1
popq %r11
leaq 0x10fdb6(%rip), %r10    # 0x1ebb00
movq 0x28(%rsp), %r9
movq 0x1d8(%rsp), %r8
movq 0x8(%rsp), %rsi
jmp 0xdbd11
movq 0x30(%rsp), %rbp
movl 0x18(%rsp), %r12d
movq 0x20(%rsp), %rbx
incl %r14d
jmp 0xdba8d
movq (%r8), %rax
cmpl %eax, 0x14(%rsp)
movq 0x17725d(%rip), %r13    # 0x252fe0
jne 0xdbe20
movq 0x8(%rsp), %rdx
movl (%rdx), %ecx
cmpq %rcx, %rax
jne 0xdbe46
pushq $0x3
popq %rbx
movl $0x7ffffff, %ebp        # imm = 0x7FFFFFF
leaq 0x10efdc(%rip), %r12    # 0x1ead84
pushq $0x6
popq %r15
pushq $0x1
popq %r14
movslq (%r8), %rax
cmpq %rax, %r14
jge 0xdbe0e
movq 0x8(%rdx), %rax
movq -0x10(%rax,%rbx,8), %rcx
movq (%rax,%rbx,8), %rax
shrq $0x1c, %rax
andl %ebp, %eax
shrq $0x1c, %rcx
andl %ebp, %ecx
cmpl %ecx, %eax
jbe 0xdbded
movq 0x10(%r8), %rax
movl (%rax,%r14,8), %ecx
cmpl -0x8(%rax,%r14,8), %ecx
jle 0xdbded
incq %r14
addq $0x2, %rbx
jmp 0xdbdb0
movq (%r13), %rcx
movq %r12, %rdi
movq %r15, %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x1d8(%rsp), %r8
movq 0x8(%rsp), %rdx
jmp 0xdbde4
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r13), %rcx
leaq 0x10ef59(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x1d8(%rsp), %r8
movq (%r8), %rax
jmp 0xdbd89
movq (%r13), %rcx
leaq 0x10ef33(%rip), %rdi    # 0x1ead84
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
movq 0x1d8(%rsp), %r8
movq 0x8(%rsp), %rdx
jmp 0xdbd99