// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq 0x40(%rcx), %rcx
movq $-0x1, %r13
shlq %cl, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
testq %rsi, %rsi
je 0x13470f
movq %rdx, %rbp
notq %r13
decq %rcx
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %rbx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq %r13, 0x40(%rsp)
movzbl (%rdi,%r14), %eax
leaq 0xf963b(%rip), %rdx     # 0x22da10
movzbl (%rdx,%rax), %eax
cmpq $0x3, %rax
ja 0x13448d
movl %eax, %edx
andl $0x1, %edx
movq (%rsp), %r9
movq 0x8(%rsp), %r8
leaq (%rdx,%r9,2), %r10
andq %r13, %r10
movq %r10, (%rsp)
addq %r8, %r8
shrl %eax
movq %rax, %r11
orq %r8, %r11
andq %r13, %r11
movq %r11, 0x8(%rsp)
movq 0x10(%rsp), %r8
xorl $0x1, %edx
shlq %cl, %rdx
shrq %r8
orq %r8, %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rsp), %r9
shrq %r9
movl $0x1, %r8d
subl %eax, %r8d
shlq %cl, %r8
orq %r9, %r8
movq %r8, 0x18(%rsp)
incq %r12
movq 0x40(%rbx), %r9
cmpq %r9, %r12
jb 0x1346d5
cmpq %r8, %r11
jne 0x134462
movq $-0x1, %rax
cmpq %rdx, %r10
je 0x134468
setae %al
movzbl %al, %eax
cmpq $-0x1, %rax
je 0x13449e
cmpq $0x20, %r9
ja 0x1344aa
movq %rax, %rdx
shlq $0x4, %rdx
movq (%rsp,%rdx), %r10
shlq $0x20, %r10
orq 0x8(%rsp,%rdx), %r10
jmp 0x13453b
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
xorl %r12d, %r12d
jmp 0x1346d5
movq $-0x1, %r10
jmp 0x13453b
movq %rax, %r8
shlq $0x4, %r8
movq (%rsp,%r8), %rdx
movq 0x8(%rsp,%r8), %r9
movq %rdx, %r8
notq %r8
shlq $0x15, %rdx
addq %r8, %rdx
movq %rdx, %r8
shrq $0x18, %r8
xorq %rdx, %r8
imulq $0x109, %r8, %rdx       # imm = 0x109
movq %rdx, %r8
shrq $0xe, %r8
xorq %rdx, %r8
leaq (%r8,%r8,4), %rdx
leaq (%r8,%rdx,4), %rdx
movq %rdx, %r8
shrq $0x1c, %r8
xorq %rdx, %r8
movq %r9, %rdx
notq %rdx
shlq $0x15, %r9
addq %rdx, %r9
movq %r9, %rdx
shrq $0x18, %rdx
xorq %r9, %rdx
imulq $0x109, %rdx, %r9       # imm = 0x109
movq %r9, %rdx
shrq $0xe, %rdx
xorq %r9, %rdx
leaq (%rdx,%rdx,4), %r9
leaq (%rdx,%r9,4), %r9
movq %r9, %rdx
shrq $0x1c, %rdx
xorq %r9, %rdx
addq %r8, %rdx
movq %rdx, %r10
shlq $0x1f, %r10
addq %rdx, %r10
cmpq $-0x1, %rax
je 0x1346d5
movb 0x18(%rbx), %dl
xorl %ecx, %ecx
subb %dl, %cl
movq %rbp, %rsi
shlq %cl, %rsi
xorl %r13d, %r13d
movb 0x50(%rbx), %cl
movq $-0x1, %r11
shlq %cl, %r11
notq %r11
movq 0x78(%rbx), %rcx
andq %r10, %r11
shlq $0x5, %r11
movq %rcx, 0x60(%rsp)
movq (%rcx,%r11), %r8
movq 0x10(%r8), %rdi
movl $0x0, %r9d
testq %rdi, %rdi
je 0x1345f3
movq %rsi, 0x38(%rsp)
movb (%r8), %cl
movl $0x1, %r9d
shll %cl, %r9d
movq %r10, %rdx
shrq $0xc, %rdx
imull $0x9e3779b9, %edx, %ebx # imm = 0x9E3779B9
negb %cl
shrl %cl, %ebx
leal -0x1(%r9), %ecx
movq 0x8(%r8), %rdx
movl %ebx, %ebp
movl %ebp, %esi
shrl $0x5, %esi
movl (%rdx,%rsi,4), %esi
btl %ebp, %esi
jae 0x1345e4
movl %ebp, %esi
shlq $0x4, %rsi
movq (%rdi,%rsi), %rsi
xorq %r10, %rsi
cmpq $0x1000, %rsi           # imm = 0x1000
jb 0x1345e1
incl %ebp
andl %ecx, %ebp
cmpl %ebx, %ebp
jne 0x1345b4
jmp 0x1345e4
movl %ebp, %r9d
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %rbp
movq 0x38(%rsp), %rsi
testq %rdi, %rdi
je 0x134604
movb (%r8), %cl
movl $0x1, %r13d
shll %cl, %r13d
cmpl %r13d, %r9d
jne 0x13460e
xorl %r13d, %r13d
jmp 0x13468b
movq 0x60(%rsp), %rcx
addq %r11, %rcx
movq %rcx, %r11
movl %r9d, %ecx
shlq $0x4, %rcx
movq 0x8(%rdi,%rcx), %r10
leaq (,%r10,8), %r15
addq 0x10(%r11), %r15
movq (%rdi,%rcx), %r13
movl $0xfff, %ecx            # imm = 0xFFF
andq %rcx, %r13
cmpq %rcx, %r13
jne 0x13468b
cmpl 0x18(%r11), %r9d
jne 0x13464e
movq 0x8(%r11), %r13
jmp 0x134688
testq %rdi, %rdi
je 0x13465f
movb (%r8), %cl
movl $0x1, %edx
shll %cl, %edx
jmp 0x134661
xorl %edx, %edx
incl %r9d
cmpl %edx, %r9d
je 0x134648
movq 0x8(%r8), %rcx
movl %r9d, %edx
shrl $0x5, %edx
movl (%rcx,%rdx,4), %ecx
btl %r9d, %ecx
jae 0x13464e
movl %r9d, %ecx
shlq $0x4, %rcx
movq 0x8(%rdi,%rcx), %r13
subq %r10, %r13
testq %r13, %r13
je 0x1346e3
shldq $0x3f, %rsi, %rax
movq 0x30(%rbx), %rcx
andq %r14, %rcx
orq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, (%r15,%rax,8)
je 0x1346b4
incq %rax
cmpq %rax, %r13
jne 0x1346a1
movq %r13, %rax
jmp 0x1346bc
movq $-0x1, (%r15,%rax,8)
cmpq %r13, %rax
je 0x134705
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rcx
movq 0x40(%rsp), %r13
incq %r14
cmpq %rsi, %r14
jne 0x1343c9
jmp 0x13470f
movq 0x1558f6(%rip), %rax    # 0x289fe0
movq (%rax), %rdi
leaq 0xfa95f(%rip), %rsi     # 0x22f053
movq %rbp, %rdx
xorl %eax, %eax
callq 0x22b0
xorps %xmm0, %xmm0
xorl %eax, %eax
jmp 0x1346bc
callq 0x1c7db
xorps %xmm0, %xmm0
jmp 0x1346c1
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq