// File: /workspace/github_c_makefile_star2_O2/lh3[P]minimap/index.c
// Function: worker_post
static void worker_post(void *g, long i, int tid)
{
	int j, start_a, start_p, n, n_keys;
	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 != b->a.a[j-1].x) {
			++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 != b->a.a[j-1].x) {
			khint_t itr;
			int absent;
			mm128_t *p = &b->a.a[j-1];
			itr = kh_put(idx, h, p->x>>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;
				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 == start_p);

	// deallocate and clear b->a
	free(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 $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rdi), %r12
imulq $0x30, %rsi, %rax
movq (%r12,%rax), %rsi
testq %rsi, %rsi
je 0x4a4a
addq %rax, %r12
movq 0x10(%r12), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x2f60
andl $0x0, 0x18(%r12)
movq (%r12), %rax
pushq $0x1
popq %rcx
xorl %edx, %edx
pushq $0x10
popq %rsi
xorl %ebp, %ebp
movl %ecx, %edi
subq $0x1, %rax
jb 0x4908
je 0x48f2
movq 0x10(%r12), %r8
movq (%r8,%rsi), %r9
cmpq -0x10(%r8,%rsi), %r9
jne 0x48f2
incl %edi
jmp 0x4902
incl %ebp
cmpl $0x2, %edi
jl 0x4900
addl %edi, %edx
movl %edx, 0x18(%r12)
movl %ecx, %edi
addq $0x10, %rsi
jmp 0x48d6
callq 0x44a1
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x44ac
movslq 0x18(%r12), %rdi
pushq $0x8
popq %rsi
callq 0x2150
movq %rax, 0x20(%r12)
movl $0x0, 0x8(%rsp)
pushq $0x1
popq %r13
pushq $0x1
popq %rbp
xorl %ebx, %ebx
movq (%r12), %rax
cmpq %rbp, %rax
jb 0x4a22
movq %rbp, %r15
shlq $0x4, %r15
addq 0x10(%r12), %r15
cmpq %rbp, %rax
jne 0x4961
movq -0x10(%r15), %rsi
jmp 0x4972
movq -0x10(%r15), %rsi
cmpq %rsi, (%r15)
jne 0x4972
incl %r13d
jmp 0x4a1a
movq 0x10(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
callq 0x46fe
cmpl $0x0, 0xc(%rsp)
je 0x4a59
movl %ebp, %ecx
subl %ebx, %ecx
cmpl %r13d, %ecx
jne 0x4a59
movl %eax, %eax
cmpl $0x1, %r13d
jne 0x49c3
movq 0x18(%r14), %rcx
orq $0x1, (%rcx,%rax,8)
movq -0x8(%r15), %rcx
movq 0x20(%r14), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x4a14
movslq 0x8(%rsp), %rcx
movslq %ebx, %rdx
movl $0x0, %esi
cmovgel %r13d, %esi
shlq $0x4, %rdx
movq %rcx, %rdi
subq $0x1, %rsi
jb 0x49fd
movq 0x10(%r12), %r8
movq 0x20(%r12), %r9
movq 0x8(%r8,%rdx), %r8
movq %r8, (%r9,%rdi,8)
incq %rdi
addq $0x10, %rdx
jmp 0x49db
shlq $0x20, %rcx
movslq %r13d, %rdx
orq %rcx, %rdx
movq 0x20(%r14), %rcx
movq %rdx, (%rcx,%rax,8)
addl %r13d, 0x8(%rsp)
pushq $0x1
popq %r13
movl %ebp, %ebx
incq %rbp
jmp 0x493d
movq %r14, 0x28(%r12)
movl 0x8(%rsp), %eax
cmpl %eax, 0x18(%r12)
jne 0x4a76
movq 0x10(%r12), %rdi
callq 0x2040
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
andq $0x0, 0x10(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3e26(%rip), %rdi      # 0x8886
leaq 0x3d7f(%rip), %rsi      # 0x87e6
leaq 0x3e33(%rip), %rcx      # 0x88a1
pushq $0x7d
popq %rdx
callq 0x2110
leaq 0x3e48(%rip), %rdi      # 0x88c5
leaq 0x3d62(%rip), %rsi      # 0x87e6
leaq 0x3e16(%rip), %rcx      # 0x88a1
movl $0x8c, %edx
callq 0x2110
nopl (%rax)