// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %rcx, %r9
movq %rdx, 0x30(%rsp)
movq 0x40(%rcx), %rcx
movq $-0x1, %r10
shlq %cl, %r10
testq %rsi, %rsi
je 0x13a84d
notq %r10
decq %rcx
leaq 0xff6e0(%rip), %r11     # 0x239c20
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %r10, 0x10(%rsp)
movq %r9, (%rsp)
movzbl (%rdi,%r12), %eax
movzbl (%r11,%rax), %eax
cmpq $0x3, %rax
ja 0x13a5db
movq %r15, %rdx
movl %eax, %r15d
andl $0x1, %r15d
leaq (%r15,%rbp,2), %rbp
andq %r10, %rbp
addq %r13, %r13
shrl %eax
orq %rax, %r13
xorl $0x1, %r15d
shlq %cl, %r15
andq %r10, %r13
shrq %rdx
orq %rdx, %r15
movq %r14, %rdx
shrq %rdx
movl $0x1, %r14d
subl %eax, %r14d
shlq %cl, %r14
orq %rdx, %r14
incq %rbx
movq 0x40(%r9), %r8
cmpq %r8, %rbx
jb 0x13a841
cmpq %r14, %r13
jne 0x13a5ed
cmpq %r15, %rbp
jne 0x13a5ed
movq %r13, %r14
movq %rbp, %r15
jmp 0x13a841
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %ebx, %ebx
jmp 0x13a841
setae %al
movzbl %al, %eax
testb %al, %al
movq %rbp, %rdx
cmovneq %r15, %rdx
cmpq $0x20, %r8
movq %rbp, 0x40(%rsp)
movq %rbx, 0x38(%rsp)
ja 0x13a622
shlq $0x20, %rdx
testq %rax, %rax
movq %r13, %rdi
cmovneq %r14, %rdi
orq %rdx, %rdi
jmp 0x13a6ad
movq %rdx, %rcx
notq %rcx
shlq $0x15, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x18, %rcx
xorq %rdx, %rcx
imulq $0x109, %rcx, %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
testq %rax, %rax
movq %r13, %rcx
cmovneq %r14, %rcx
movq %rcx, %rsi
notq %rsi
shlq $0x15, %rcx
addq %rsi, %rcx
movq %rcx, %rsi
shrq $0x18, %rsi
xorq %rcx, %rsi
imulq $0x109, %rsi, %rcx      # imm = 0x109
movq %rcx, %rsi
shrq $0xe, %rsi
xorq %rcx, %rsi
leaq (%rsi,%rsi,4), %rcx
leaq (%rsi,%rcx,4), %rcx
movq %rcx, %rsi
shrq $0x1c, %rsi
xorq %rcx, %rsi
addq %rdx, %rsi
movq %rsi, %rdi
shlq $0x1f, %rdi
addq %rsi, %rdi
movb 0x18(%r9), %dl
xorl %ecx, %ecx
subb %dl, %cl
movq 0x30(%rsp), %rdx
shlq %cl, %rdx
movb 0x50(%r9), %cl
movq $-0x1, %r8
shlq %cl, %r8
notq %r8
movq 0x78(%r9), %rcx
andq %rdi, %r8
shlq $0x5, %r8
movq %rcx, 0x8(%rsp)
movq (%rcx,%r8), %r9
movq 0x10(%r9), %rsi
testq %rsi, %rsi
je 0x13a7f6
shrdq $0x1, %rax, %rdx
movq (%rsp), %rax
movq 0x30(%rax), %rax
andq %r12, %rax
orq %rdx, %rax
movb (%r9), %cl
movl $0x1, %ebp
shll %cl, %ebp
movq %rdi, %rdx
shrq $0xc, %rdx
imull $0x9e3779b9, %edx, %edx # imm = 0x9E3779B9
negb %cl
shrl %cl, %edx
addq %r8, 0x8(%rsp)
leal -0x1(%rbp), %r8d
movq 0x8(%r9), %r10
movl %edx, %r9d
movl %r9d, %ecx
shrl $0x5, %ecx
movl (%r10,%rcx,4), %ecx
btl %r9d, %ecx
jae 0x13a7f6
movl %r9d, %ecx
shlq $0x4, %rcx
movq (%rsi,%rcx), %rbx
movq %rbx, %r11
xorq %rdi, %r11
cmpq $0x1000, %r11           # imm = 0x1000
jb 0x13a76b
incl %r9d
andl %r8d, %r9d
cmpl %edx, %r9d
jne 0x13a72d
jmp 0x13a7f6
cmpl %ebp, %r9d
je 0x13a7f6
movq 0x8(%rsi,%rcx), %rcx
movl $0xfff, %edx            # imm = 0xFFF
andq %rdx, %rbx
cmpq %rdx, %rbx
jne 0x13a7be
movq 0x8(%rsp), %rdi
cmpl 0x18(%rdi), %r9d
jne 0x13a797
movq 0x8(%rdi), %rbx
jmp 0x13a7bb
cmpl %r9d, %r8d
je 0x13a791
incl %r9d
movl %r9d, %edx
shrl $0x5, %edx
movl (%r10,%rdx,4), %edx
btl %r9d, %edx
jae 0x13a797
movl %r9d, %edx
shlq $0x4, %rdx
movq 0x8(%rsi,%rdx), %rbx
subq %rcx, %rbx
testq %rbx, %rbx
je 0x13a7f6
shlq $0x3, %rcx
movq 0x8(%rsp), %rdx
addq 0x10(%rdx), %rcx
xorl %edx, %edx
movq 0x40(%rsp), %rbp
cmpq %rax, (%rcx,%rdx,8)
je 0x13a7e7
incq %rdx
cmpq %rdx, %rbx
jne 0x13a7d7
jmp 0x13a818
movq $-0x1, (%rcx,%rdx,8)
cmpq %rdx, %rbx
jne 0x13a81d
jmp 0x13a818
movq 0x15a7e3(%rip), %rax    # 0x294fe0
movq (%rax), %rdi
leaq 0x100a9c(%rip), %rsi    # 0x23b2a3
movq 0x30(%rsp), %rdx
xorl %eax, %eax
callq 0x22b0
movq 0x40(%rsp), %rbp
callq 0x1c0fe
movq (%rsp), %r9
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %r10
leaq 0xff3e4(%rip), %r11     # 0x239c20
movq 0x38(%rsp), %rbx
incq %r12
cmpq %rsi, %r12
jne 0x13a568
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq