// File: 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
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq %r9, -0x20(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
leaq -0x13c(%rbp), %rdi
xorl %esi, %esi
movl $0x108, %edx            # imm = 0x108
callq 0x2100
movl -0x14(%rbp), %eax
subl $0x1, %eax
cltq
movq %rax, -0x148(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x150(%rbp)
leaq -0x170(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x2100
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x193c1a
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1f6fd7(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movl %eax, -0x174(%rbp)
cmpl $0x4, -0x174(%rbp)
jge 0x193be8
cmpl $0x0, -0x18(%rbp)
je 0x19390f
movl $0x1, -0x17c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
cmpl -0xc(%rbp), %eax
jge 0x1938ce
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1f6f83(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
cmpl -0x174(%rbp), %eax
jne 0x1938ce
movl $0x2, -0x17c(%rbp)
movl -0x24(%rbp), %eax
addl -0x17c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x1938bf
movq -0x8(%rbp), %rax
movl -0x24(%rbp), %ecx
addl -0x17c(%rbp), %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1f6f42(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
cmpl -0x174(%rbp), %eax
je 0x1938ac
jmp 0x1938bf
jmp 0x1938ae
movl -0x17c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17c(%rbp)
jmp 0x193873
movl -0x17c(%rbp), %eax
subl $0x1, %eax
addl -0x24(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x17c(%rbp), %esi
leaq -0x13c(%rbp), %rdi
callq 0x193d30
movl -0x17c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x138(%rbp), %eax
cmpl -0x14(%rbp), %eax
jle 0x19390d
leaq -0x13c(%rbp), %rdi
callq 0x193d70
movl %eax, %ecx
movl -0x34(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x34(%rbp)
jmp 0x19393a
movl -0x28(%rbp), %eax
addl $0x1, %eax
cmpl -0x14(%rbp), %eax
jge 0x193928
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x190(%rbp)
jmp 0x193931
movl -0x14(%rbp), %eax
movl %eax, -0x190(%rbp)
movl -0x190(%rbp), %eax
movl %eax, -0x34(%rbp)
movq -0x170(%rbp), %rax
shlq %rax
movl -0x174(%rbp), %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x150(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rax
shlq %rax
movl -0x174(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x150(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x160(%rbp), %rax
shrq %rax
movl -0x174(%rbp), %edx
andl $0x1, %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movq -0x148(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x160(%rbp)
movq -0x158(%rbp), %rax
shrq %rax
movl -0x174(%rbp), %edx
sarl %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movq -0x148(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x158(%rbp)
movq -0x168(%rbp), %rax
cmpq -0x158(%rbp), %rax
jne 0x193a03
jmp 0x193c0c
movq -0x168(%rbp), %rdx
movq -0x158(%rbp), %rsi
movl $0x1, %eax
xorl %ecx, %ecx
cmpq %rsi, %rdx
cmovbl %ecx, %eax
movl %eax, -0x178(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x193be6
cmpl $0x100, -0x34(%rbp)     # imm = 0x100
jge 0x193be6
movl -0x178(%rbp), %eax
shll %eax
orl $0x0, %eax
cltq
movq -0x170(%rbp,%rax,8), %rdi
callq 0x193dd0
movq %rax, -0x198(%rbp)
movl -0x178(%rbp), %eax
shll %eax
orl $0x1, %eax
cltq
movq -0x170(%rbp,%rax,8), %rdi
callq 0x193dd0
movq %rax, %rcx
movq -0x198(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x193ab4
movq 0x10(%rbp), %rdi
movq -0x188(%rbp), %rsi
callq 0x188d00
movl %eax, -0x19c(%rbp)
jmp 0x193abe
xorl %eax, %eax
movl %eax, -0x19c(%rbp)
jmp 0x193abe
movl -0x19c(%rbp), %eax
movl %eax, -0x18c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl %ecx, %eax
jge 0x193be4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0x188(%rbp), %rax
jne 0x193bd4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
andq $0xfffffff, %rax        # imm = 0xFFFFFFF
cmpl -0x18c(%rbp), %eax
jne 0x193bd4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x1c, %rax
andq $0x7ffffff, %rax        # imm = 0x7FFFFFF
cmpl -0x24(%rbp), %eax
jne 0x193bd4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x37, %rax
andq $0x1, %rax
cmpl -0x178(%rbp), %eax
jne 0x193bd4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x38, %rax
cmpl -0x34(%rbp), %eax
jne 0x193bd4
movl -0x28(%rbp), %eax
movq 0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x2c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
je 0x193bcb
movq 0x230426(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1f5eeb(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x193bd6
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x193ad1
jmp 0x193be6
jmp 0x193c0a
movl $0x0, -0x28(%rbp)
movl $0x0, -0x13c(%rbp)
movl $0x0, -0x138(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x193c0c
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1937e8
movl -0x30(%rbp), %eax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl %ecx, %eax
je 0x193c40
movq 0x2303b1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1f5e76(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
je 0x193c6a
movq 0x230387(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1f5e4c(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
cmpl %ecx, %eax
jge 0x193d20
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x1c, %rax
andq $0x7ffffff, %rax        # imm = 0x7FFFFFF
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq 0x8(%rcx), %rcx
shrq $0x1c, %rcx
andq $0x7ffffff, %rcx        # imm = 0x7FFFFFF
cmpl %ecx, %eax
jle 0x193cf8
movq 0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jg 0x193d10
movq 0x2302e1(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1f5da6(%rip), %rsi    # 0x389aaf
movb $0x0, %al
callq 0x22a0
jmp 0x193d12
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x193c71
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopl (%rax)