// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/hic.cpp
// Function: parallel_count_hc_pt1(pldat_t*)
void parallel_count_hc_pt1(pldat_t* pl)
{
    uint64_t i, l = 0, uID, num_pos = 0, pos_thre;
    uint64_t x[4], mask = (1ULL<<pl->h->k) - 1, shift = pl->h->k - 1, hash, pos, skip, bucket_mask = (1ULL<<pl->h->pre) - 1;
    ma_utg_t *u = NULL;
    ch_buf_t k_pos;
    if(pl->is_cnt) l = ((pl->buf_bytes>>3)/pl->h->tot) + 1, pos_thre = pl->buf_bytes>>3;
    if(!pl->is_cnt) l = ((pl->buf_bytes>>4)/pl->h->tot) + 1, pos_thre = pl->buf_bytes>>4;
    for (i = 0; i < pl->h->tot; i++)
    {
        if(pl->is_cnt)
        {
            kv_resize(uint64_t, pl->cnt[i].a, l);
            pl->cnt[i].a.n = 0;
        } 
        
        if(!pl->is_cnt)
        {
            kv_resize(ch_buf_t, pl->buf[i].a, l);
            pl->buf[i].a.n = 0;
        } 
    }
        
     
    for (uID = 0; uID < pl->h->ug->u.n; uID++)
    {
        u = &(pl->h->ug->u.a[uID]);
        if(u->m == 0) continue;

        for (i = l = 0, x[0] = x[1] = x[2] = x[3] = 0; i < u->len; ++i) {
        int c = seq_nt4_table[(uint8_t)u->s[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 >= pl->h->k)
            {
                hash = hc_hash_long(x, &skip, pl->h->k);
                if(skip == (uint64_t)-1) continue;
                if(pl->is_cnt)
                {
                    kv_push(uint64_t, pl->cnt[hash & bucket_mask].a, hash);
                }
                else
                {
                    pos = (skip << 63) | ((uID << (64-pl->h->uID_bits))>>1) | (i & pl->h->pos_mode);
                    k_pos.key = hash; k_pos.pos = pos;
                    kv_push(ch_buf_t, pl->buf[hash & bucket_mask].a, k_pos);
                }
                num_pos++;

                if(num_pos >= pos_thre)
                {
                    num_pos = 0;
                    kt_for(pl->n_thread, worker_for, pl, pl->h->tot);
                }
            }
                
        } else l = 0, x[0] = x[1] = x[2] = x[3] = 0; // if there is an "N", restart
    }
    }

    if(num_pos > 0) kt_for(pl->n_thread, worker_for, pl, pl->h->tot);

    for (i = 0; i < pl->h->tot; i++)
    {
        if(pl->cnt[i].a.m > 0) kv_destroy(pl->cnt[i].a), kv_init(pl->cnt[i].a);
        if(pl->buf[i].a.m > 0) kv_destroy(pl->buf[i].a), kv_init(pl->buf[i].a);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r8
movq 0x10(%rdi), %rsi
movq 0x40(%rsi), %rdi
movq $-0x1, %rax
movq $-0x1, %r9
movl %edi, %ecx
shlq %cl, %r9
movb 0x50(%rsi), %cl
shlq %cl, %rax
movq %rax, 0x28(%rsp)
movl (%r8), %ecx
testl %ecx, %ecx
je 0x135009
movq 0x8(%r8), %rax
shrq $0x3, %rax
movq %rax, 0x60(%rsp)
xorl %edx, %edx
divq 0x58(%rsi)
movq %rax, %r12
incq %r12
jmp 0x13500c
xorl %r12d, %r12d
movq %rdi, 0x10(%rsp)
testl %ecx, %ecx
jne 0x13502e
movq 0x8(%r8), %rax
shrq $0x4, %rax
movq %rax, 0x60(%rsp)
xorl %edx, %edx
divq 0x58(%rsi)
movq %rax, %r12
incq %r12
movq 0x10(%r8), %rax
cmpq $0x0, 0x58(%rax)
movq %r8, 0x8(%rsp)
je 0x13512f
leaq -0x1(%r12), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rbx
shrq $0x10, %rbx
orq %rax, %rbx
incq %rbx
xorl %r14d, %r14d
movq %rbx, %rax
shlq $0x4, %rax
movq %rax, 0x38(%rsp)
leaq (,%rbx,8), %rbp
xorl %r15d, %r15d
movq %r9, %r13
cmpl $0x0, (%r8)
je 0x1350d8
movq 0x18(%r8), %rax
cmpq %r12, 0x8(%rax,%r14)
jae 0x1350cc
movq %rbx, 0x8(%rax,%r14)
movq 0x10(%rax,%r14), %rdi
movq %rbp, %rsi
callq 0x2370
movq %r13, %r9
movq 0x8(%rsp), %r8
movq 0x18(%r8), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x18(%r8), %rax
movq $0x0, (%rax,%r14)
cmpl $0x0, (%r8)
jne 0x13511a
movq 0x20(%r8), %rax
cmpq %r12, 0x8(%rax,%r14)
jae 0x13510e
movq %rbx, 0x8(%rax,%r14)
movq 0x10(%rax,%r14), %rdi
movq 0x38(%rsp), %rsi
callq 0x2370
movq %r13, %r9
movq 0x8(%rsp), %r8
movq 0x20(%r8), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x20(%r8), %rax
movq $0x0, (%rax,%r14)
incq %r15
movq 0x10(%r8), %rax
addq $0x18, %r14
cmpq 0x58(%rax), %r15
jb 0x135098
movq 0x10(%r8), %rcx
movq (%rcx), %rax
cmpq $0x0, (%rax)
je 0x13556d
notq %r9
movq 0x10(%rsp), %r14
decq %r14
notq 0x28(%rsp)
xorl %edx, %edx
xorps %xmm0, %xmm0
leaq 0xf88b4(%rip), %rdi     # 0x22da10
movq $0x0, 0x20(%rsp)
movq %r14, 0x10(%rsp)
movq %r9, 0x38(%rsp)
movq 0x10(%rax), %rax
leaq (%rdx,%rdx,4), %rcx
cmpl $0x0, 0xc(%rax,%rcx,8)
movq %rdx, 0x68(%rsp)
je 0x13554a
leaq (%rax,%rcx,8), %r11
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
testl $0x7fffffff, (%r11)     # imm = 0x7FFFFFFF
je 0x13554a
xorl %r15d, %r15d
xorl %esi, %esi
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r11, 0x30(%rsp)
movq 0x20(%r11), %rax
movzbl (%rax,%r15), %eax
movzbl (%rdi,%rax), %eax
cmpq $0x3, %rax
ja 0x13527c
movq %r12, %rdx
movl %eax, %r12d
andl $0x1, %r12d
leaq (%r12,%rbp,2), %rbp
movq 0x38(%rsp), %rcx
andq %rcx, %rbp
movq %rbp, 0x40(%rsp)
addq %r13, %r13
shrl %eax
orq %rax, %r13
andq %rcx, %r13
movq %r13, 0x48(%rsp)
shrq %rdx
xorl $0x1, %r12d
movl %r14d, %ecx
shlq %cl, %r12
orq %rdx, %r12
movq %rbx, %rdx
movl $0x1, %ebx
subl %eax, %ebx
shlq %cl, %rbx
movq %r12, 0x50(%rsp)
shrq %rdx
orq %rdx, %rbx
movq %rbx, 0x58(%rsp)
incq %rsi
movq 0x10(%r8), %rax
movq 0x40(%rax), %rcx
cmpq %rcx, %rsi
jb 0x135536
cmpq %rbx, %r13
jne 0x13524a
movq $-0x1, %r10
cmpq %r12, %rbp
je 0x135251
setae %dl
movzbl %dl, %r10d
cmpq $-0x1, %r10
movq %rbp, 0x78(%rsp)
je 0x135297
cmpq $0x20, %rcx
ja 0x1352a3
movq %r10, %rcx
shlq $0x4, %rcx
movq 0x40(%rsp,%rcx), %rbp
shlq $0x20, %rbp
orq 0x48(%rsp,%rcx), %rbp
jmp 0x13533b
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %esi, %esi
jmp 0x135536
movq $-0x1, %rbp
jmp 0x13533b
movq %r10, %rcx
shlq $0x4, %rcx
movq 0x40(%rsp,%rcx), %rdx
movq 0x48(%rsp,%rcx), %rcx
movq %rsi, %rbp
movq %rdx, %rsi
notq %rsi
shlq $0x15, %rdx
addq %rsi, %rdx
movq %rdx, %rsi
shrq $0x18, %rsi
xorq %rdx, %rsi
imulq $0x109, %rsi, %rdx      # imm = 0x109
movq %rdx, %rsi
shrq $0xe, %rsi
xorq %rdx, %rsi
leaq (%rsi,%rsi,4), %rdx
leaq (%rsi,%rdx,4), %rdx
movq %rdx, %rsi
shrq $0x1c, %rsi
xorq %rdx, %rsi
movq %rcx, %rdx
notq %rdx
shlq $0x15, %rcx
addq %rdx, %rcx
movq %rcx, %rdx
shrq $0x18, %rdx
xorq %rcx, %rdx
imulq $0x109, %rdx, %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
addq %rsi, %rdx
movq %rbp, %rsi
movq %rdx, %rbp
shlq $0x1f, %rbp
addq %rdx, %rbp
cmpq $-0x1, %r10
je 0x1353eb
movq %rsi, 0x70(%rsp)
cmpl $0x0, (%r8)
je 0x1353f5
movq 0x18(%r8), %rax
movq %rbp, %rcx
andq 0x28(%rsp), %rcx
leaq (%rcx,%rcx,2), %r14
movq 0x8(%rax,%r14,8), %rdx
cmpq %rdx, (%rax,%r14,8)
jne 0x1353c8
leaq (%rax,%r14,8), %rdi
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rsi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, 0x18(%rsp)
movq %rsi, 0x8(%rax,%rcx)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x30(%rsp), %r11
leaq 0xf865e(%rip), %rdi     # 0x22da10
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r8
movq 0x18(%r8), %rcx
movq 0x18(%rsp), %rdx
movq %rax, 0x10(%rcx,%rdx)
movq 0x18(%r8), %rax
movq (%rax,%r14,8), %rcx
movq 0x10(%rax,%r14,8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax,%r14,8)
movq %rbp, (%rdx,%rcx,8)
movq 0x10(%rsp), %r14
jmp 0x1354e0
movq 0x78(%rsp), %rbp
jmp 0x135536
movq %r10, 0x90(%rsp)
movb 0x18(%rax), %dl
xorl %ecx, %ecx
subb %dl, %cl
movq 0x68(%rsp), %rsi
shlq %cl, %rsi
movq 0x30(%rax), %rax
andq %r15, %rax
movq %rax, 0x88(%rsp)
movq 0x20(%r8), %rax
movq %rbp, %rcx
andq 0x28(%rsp), %rcx
leaq (%rcx,%rcx,2), %r10
movq 0x8(%rax,%r10,8), %rdx
movq %r10, 0x18(%rsp)
cmpq %rdx, (%rax,%r10,8)
jne 0x1354a4
movq 0x18(%rsp), %rdi
leaq (%rax,%rdi,8), %rdi
movq %rsi, 0x80(%rsp)
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rsi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r14
movq %rsi, 0x8(%rax,%r14)
movq 0x8(%rdi), %rsi
movq 0x10(%rdi), %rdi
shlq $0x4, %rsi
callq 0x2370
movq 0x80(%rsp), %rsi
movq 0x30(%rsp), %r11
leaq 0xf8582(%rip), %rdi     # 0x22da10
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r8
movq 0x20(%r8), %rcx
movq %rax, 0x10(%rcx,%r14)
movq 0x10(%rsp), %r14
movq 0x90(%rsp), %r10
shldq $0x3f, %rsi, %r10
orq 0x88(%rsp), %r10
movq 0x20(%r8), %rax
movq 0x18(%rsp), %r9
movq (%rax,%r9,8), %rcx
movq 0x10(%rax,%r9,8), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rax,%r9,8)
shlq $0x4, %rcx
movq %rbp, (%rdx,%rcx)
movq %r10, 0x8(%rdx,%rcx)
movq 0x20(%rsp), %rcx
incq %rcx
movq %rcx, 0x20(%rsp)
cmpq 0x60(%rsp), %rcx
movq 0x78(%rsp), %rbp
jb 0x135531
movl 0x28(%r8), %edi
movq 0x10(%r8), %rax
movq 0x58(%rax), %rcx
leaq 0x114(%rip), %rsi       # 0x135620
movq %r8, %rdx
callq 0x1047b4
movq 0x30(%rsp), %r11
leaq 0xf84f0(%rip), %rdi     # 0x22da10
xorps %xmm0, %xmm0
movq 0x8(%rsp), %r8
movq $0x0, 0x20(%rsp)
movq 0x70(%rsp), %rsi
incq %r15
movl (%r11), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %r15
jb 0x1351b6
movq 0x68(%rsp), %rdx
incq %rdx
movq 0x10(%r8), %rcx
movq (%rcx), %rax
cmpq (%rax), %rdx
jb 0x13516f
cmpq $0x0, 0x20(%rsp)
sete %al
jmp 0x13556f
movb $0x1, %al
testb %al, %al
jne 0x13558f
movl 0x28(%r8), %edi
movq 0x58(%rcx), %rcx
leaq 0x9e(%rip), %rsi        # 0x135620
movq %r8, %rdx
callq 0x1047b4
movq 0x8(%rsp), %r8
movq 0x10(%r8), %rax
cmpq $0x0, 0x58(%rax)
je 0x13560e
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x18(%r8), %rax
cmpq $0x0, 0x8(%rax,%rbx)
je 0x1355ce
movq 0x10(%rax,%rbx), %rdi
callq 0x2220
movq 0x8(%rsp), %r8
movq 0x18(%r8), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rbx)
movq $0x0, 0x10(%rax,%rbx)
movq 0x20(%r8), %rax
cmpq $0x0, 0x8(%rax,%rbx)
je 0x1355fd
movq 0x10(%rax,%rbx), %rdi
callq 0x2220
movq 0x8(%rsp), %r8
movq 0x20(%r8), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%rbx)
movq $0x0, 0x10(%rax,%rbx)
incq %r14
movq 0x10(%r8), %rax
addq $0x18, %rbx
cmpq 0x58(%rax), %r14
jb 0x13559f
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq