// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %r15
movq %rdx, 0x40(%rsp)
leaq 0x48(%rsp), %rax
andq $0x0, (%rax)
movq %rsi, %r14
movq %rdi, %rbp
movq 0x40(%rcx), %rcx
pushq $-0x1
popq %r8
shlq %cl, %r8
notq %r8
decq %rcx
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
leaq 0xf7fd7(%rip), %r9      # 0x1ebb00
pushq $0x1
popq %r10
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %r15, 0x38(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movq %rcx, 0x8(%rsp)
movq %r8, (%rsp)
cmpq %r14, %rbx
je 0xf3cbd
movzbl (%rbp,%rbx), %eax
movzbl (%r9,%rax), %eax
cmpq $0x3, %rax
ja 0xf3c45
movl %eax, %edx
andl $0x1, %edx
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
leaq (%rdx,%rdi,2), %rdi
andq %r8, %rdi
movq %rdi, 0x10(%rsp)
addq %rsi, %rsi
shrl %eax
movq %rax, %rdi
orq %rsi, %rdi
andq %r8, %rdi
movq %rdi, 0x18(%rsp)
movq 0x20(%rsp), %rsi
xorl $0x1, %edx
shlq %cl, %rdx
shrq %rsi
orq %rsi, %rdx
movq %rdx, 0x20(%rsp)
movq 0x28(%rsp), %rdx
shrq %rdx
movl %r10d, %esi
subl %eax, %esi
shlq %cl, %rsi
orq %rdx, %rsi
movq %rsi, 0x28(%rsp)
incq %r13
movq 0x40(%r15), %rdx
cmpq %rdx, %r13
jb 0xf3c75
leaq 0x10(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x120a71
movq 0x60(%rsp), %r12
cmpq $-0x1, %r12
je 0xf3c5e
movb 0x18(%r15), %dl
xorl %ecx, %ecx
subb %dl, %cl
movq 0x40(%rsp), %rbp
shlq %cl, %rbp
movq 0x30(%r15), %r14
andq %rbx, %r14
movq %r15, %rdi
movq %rax, %rsi
leaq 0x48(%rsp), %rdx
callq 0x120ad7
movq %rax, %r15
testq %rax, %rax
je 0xf3c9b
shldq $0x3f, %rbp, %r12
orq %r14, %r12
movq 0x48(%rsp), %rax
xorl %ecx, %ecx
movq 0x58(%rsp), %r14
movq 0x50(%rsp), %rbp
cmpq %rcx, %r15
je 0xf3c7d
cmpq %r12, (%rax,%rcx,8)
je 0xf3c54
incq %rcx
jmp 0xf3c35
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
xorl %r13d, %r13d
jmp 0xf3c75
orq $-0x1, (%rax,%rcx,8)
movq 0x38(%rsp), %r15
movq 0x8(%rsp), %rcx
movq (%rsp), %r8
xorps %xmm0, %xmm0
leaq 0xf7e8f(%rip), %r9      # 0x1ebb00
pushq $0x1
popq %r10
incq %rbx
jmp 0xf3b4a
movq 0x15f35c(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0xf951a(%rip), %rdi     # 0x1ed1a8
pushq $0x8
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xf3c59
movq 0x15f33e(%rip), %rax    # 0x252fe0
movq (%rax), %rdi
leaq 0xf94e7(%rip), %rsi     # 0x1ed193
movq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x22b0
jmp 0xf3c1c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq