// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/hic.cpp
// Function: worker_for(void*, long, int)
static void worker_for(void *data, long i, int tid) // callback for kt_for()
{
	pldat_t *pl = (pldat_t*)data;
    hc_pt1_t *h = &(pl->h->idx_buf[i]);
    uint64_t m = 0, beg, end, occ;
    khint_t key;
    int absent;
    
    
    if(pl->is_cnt)
    {
        uint64_t* cnt = NULL;
        if(pl->cnt[i].a.n > 2) radix_sort_b64(pl->cnt[i].a.a, pl->cnt[i].a.a + pl->cnt[i].a.n);
        cnt = pl->cnt[i].a.a;
        occ = pl->cnt[i].a.n;
        for (m = beg = end = 0; m < occ; m++)
        {
            if(cnt[beg] == cnt[m])
            {
                end = m;
            }
            else
            {
                key = hc_pt_put(h->h, cnt[beg], &absent);
                if(absent) kh_val(h->h, key) = 0;
                kh_val(h->h, key) += (end - beg + 1);
                kh_key(h->h, key) = (kh_key(h->h, key)&HIC_KEY_MODE)|
                        (kh_val(h->h, key)<HIC_MAX_COUNT?kh_val(h->h, key):HIC_MAX_COUNT);
                beg = end = m;
            }
        }
        if(occ > 0)
        {
            key = hc_pt_put(h->h, cnt[beg], &absent);
            if(absent) kh_val(h->h, key) = 0;
            kh_val(h->h, key) += (end - beg + 1);
            kh_key(h->h, key) = (kh_key(h->h, key)&HIC_KEY_MODE)|
                        (kh_val(h->h, key)<HIC_MAX_COUNT?kh_val(h->h, key):HIC_MAX_COUNT);
        }
        pl->cnt[i].a.n = 0;
    } 
    
    if(!pl->is_cnt) 
    {
        ch_buf_t* pos = NULL;
        uint64_t num, *pos_list = NULL, k, k_n, pos_k;
        if(pl->buf[i].a.n > 2) radix_sort_ch_buf(pl->buf[i].a.a, pl->buf[i].a.a + pl->buf[i].a.n);
        pos = pl->buf[i].a.a;
        occ = pl->buf[i].a.n;
        for (m = beg = end = 0; m < occ; m++)
        {
            if(pos[beg].key == pos[m].key)
            {
                end = m;
            }
            else
            {
                num = get_hc_pt1_count(pl->h, pos[beg].key, &pos_list);
                if(num > 0)
                {
                    k_n=(end-beg+1);pos_k=pos_list[num-1];pos_list[num-1]+=k_n;
                    for (k = 0; k < k_n; k++)
                    {
                        pos_list[pos_k+k] = pos[beg+k].pos;
                    }
                }
                
                beg = end = m;
            }
            
        }
        if(occ > 0)
        {
            num = get_hc_pt1_count(pl->h, pos[beg].key, &pos_list);
            if(num > 0)
            {
                k_n=(end-beg+1);pos_k=pos_list[num-1];pos_list[num-1]+=k_n;
                for (k = 0; k < k_n; k++)
                {
                    pos_list[pos_k+k] = pos[beg+k].pos;
                }
            }
        }
        pl->buf[i].a.n = 0;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
cmpl $0x0, (%rdi)
movq %rdi, 0x20(%rsp)
je 0xf4ccf
movq 0x10(%rbx), %rax
movq %rsi, %r13
shlq $0x5, %r13
addq 0x78(%rax), %r13
movq 0x18(%rbx), %rax
imulq $0x18, %rsi, %r14
movq (%rax,%r14), %rbp
cmpq $0x3, %rbp
movq %rsi, 0x18(%rsp)
jb 0xf4ba9
addq %r14, %rax
movq 0x10(%rax), %rdi
leaq (%rdi,%rbp,8), %rsi
callq 0xf2735
movq 0x18(%rbx), %rax
movq (%rax,%r14), %rbp
movq %r14, 0x10(%rsp)
movq 0x10(%rax,%r14), %r12
xorl %eax, %eax
xorl %r14d, %r14d
xorl %r15d, %r15d
cmpq %rax, %rbp
je 0xf4c45
movq %rax, %rbx
movq (%r12,%r14,8), %rsi
cmpq (%r12,%rax,8), %rsi
je 0xf4c39
movq (%r13), %rdi
leaq 0x4(%rsp), %rdx
callq 0x1203a4
movl %eax, %eax
shlq $0x4, %rax
cmpl $0x0, 0x4(%rsp)
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
leaq 0x8(%rcx,%rax), %rdx
je 0xf4c01
andq $0x0, (%rdx)
xorl %edx, %edx
jmp 0xf4c04
movq (%rdx), %rdx
subq %r14, %r15
addq %r15, %rdx
incq %rdx
movq %rdx, 0x8(%rcx,%rax)
movq (%rcx,%rax), %rsi
movq $-0x1000, %rdi          # imm = 0xF000
andq %rdi, %rsi
movl $0xfff, %edi            # imm = 0xFFF
cmpq %rdi, %rdx
jb 0xf4c2f
movl $0xfff, %edx            # imm = 0xFFF
orq %rsi, %rdx
movq %rdx, (%rcx,%rax)
movq %rbx, %r14
leaq 0x1(%rbx), %rax
movq %rbx, %r15
jmp 0xf4bbb
testq %rbp, %rbp
je 0xf4cae
movq (%r13), %rdi
movq (%r12,%r14,8), %rsi
leaq 0x4(%rsp), %rbx
movq %rbx, %rdx
callq 0x1203a4
movl %eax, %eax
shlq $0x4, %rax
cmpl $0x0, (%rbx)
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
leaq 0x8(%rcx,%rax), %rdx
je 0xf4c7f
andq $0x0, (%rdx)
xorl %edx, %edx
jmp 0xf4c82
movq (%rdx), %rdx
subq %r14, %r15
addq %r15, %rdx
incq %rdx
movq %rdx, 0x8(%rcx,%rax)
movq $-0x1000, %rsi          # imm = 0xF000
andq (%rcx,%rax), %rsi
movl $0xfff, %edi            # imm = 0xFFF
cmpq %rdi, %rdx
cmovbq %rdx, %rdi
orq %rsi, %rdi
movq %rdi, (%rcx,%rax)
movq 0x20(%rsp), %rbx
movq 0x18(%rbx), %rax
movq 0x10(%rsp), %rcx
andq $0x0, (%rax,%rcx)
cmpl $0x0, (%rbx)
movq 0x18(%rsp), %rsi
jne 0xf4e27
andq $0x0, 0x8(%rsp)
movq 0x20(%rbx), %rax
imulq $0x18, %rsi, %r15
movq (%rax,%r15), %r14
cmpq $0x3, %r14
jb 0xf4d05
addq %r15, %rax
movq 0x10(%rax), %rdi
shlq $0x4, %r14
addq %rdi, %r14
movq %r14, %rsi
callq 0xf2948
movq 0x20(%rbx), %rax
movq (%rax,%r15), %r14
movq %r15, 0x10(%rsp)
movq 0x10(%rax,%r15), %rbp
leaq 0x8(%rbp), %rax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpq %r14, %rax
je 0xf4db1
movq %rax, %r12
movq %rbx, %r15
shlq $0x4, %r15
movq (%rbp,%r15), %rsi
shlq $0x4, %rax
cmpq (%rbp,%rax), %rsi
jne 0xf4d47
movq %rbx, %rcx
jmp 0xf4da1
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
leaq 0x8(%rsp), %rdx
callq 0x120ad7
movq %r12, %rcx
testq %rax, %rax
je 0xf4da1
subq %rbx, %r13
movq 0x8(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rdx
leaq (%rdx,%r13), %rsi
incq %rsi
incq %r13
movq %rsi, -0x8(%rcx,%rax,8)
leaq (%rcx,%rdx,8), %rax
addq 0x18(%rsp), %r15
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0xf4d9e
movq (%r15), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
addq $0x10, %r15
jmp 0xf4d89
movq %r12, %rcx
leaq 0x1(%r12), %rax
movq %rcx, %rbx
movq %r12, %r13
jmp 0xf4d1f
testq %r14, %r14
movq 0x20(%rsp), %r15
je 0xf4e19
movq 0x10(%r15), %rdi
movq %rbx, %r14
shlq $0x4, %r14
movq (%rbp,%r14), %rsi
leaq 0x8(%rsp), %rdx
callq 0x120ad7
testq %rax, %rax
je 0xf4e19
subq %rbx, %r13
movq 0x8(%rsp), %rcx
movq -0x8(%rcx,%rax,8), %rdx
leaq (%rdx,%r13), %rsi
incq %rsi
incq %r13
movq %rsi, -0x8(%rcx,%rax,8)
leaq (%rcx,%rdx,8), %rax
leaq (%r14,%rbp), %rcx
addq $0x8, %rcx
xorl %edx, %edx
cmpq %rdx, %r13
je 0xf4e19
movq (%rcx), %rsi
movq %rsi, (%rax,%rdx,8)
incq %rdx
addq $0x10, %rcx
jmp 0xf4e04
movq 0x20(%r15), %rax
movq 0x10(%rsp), %rcx
andq $0x0, (%rax,%rcx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq