// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, (%rdi)
je 0x1357df
movq 0x10(%r14), %rax
movq %rbx, %r13
shlq $0x5, %r13
addq 0x78(%rax), %r13
movq 0x18(%r14), %rcx
leaq (%rbx,%rbx,2), %r15
movq (%rcx,%r15,8), %rax
cmpq $0x3, %rax
jb 0x13566f
leaq (%rcx,%r15,8), %rcx
movq 0x10(%rcx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x132eff
movq %rbx, 0x8(%rsp)
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rcx
movq %r15, 0x18(%rsp)
movq 0x10(%rax,%r15,8), %rbp
testq %rcx, %rcx
je 0x13574d
movq %r14, (%rsp)
xorl %r12d, %r12d
xorl %r14d, %r14d
xorl %eax, %eax
xorl %r15d, %r15d
movq (%rbp,%rax,8), %rsi
cmpq (%rbp,%r15,8), %rsi
je 0x135722
movq %rcx, %rbx
movq (%r13), %rdi
leaq 0x24(%rsp), %rdx
callq 0x15eb65
cmpl $0x0, 0x24(%rsp)
movl %eax, %eax
je 0x1356dc
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movq $0x0, 0x8(%rcx,%rdx)
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rdx
addq %r14, %r12
addq %r12, %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
cmovaeq %rdi, %rdx
orq %rsi, %rdx
movq %rdx, (%rcx,%rax)
movq %r15, %rax
movq %rbx, %rcx
leaq 0x1(%r15), %rbx
movq %rax, %r12
negq %r12
movq %r15, %r14
movq %rbx, %r15
cmpq %rbx, %rcx
jne 0x13569e
movl $0x1, %r12d
subq %rax, %r12
decq %rbx
movq (%rsp), %r14
jmp 0x135757
movl $0x1, %r12d
xorl %eax, %eax
xorl %ebx, %ebx
testq %rcx, %rcx
je 0x1357c9
movq (%r13), %rdi
movq (%rbp,%rax,8), %rsi
leaq 0x24(%rsp), %r15
movq %r15, %rdx
callq 0x15eb65
cmpl $0x0, (%r15)
movl %eax, %eax
je 0x135792
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movq $0x0, 0x8(%rcx,%rdx)
movq (%r13), %rcx
movq 0x10(%rcx), %rcx
shlq $0x4, %rax
addq %rbx, %r12
addq 0x8(%rcx,%rax), %r12
movq %r12, 0x8(%rcx,%rax)
movq $-0x1000, %rdx          # imm = 0xF000
andq (%rcx,%rax), %rdx
movl $0xfff, %esi            # imm = 0xFFF
cmpq %rsi, %r12
cmovaeq %rsi, %r12
orq %rdx, %r12
movq %r12, (%rcx,%rax)
movq 0x18(%r14), %rax
movq 0x18(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movq 0x8(%rsp), %rbx
cmpl $0x0, (%r14)
jne 0x135bc0
movq 0x20(%r14), %rax
leaq (%rbx,%rbx,2), %rbx
movq (%rax,%rbx,8), %rsi
cmpq $0x3, %rsi
jb 0x13580f
leaq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x13315a
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rcx
movq %rbx, 0x38(%rsp)
movq %rax, 0x30(%rsp)
movq 0x10(%rax,%rbx,8), %rdi
testq %rcx, %rcx
movq %rdi, 0x10(%rsp)
je 0x135a02
leaq 0x8(%rdi), %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
xorl %esi, %esi
xorl %eax, %eax
xorl %r8d, %r8d
movq %r14, (%rsp)
movq %rcx, 0x28(%rsp)
movq %rax, %rdx
movq %rsi, %r12
shlq $0x4, %r12
movq (%rdi,%r12), %r11
shlq $0x4, %rax
cmpq (%rdi,%rax), %r11
je 0x1359f0
movq 0x10(%r14), %rax
movb 0x50(%rax), %cl
movq $-0x1, %r14
shlq %cl, %r14
notq %r14
movq 0x78(%rax), %r13
andq %r11, %r14
shlq $0x5, %r14
movq (%r13,%r14), %r10
movq 0x10(%r10), %rbp
xorl %ebx, %ebx
movl $0x0, %r9d
testq %rbp, %rbp
je 0x135916
movq %rsi, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movb (%r10), %cl
movl $0x1, %r9d
shll %cl, %r9d
movq %r11, %rax
shrq $0xc, %rax
imull $0x9e3779b9, %eax, %r8d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r8d
leal -0x1(%r9), %ecx
movq 0x8(%r10), %rax
movl %r8d, %esi
movl %esi, %edi
shrl $0x5, %edi
movl (%rax,%rdi,4), %edi
btl %esi, %edi
jae 0x135907
movl %esi, %edi
shlq $0x4, %rdi
movq (%rbp,%rdi), %rdi
xorq %r11, %rdi
cmpq $0x1000, %rdi           # imm = 0x1000
jb 0x135904
incl %esi
andl %ecx, %esi
cmpl %r8d, %esi
jne 0x1358d5
jmp 0x135907
movl %esi, %r9d
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rsi
testq %rbp, %rbp
je 0x135925
movb (%r10), %cl
movl $0x1, %ebx
shll %cl, %ebx
cmpl %ebx, %r9d
jne 0x13592e
xorl %ecx, %ecx
jmp 0x1359aa
addq %r14, %r13
movl %r9d, %eax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %r11
leaq (,%r11,8), %r8
addq 0x10(%r13), %r8
movq (%rbp,%rax), %rcx
movl $0xfff, %eax            # imm = 0xFFF
andq %rax, %rcx
cmpq %rax, %rcx
jne 0x1359aa
cmpl 0x18(%r13), %r9d
movq (%rsp), %r14
jne 0x13596b
movq 0x8(%r13), %rcx
jmp 0x1359a5
testq %rbp, %rbp
je 0x13597c
movb (%r10), %cl
movl $0x1, %eax
shll %cl, %eax
jmp 0x13597e
xorl %eax, %eax
incl %r9d
cmpl %eax, %r9d
je 0x135965
movq 0x8(%r10), %rax
movl %r9d, %ecx
shrl $0x5, %ecx
movl (%rax,%rcx,4), %eax
btl %r9d, %eax
jae 0x13596b
movl %r9d, %eax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rcx
subq %r11, %rcx
jmp 0x1359ae
movq (%rsp), %r14
testq %rcx, %rcx
je 0x1359e8
subq %rsi, %r15
movq -0x8(%r8,%rcx,8), %rax
incq %r15
leaq (%rax,%r15), %rsi
movq %rsi, -0x8(%r8,%rcx,8)
je 0x1359e8
leaq (%r8,%rax,8), %rax
addq 0x40(%rsp), %r12
xorl %ecx, %ecx
movq (%r12), %rsi
movq %rsi, (%rax,%rcx,8)
incq %rcx
addq $0x10, %r12
cmpq %rcx, %r15
jne 0x1359d4
movq %rdx, %rsi
movq 0x28(%rsp), %rcx
leaq 0x1(%rdx), %rax
movq %rdx, %r15
cmpq %rcx, %rax
jne 0x135850
jmp 0x135a09
xorl %r8d, %r8d
xorl %esi, %esi
xorl %edx, %edx
movq %r8, 0x8(%rsp)
movq 0x38(%rsp), %rax
movq 0x30(%rsp), %r8
leaq (%r8,%rax,8), %r13
testq %rcx, %rcx
je 0x135bb8
movq 0x10(%r14), %rax
movq %rsi, %r8
shlq $0x4, %r8
movq (%rdi,%r8), %r12
movb 0x50(%rax), %cl
movq $-0x1, %r15
shlq %cl, %r15
notq %r15
movq 0x78(%rax), %r10
andq %r12, %r15
shlq $0x5, %r15
movq (%r10,%r15), %rbx
movq 0x10(%rbx), %r11
xorl %ebp, %ebp
movl $0x0, %r14d
testq %r11, %r11
je 0x135ad4
movq %r13, (%rsp)
movq %rsi, %r9
movb (%rbx), %cl
movl $0x1, %r14d
shll %cl, %r14d
movq %r12, %rax
shrq $0xc, %rax
imull $0x9e3779b9, %eax, %esi # imm = 0x9E3779B9
negb %cl
shrl %cl, %esi
leal -0x1(%r14), %ecx
movq 0x8(%rbx), %rax
movl %esi, %r13d
movl %r13d, %edi
shrl $0x5, %edi
movl (%rax,%rdi,4), %edi
btl %r13d, %edi
jae 0x135ac8
movl %r13d, %edi
shlq $0x4, %rdi
movq (%r11,%rdi), %rdi
xorq %r12, %rdi
cmpq $0x1000, %rdi           # imm = 0x1000
jb 0x135ac5
incl %r13d
andl %ecx, %r13d
cmpl %esi, %r13d
jne 0x135a92
jmp 0x135ac8
movl %r13d, %r14d
movq 0x10(%rsp), %rdi
movq %r9, %rsi
movq (%rsp), %r13
testq %r11, %r11
je 0x135ae2
movb (%rbx), %cl
movl $0x1, %ebp
shll %cl, %ebp
cmpl %ebp, %r14d
jne 0x135aee
xorl %ecx, %ecx
jmp 0x135b72
movq %rsi, %r9
addq %r15, %r10
movl %r14d, %eax
shlq $0x4, %rax
movq 0x8(%r11,%rax), %r15
leaq (,%r15,8), %rcx
addq 0x10(%r10), %rcx
movq %rcx, 0x8(%rsp)
movl $0xfff, %esi            # imm = 0xFFF
movq (%r11,%rax), %rcx
andq %rsi, %rcx
cmpq %rsi, %rcx
jne 0x135b6f
cmpl 0x18(%r10), %r14d
movq %r9, %rsi
jne 0x135b31
movq 0x8(%r10), %rcx
jmp 0x135b6a
testq %r11, %r11
je 0x135b41
movb (%rbx), %cl
movl $0x1, %eax
shll %cl, %eax
jmp 0x135b43
xorl %eax, %eax
incl %r14d
cmpl %eax, %r14d
je 0x135b2b
movq 0x8(%rbx), %rax
movl %r14d, %ecx
shrl $0x5, %ecx
movl (%rax,%rcx,4), %eax
btl %r14d, %eax
jae 0x135b31
movl %r14d, %eax
shlq $0x4, %rax
movq 0x8(%r11,%rax), %rcx
subq %r15, %rcx
jmp 0x135b72
movq %r9, %rsi
testq %rcx, %rcx
je 0x135bb8
subq %rsi, %rdx
movq 0x8(%rsp), %r10
movq -0x8(%r10,%rcx,8), %rax
incq %rdx
leaq (%rax,%rdx), %rsi
movq %rsi, -0x8(%r10,%rcx,8)
je 0x135bb8
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rax
leaq (%r8,%rdi), %rcx
addq $0x8, %rcx
xorl %esi, %esi
movq (%rcx), %rdi
movq %rdi, (%rax,%rsi,8)
incq %rsi
addq $0x10, %rcx
cmpq %rsi, %rdx
jne 0x135ba5
movq $0x0, (%r13)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq