// File: /workspace/github_cpp_makefile_star2_O3/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 $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
cmpl $0x0, (%rdi)
je 0x13b800
movq 0x10(%r14), %rax
movq %rbx, %rcx
shlq $0x5, %rcx
addq 0x78(%rax), %rcx
movq %rcx, (%rsp)
movq 0x18(%r14), %rax
leaq (%rbx,%rbx,2), %r15
movq (%rax,%r15,8), %rcx
cmpq $0x3, %rcx
jb 0x13b6b0
leaq (%rax,%r15,8), %rax
movq 0x10(%rax), %rdi
leaq (%rdi,%rcx,8), %rsi
callq 0x1390c9
movq 0x18(%r14), %rax
movq (%rax,%r15,8), %rcx
testq %rcx, %rcx
je 0x13b7ea
movq %rbx, 0x28(%rsp)
movq %r14, 0x8(%rsp)
movq %r15, 0x20(%rsp)
movq 0x10(%rax,%r15,8), %r14
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
movq %rcx, 0x10(%rsp)
movq (%r14,%r15,8), %rsi
cmpq (%r14,%r13,8), %rsi
je 0x13b759
movq (%rsp), %rbx
movq (%rbx), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x165566
movl %eax, %eax
shlq $0x4, %rax
cmpl $0x0, 0x1c(%rsp)
movq (%rbx), %rcx
movq 0x10(%rcx), %rcx
leaq 0x8(%rcx,%rax), %rdx
je 0x13b71c
movq $0x0, (%rdx)
xorl %edx, %edx
jmp 0x13b71f
movq (%rdx), %rdx
addq %rbp, %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
jb 0x13b74a
movl $0xfff, %edx            # imm = 0xFFF
orq %rsi, %rdx
movq %rdx, (%rcx,%rax)
movq %r13, %r15
movq 0x10(%rsp), %rcx
leaq 0x1(%r13), %rbx
movq %r15, %r12
negq %r12
movq %r13, %rbp
movq %rbx, %r13
cmpq %rbx, %rcx
jne 0x13b6dd
movq (%rsp), %r12
movq (%r12), %rdi
movq (%r14,%r15,8), %rsi
leaq 0x1c(%rsp), %r14
movq %r14, %rdx
callq 0x165566
movl %eax, %eax
shlq $0x4, %rax
cmpl $0x0, (%r14)
movq (%r12), %rcx
movq 0x10(%rcx), %rcx
leaq 0x8(%rcx,%rax), %rdx
je 0x13b7af
movq $0x0, (%rdx)
xorl %edx, %edx
jmp 0x13b7b2
movq (%rdx), %rdx
movq 0x8(%rsp), %r14
subq %r15, %rdx
addq %rbx, %rdx
movq %rdx, 0x8(%rcx,%rax)
movq $-0x1000, %rsi          # imm = 0xF000
andq (%rcx,%rax), %rsi
movl $0xfff, %edi            # imm = 0xFFF
cmpq %rdi, %rdx
cmovaeq %rdi, %rdx
orq %rsi, %rdx
movq %rdx, (%rcx,%rax)
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r15
movq 0x18(%r14), %rax
movq $0x0, (%rax,%r15,8)
cmpl $0x0, (%r14)
jne 0x13bb42
movq 0x20(%r14), %rax
leaq (%rbx,%rbx,2), %rbx
movq (%rax,%rbx,8), %rsi
cmpq $0x3, %rsi
jb 0x13b82e
leaq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x139324
movq 0x20(%r14), %rax
movq (%rax,%rbx,8), %rsi
leaq (%rax,%rbx,8), %rdi
testq %rsi, %rsi
je 0x13bb3b
movq %rdi, 0x20(%rsp)
movq %r14, 0x8(%rsp)
movq 0x10(%rax,%rbx,8), %rax
movq %rax, 0x10(%rsp)
addq $0x8, %rax
movq %rax, 0x30(%rsp)
movl $0x1, %eax
xorl %r11d, %r11d
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %rsi, 0x28(%rsp)
movq %rcx, %r8
movq %r14, %r12
movq %rax, (%rsp)
movq %r14, %r15
shlq $0x4, %r15
movq 0x10(%rsp), %rcx
movq (%rcx,%r15), %r9
movq %r8, %rax
shlq $0x4, %rax
cmpq (%rcx,%rax), %r9
jne 0x13b899
movq %r12, %r14
jmp 0x13b92c
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rdx
movb 0x50(%rdx), %cl
movq $-0x1, %rax
shlq %cl, %rax
notq %rax
movq 0x78(%rdx), %r13
andq %r9, %rax
shlq $0x5, %rax
movq (%r13,%rax), %r10
movq 0x10(%r10), %rbp
movq %r8, %r14
testq %rbp, %rbp
je 0x13b92c
movb (%r10), %cl
movl $0x1, %edx
shll %cl, %edx
movq %r9, %rsi
shrq $0xc, %rsi
imull $0x9e3779b9, %esi, %r14d # imm = 0x9E3779B9
negb %cl
shrl %cl, %r14d
addq %rax, %r13
leal -0x1(%rdx), %ebx
movq 0x8(%r10), %r10
movl %r14d, %eax
movl %eax, %ecx
shrl $0x5, %ecx
movl (%r10,%rcx,4), %ecx
btl %eax, %ecx
jae 0x13b929
movl %eax, %esi
shlq $0x4, %rsi
movq (%rbp,%rsi), %rdi
movq %rdi, %rcx
xorq %r9, %rcx
cmpq $0x1000, %rcx           # imm = 0x1000
jb 0x13b94d
incl %eax
andl %ebx, %eax
cmpl %r14d, %eax
jne 0x13b8f8
movq %r8, %r14
leaq 0x1(%r8), %rcx
movq (%rsp), %rax
incq %rax
movq %r8, %r11
movq 0x28(%rsp), %rsi
cmpq %rsi, %rcx
jne 0x13b86a
jmp 0x13b9eb
movq %r8, %r14
cmpl %edx, %eax
je 0x13b92c
movq 0x8(%rbp,%rsi), %r9
movl $0xfff, %ecx            # imm = 0xFFF
andq %rcx, %rdi
cmpq %rcx, %rdi
jne 0x13b994
cmpl 0x18(%r13), %eax
jne 0x13b972
movq 0x8(%r13), %rdi
jmp 0x13b991
cmpl %eax, %ebx
je 0x13b96c
incl %eax
movl %eax, %ecx
shrl $0x5, %ecx
movl (%r10,%rcx,4), %ecx
btl %eax, %ecx
jae 0x13b972
movl %eax, %eax
shlq $0x4, %rax
movq 0x8(%rbp,%rax), %rdi
subq %r9, %rdi
movq %r8, %r14
testq %rdi, %rdi
je 0x13b92c
movq 0x10(%r13), %rax
leaq (%rax,%r9,8), %rcx
subq %r12, %r11
movq -0x8(%rcx,%rdi,8), %rdx
movq %r8, %r14
incq %r11
leaq (%rdx,%r11), %rsi
movq %rsi, -0x8(%rcx,%rdi,8)
je 0x13b92c
addq 0x30(%rsp), %r15
shlq $0x3, %rdx
leaq (%rdx,%r9,8), %rcx
addq %rcx, %rax
xorl %ecx, %ecx
movq (%r15), %rdx
movq %rdx, (%rax,%rcx,8)
incq %rcx
addq $0x10, %r15
cmpq %rcx, %r11
jne 0x13b9d3
jmp 0x13b929
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdx
shlq $0x4, %rdx
movb 0x50(%rsi), %cl
movq $-0x1, %r11
shlq %cl, %r11
movq 0x10(%rsp), %rax
movq (%rax,%rdx), %rax
notq %r11
movq 0x78(%rsi), %r9
andq %rax, %r11
shlq $0x5, %r11
movq (%r9,%r11), %rbx
movq 0x10(%rbx), %r10
testq %r10, %r10
movq 0x20(%rsp), %rdi
je 0x13bb3b
movb (%rbx), %cl
movl $0x1, %r12d
shll %cl, %r12d
movq %rax, %rsi
shrq $0xc, %rsi
imull $0x9e3779b9, %esi, %ebp # imm = 0x9E3779B9
negb %cl
shrl %cl, %ebp
addq %r11, %r9
leal -0x1(%r12), %r11d
movq 0x8(%rbx), %r15
movl %ebp, %ebx
movl %ebx, %ecx
shrl $0x5, %ecx
movl (%r15,%rcx,4), %ecx
btl %ebx, %ecx
jae 0x13bb3b
movl %ebx, %ecx
shlq $0x4, %rcx
movq (%r10,%rcx), %r13
movq %r13, %rsi
xorq %rax, %rsi
cmpq $0x1000, %rsi           # imm = 0x1000
jb 0x13ba98
incl %ebx
andl %r11d, %ebx
cmpl %ebp, %ebx
jne 0x13ba5f
jmp 0x13bb3b
cmpl %r12d, %ebx
je 0x13bb3b
movq 0x8(%r10,%rcx), %rcx
movl $0xfff, %eax            # imm = 0xFFF
andq %rax, %r13
cmpq %rax, %r13
jne 0x13bae2
cmpl 0x18(%r9), %ebx
jne 0x13babf
movq 0x8(%r9), %r13
jmp 0x13badf
cmpl %ebx, %r11d
je 0x13bab9
incl %ebx
movl %ebx, %eax
shrl $0x5, %eax
movl (%r15,%rax,4), %eax
btl %ebx, %eax
jae 0x13babf
movl %ebx, %eax
shlq $0x4, %rax
movq 0x8(%r10,%rax), %r13
subq %rcx, %r13
testq %r13, %r13
je 0x13bb3b
movq 0x10(%r9), %rax
leaq (%rax,%rcx,8), %rdi
subq %r14, %r8
movq -0x8(%rdi,%r13,8), %rsi
incq %r8
leaq (%rsi,%r8), %r8
movq %r8, -0x8(%rdi,%r13,8)
movq 0x20(%rsp), %rdi
je 0x13bb3b
subq %r14, (%rsp)
movq 0x10(%rsp), %r8
addq %r8, %rdx
addq $0x8, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rcx,8), %rcx
addq %rcx, %rax
xorl %ecx, %ecx
movq (%rdx), %rsi
movq %rsi, (%rax,%rcx,8)
incq %rcx
addq $0x10, %rdx
cmpq %rcx, (%rsp)
jne 0x13bb27
movq $0x0, (%rdi)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq