// File: /workspace/github_c_makefile_star2_O3/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
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq (%r12,%rax), %rsi
testq %rsi, %rsi
je 0x4e8a
addq %rax, %r12
movq 0x10(%r12), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x319d
movl $0x0, 0x18(%r12)
movq (%r12), %rax
movl $0x0, %ebp
testq %rax, %rax
je 0x4cf5
movl $0x1, %esi
xorl %ecx, %ecx
movl $0x10, %edx
xorl %ebp, %ebp
cmpq $0x1, %rax
je 0x4cd7
movq 0x10(%r12), %rdi
movq (%rdi,%rdx), %r8
cmpq -0x10(%rdi,%rdx), %r8
jne 0x4cd7
incl %esi
movl %esi, %edi
jmp 0x4cea
incl %ebp
movl $0x1, %edi
cmpl $0x2, %esi
jl 0x4cea
addl %esi, %ecx
movl %ecx, 0x18(%r12)
addq $0x10, %rdx
movl %edi, %esi
decq %rax
jne 0x4cbb
movl $0x0, 0x8(%rsp)
movl $0x1, %r15d
movl $0x1, %edi
movl $0x28, %esi
callq 0x2150
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
callq 0x4858
movl 0x18(%r12), %ebx
movslq %ebx, %rdi
movl $0x8, %esi
callq 0x2150
movq %rax, 0x20(%r12)
movq (%r12), %rax
testq %rax, %rax
je 0x4e64
movl $0x1, %ebp
xorl %ebx, %ebx
movl $0x0, 0x8(%rsp)
movq 0x10(%r12), %r13
cmpq %r15, %rax
jne 0x4d67
shlq $0x4, %rax
movq -0x10(%r13,%rax), %rsi
jmp 0x4d81
movq %r15, %rcx
shlq $0x4, %rcx
movq -0x10(%r13,%rcx), %rsi
cmpq %rsi, (%r13,%rcx)
jne 0x4d81
incl %ebp
jmp 0x4e4f
movq 0x10(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
movq %r14, %rdi
leaq 0xc(%rsp), %rdx
callq 0x4ac4
cmpl $0x0, 0xc(%rsp)
je 0x4e99
movl %r15d, %ecx
subl %ebx, %ecx
cmpl %ebp, %ecx
jne 0x4e99
movl %eax, %eax
cmpl $0x1, %ebp
jne 0x4ddb
movq 0x18(%r14), %rcx
orq $0x1, (%rcx,%rax,8)
movq %r15, %rcx
shlq $0x4, %rcx
addq %rcx, %r13
movq -0x8(%r13), %rcx
movq 0x20(%r14), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x4e43
jl 0x4e21
movq 0x10(%r12), %rdi
movslq %ebx, %r8
movl 0x8(%rsp), %r10d
movslq %r10d, %rcx
movl %ebp, %edx
leaq (,%rcx,8), %rsi
addq 0x20(%r12), %rsi
shlq $0x4, %r8
addq %r8, %rdi
addq $0x8, %rdi
shlq $0x3, %rdx
xorl %r8d, %r8d
movq (%rdi,%r8,2), %r9
movq %r9, (%rsi,%r8)
addq $0x8, %r8
cmpq %r8, %rdx
jne 0x4e0e
jmp 0x4e29
movl 0x8(%rsp), %r10d
movslq %r10d, %rcx
shlq $0x20, %rcx
movslq %ebp, %rdx
orq %rcx, %rdx
movq 0x20(%r14), %rcx
movq %rdx, (%rcx,%rax,8)
addl %ebp, %r10d
movl %r10d, 0x8(%rsp)
movq (%r12), %rax
movl $0x1, %ebp
movl %r15d, %ebx
leaq 0x1(%r15), %rcx
cmpq %r15, %rax
movq %rcx, %r15
ja 0x4d52
movl 0x18(%r12), %ebx
movq %r14, 0x28(%r12)
cmpl 0x8(%rsp), %ebx
jne 0x4eb8
movq 0x10(%r12), %rdi
callq 0x2040
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq $0x0, 0x10(%r12)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39e6(%rip), %rdi      # 0x8886
leaq 0x393f(%rip), %rsi      # 0x87e6
leaq 0x39f3(%rip), %rcx      # 0x88a1
movl $0x7d, %edx
callq 0x2110
leaq 0x3a06(%rip), %rdi      # 0x88c5
leaq 0x3920(%rip), %rsi      # 0x87e6
leaq 0x39d4(%rip), %rcx      # 0x88a1
movl $0x8c, %edx
callq 0x2110
nop