// File: /workspace/github_c_makefile_star2_O1/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), %r15
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq (%r15,%rax), %rsi
testq %rsi, %rsi
je 0xac25
addq %rax, %r15
movq 0x10(%r15), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x5ae1
movl $0x0, 0x18(%r15)
movq (%r15), %rax
movq $0x0, 0x8(%rsp)
movl $0x0, %ebx
testq %rax, %rax
je 0xaa79
leaq 0x1(%rax), %rdx
cmpq $0x3, %rdx
movl $0x2, %ecx
cmovaeq %rdx, %rcx
movl $0x1, %edx
xorl %ebx, %ebx
movl $0x1, %edi
movl $0x10, %esi
cmpq %rdx, %rax
je 0xaa59
movq 0x10(%r15), %r8
movq -0x10(%r8,%rsi), %r9
xorq (%r8,%rsi), %r9
cmpq $0x100, %r9             # imm = 0x100
jae 0xaa59
incl %edi
movl %edi, %r8d
jmp 0xaa6a
incl %ebx
movl $0x1, %r8d
cmpl $0x2, %edi
jl 0xaa6a
addl %edi, 0x18(%r15)
incq %rdx
addq $0x10, %rsi
movl %r8d, %edi
cmpq %rdx, %rcx
jne 0xaa37
movl $0x1, %ebp
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x1257c
movq %rax, %r14
movq %rax, %rdi
movl %ebx, %esi
callq 0x82af
movslq 0x18(%r15), %rdi
movl $0x8, %esi
callq 0x2230
movq %r14, %rdi
movq %rax, 0x20(%r15)
movq (%r15), %rax
testq %rax, %rax
je 0xabfc
movl $0x1, %ebx
xorl %r13d, %r13d
movq $0x0, 0x8(%rsp)
movq %rdi, 0x18(%rsp)
cmpq %rax, %rbp
je 0xaafc
movq 0x10(%r15), %rax
movq %rbp, %rcx
shlq $0x4, %rcx
movq -0x10(%rax,%rcx), %rdx
xorq (%rax,%rcx), %rdx
cmpq $0x100, %rdx            # imm = 0x100
jae 0xaafc
incl %ebx
jmp 0xabed
movq %r15, %r14
movq 0x10(%r15), %r12
movq %rbp, %r15
shlq $0x4, %r15
movq -0x10(%r12,%r15), %rsi
shrq $0x8, %rsi
movq 0x20(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
leaq 0x14(%rsp), %rdx
callq 0x8568
cmpl $0x0, 0x14(%rsp)
je 0xac34
movl %ebx, %edi
movq %r13, %rsi
movslq %ebx, %r13
leaq (%rsi,%r13), %rcx
cmpq %rcx, %rbp
jne 0xac34
movl %eax, %ebx
cmpl $0x1, %edi
jne 0xab74
movq 0x18(%rsp), %rdi
movq 0x18(%rdi), %rax
orq $0x1, (%rax,%rbx,8)
addq %r15, %r12
movq -0x8(%r12), %rax
movq 0x20(%rdi), %rcx
movq %rax, (%rcx,%rbx,8)
movq %r14, %r15
jmp 0xabe5
movq %r14, %r15
jl 0xabb2
movq 0x10(%r15), %rdx
movq 0x8(%rsp), %rax
leaq (,%rax,8), %rax
addq 0x20(%r15), %rax
movl %edi, %ecx
shlq $0x4, %rsi
addq %rsi, %rdx
addq $0x8, %rdx
shlq $0x3, %rcx
xorl %esi, %esi
movq (%rdx,%rsi,2), %rdi
movq %rdi, (%rax,%rsi)
addq $0x8, %rsi
cmpq %rsi, %rcx
jne 0xaba1
movq 0x20(%r15), %rax
movq 0x8(%rsp), %r14
leaq (%rax,%r14,8), %rdi
leaq (%r14,%r13), %r12
leaq (%rax,%r12,8), %rsi
callq 0x5d2f
shlq $0x20, %r14
orq %r13, %r14
movq 0x18(%rsp), %rdi
movq 0x20(%rdi), %rax
movq %r14, (%rax,%rbx,8)
movq %r12, 0x8(%rsp)
movl $0x1, %ebx
movq %rbp, %r13
incq %rbp
movq (%r15), %rax
cmpq %rax, %rbp
jbe 0xaad3
movq %rdi, 0x28(%r15)
movq 0x8(%rsp), %rax
cmpl %eax, 0x18(%r15)
jne 0xac53
movq 0x10(%r15), %rsi
xorl %edi, %edi
callq 0x1261e
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $0x0, 0x10(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x219ee(%rip), %rdi     # 0x2c629
leaq 0x21653(%rip), %rsi     # 0x2c295
leaq 0x219fb(%rip), %rcx     # 0x2c644
movl $0x101, %edx            # imm = 0x101
callq 0x21a0
leaq 0x21a0e(%rip), %rdi     # 0x2c668
leaq 0x21634(%rip), %rsi     # 0x2c295
leaq 0x219dc(%rip), %rcx     # 0x2c644
movl $0x111, %edx            # imm = 0x111
callq 0x21a0