// File: chhylp123[P]hifiasm/hic.cpp
// Function: test_hc_pt1(char*, unsigned long, unsigned long, ha_ug_index*)
void test_hc_pt1(char* seq, uint64_t len, uint64_t uID, ha_ug_index* idx)
{
    uint64_t i, l, k, pos, *pos_list = NULL, cnt;
    uint64_t x[4], mask = (1ULL<<idx->k) - 1, shift = idx->k - 1, hash, skip;
    for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < len; ++i) {
        int c = seq_nt4_table[(uint8_t)seq[i]];
        ///c = 00, 01, 10, 11
        if (c < 4) { // not an "N" base
            ///x[0] & x[1] are the forward k-mer
            ///x[2] & x[3] are the reverse complementary k-mer
            x[0] = (x[0] << 1 | (c&1))  & mask;
            x[1] = (x[1] << 1 | (c>>1)) & mask;
            x[2] = x[2] >> 1 | (uint64_t)(1 - (c&1))  << shift;
            x[3] = x[3] >> 1 | (uint64_t)(1 - (c>>1)) << shift;
            if (++l >= idx->k)
            {
                hash = hc_hash_long(x, &skip, idx->k);
                if(skip == (uint64_t)-1) continue;
                pos = (skip << 63) | ((uID << (64-idx->uID_bits))>>1) | (i & idx->pos_mode);
                cnt = get_hc_pt1_count(idx, hash, &pos_list);
                if(cnt == 0) fprintf(stderr, "ERROR cnt, uID: %lu\n", uID);
                for (k = 0; k < cnt; k++)
                {
                    if(pos_list[k]==pos)
                    {
                        pos_list[k] = (uint64_t)-1;
                        break;
                    }
                }
                if(k == cnt) fprintf(stderr, "ERROR k\n");
                
            }
        } else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rcx
movl $0x1, %eax
shlq %cl, %rax
subq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
subq $0x1, %rax
movq %rax, -0x80(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x1bf95a
movq -0x8(%rbp), %rax
movq -0x28(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x1cb092(%rip), %rax    # 0x38a7e0
movzbl (%rax,%rcx), %eax
movl %eax, -0x94(%rbp)
cmpl $0x4, -0x94(%rbp)
jge 0x1bf91f
movq -0x70(%rbp), %rax
shlq %rax
movl -0x94(%rbp), %ecx
andl $0x1, %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x78(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rax
shlq %rax
movl -0x94(%rbp), %ecx
sarl %ecx
movslq %ecx, %rcx
orq %rcx, %rax
andq -0x78(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
shrq %rax
movl -0x94(%rbp), %edx
andl $0x1, %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movq -0x80(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
shrq %rax
movl -0x94(%rbp), %edx
sarl %edx
movl $0x1, %ecx
subl %edx, %ecx
movslq %ecx, %rdx
movq -0x80(%rbp), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jb 0x1bf91d
leaq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rdx
leaq -0x90(%rbp), %rsi
callq 0x212f90
movq %rax, -0x88(%rbp)
cmpq $-0x1, -0x90(%rbp)
jne 0x1bf83d
jmp 0x1bf949
movq -0x90(%rbp), %rax
shlq $0x3f, %rax
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rsi
movl $0x40, %ecx
subq 0x18(%rsi), %rcx
shlq %cl, %rdx
movq %rdx, %rcx
shrq %rcx
orq %rcx, %rax
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rdx
andq 0x30(%rdx), %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x88(%rbp), %rsi
leaq -0x48(%rbp), %rdx
callq 0x213060
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x1bf8b3
movq 0x204742(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
leaq 0x1cc614(%rip), %rsi    # 0x38bec0
movb $0x0, %al
callq 0x22a0
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1bf8f9
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
jne 0x1bf8e9
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movq $-0x1, (%rax,%rcx,8)
jmp 0x1bf8f9
jmp 0x1bf8eb
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x1bf8bb
movq -0x38(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x1bf91b
movq 0x2046d6(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x1cc5c1(%rip), %rsi    # 0x38bed5
movb $0x0, %al
callq 0x22a0
jmp 0x1bf91d
jmp 0x1bf947
movq $0x0, -0x30(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
jmp 0x1bf949
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1bf72b
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)