// File: /workspace/github_c_makefile_star2_O2/lh3[P]minimap2/index.c
// Function: worker_post
static void worker_post(void *g, long i, int tid)
{
	int n, n_keys;
	size_t j, start_a, start_p;
	idxhash_t *h;
	mm_idx_t *mi = (mm_idx_t*)g;
	mm_idx_bucket_t *b = &mi->B[i];
	if (b->a.n == 0) return;

	// sort by minimizer
	radix_sort_128x(b->a.a, b->a.a + b->a.n);

	// count and preallocate
	for (j = 1, n = 1, n_keys = 0, b->n = 0; j <= b->a.n; ++j) {
		if (j == b->a.n || b->a.a[j].x>>8 != b->a.a[j-1].x>>8) {
			++n_keys;
			if (n > 1) b->n += n;
			n = 1;
		} else ++n;
	}
	h = kh_init(idx);
	kh_resize(idx, h, n_keys);
	b->p = (uint64_t*)calloc(b->n, 8);

	// create the hash table
	for (j = 1, n = 1, start_a = start_p = 0; j <= b->a.n; ++j) {
		if (j == b->a.n || b->a.a[j].x>>8 != b->a.a[j-1].x>>8) {
			khint_t itr;
			int absent;
			mm128_t *p = &b->a.a[j-1];
			itr = kh_put(idx, h, p->x>>8>>mi->b<<1, &absent);
			assert(absent && j == start_a + n);
			if (n == 1) {
				kh_key(h, itr) |= 1;
				kh_val(h, itr) = p->y;
			} else {
				int k;
				for (k = 0; k < n; ++k)
					b->p[start_p + k] = b->a.a[start_a + k].y;
				radix_sort_64(&b->p[start_p], &b->p[start_p + n]); // sort by position; needed as in-place radix_sort_128x() is not stable
				kh_val(h, itr) = (uint64_t)start_p<<32 | n;
				start_p += n;
			}
			start_a = j, n = 1;
		} else ++n;
	}
	b->h = h;
	assert(b->n == (int32_t)start_p);

	// deallocate and clear b->a
	kfree(0, b->a.a);
	b->a.n = b->a.m = 0, b->a.a = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x30(%rdi), %r12
imulq $0x30, %rsi, %rax
movq (%r12,%rax), %rsi
testq %rsi, %rsi
je 0x98b1
addq %rax, %r12
movq 0x10(%r12), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x47dc
andl $0x0, 0x18(%r12)
movq (%r12), %rax
pushq $0x1
popq %rcx
pushq $0x1
popq %rdx
xorl %esi, %esi
pushq $0x10
popq %rdi
xorl %ebp, %ebp
movl %ecx, %r8d
cmpq %rax, %rdx
ja 0x9734
je 0x9718
movq 0x10(%r12), %r9
movq -0x10(%r9,%rdi), %r10
xorq (%r9,%rdi), %r10
cmpq $0x100, %r10            # imm = 0x100
jae 0x9718
incl %r8d
jmp 0x972b
incl %ebp
cmpl $0x2, %r8d
jl 0x9728
addl %r8d, %esi
movl %esi, 0x18(%r12)
movl %ecx, %r8d
incq %rdx
addq $0x10, %rdi
jmp 0x96f5
callq 0x71a5
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x71b2
movslq 0x18(%r12), %rdi
pushq $0x8
popq %rsi
callq 0x2230
movq %rax, 0x20(%r12)
pushq $0x1
popq %rax
pushq $0x1
popq %r15
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
movl %eax, %ebx
movq %r14, 0x18(%rsp)
movq (%r12), %rax
cmpq %rax, %r15
ja 0x9886
movq %r15, %rbp
shlq $0x4, %rbp
addq 0x10(%r12), %rbp
cmpq %rax, %r15
jne 0x9796
movq -0x10(%rbp), %rsi
jmp 0x97b0
movq -0x10(%rbp), %rsi
movq (%rbp), %rax
xorq %rsi, %rax
cmpq $0x100, %rax            # imm = 0x100
jae 0x97b0
incl %ebx
jmp 0x987e
shrq $0x8, %rsi
movq 0x20(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
callq 0x7414
cmpl $0x0, 0x14(%rsp)
je 0x98c0
movslq %ebx, %r14
leaq (%r14,%r13), %rcx
cmpq %rcx, %r15
jne 0x98c0
movl %eax, %edx
cmpl $0x1, %ebx
jne 0x980c
movq 0x18(%rsp), %r14
movq 0x18(%r14), %rax
orq $0x1, (%rax,%rdx,8)
movq -0x8(%rbp), %rax
movq 0x20(%r14), %rcx
movq %rax, (%rcx,%rdx,8)
jmp 0x9876
movq %rdx, %rbp
movl $0x0, %eax
cmovll %eax, %ebx
shlq $0x4, %r13
movq 0x8(%rsp), %rax
subq $0x1, %rbx
jb 0x9842
movq 0x10(%r12), %rcx
movq 0x20(%r12), %rdx
movq 0x8(%rcx,%r13), %rcx
movq %rcx, (%rdx,%rax,8)
addq $0x10, %r13
incq %rax
jmp 0x9820
movq 0x20(%r12), %rax
movq 0x8(%rsp), %r13
leaq (%rax,%r13,8), %rdi
leaq (%r14,%r13), %rbx
leaq (%rax,%rbx,8), %rsi
callq 0x49de
shlq $0x20, %r13
orq %r14, %r13
movq 0x18(%rsp), %r14
movq 0x20(%r14), %rax
movq %r13, (%rax,%rbp,8)
movq %rbx, 0x8(%rsp)
movq %r15, %r13
pushq $0x1
popq %rax
movl %eax, %ebx
incq %r15
jmp 0x9772
movq %r14, 0x28(%r12)
movq 0x8(%rsp), %rax
cmpl %eax, 0x18(%r12)
jne 0x98df
movq 0x10(%r12), %rsi
xorl %edi, %edi
callq 0x10a07
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
andq $0x0, 0x10(%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1ed86(%rip), %rdi     # 0x2864d
leaq 0x1e9eb(%rip), %rsi     # 0x282b9
leaq 0x1ed93(%rip), %rcx     # 0x28668
movl $0x101, %edx            # imm = 0x101
callq 0x21a0
leaq 0x1eda6(%rip), %rdi     # 0x2868c
leaq 0x1e9cc(%rip), %rsi     # 0x282b9
leaq 0x1ed74(%rip), %rcx     # 0x28668
movl $0x111, %edx            # imm = 0x111
callq 0x21a0