// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x10(%rdi), %r12
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq (%r12,%rax), %rsi
testq %rsi, %rsi
je 0x4e4e
addq %rax, %r12
movq 0x10(%r12), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x31ad
movl $0x0, 0x18(%r12)
movq (%r12), %rax
movq $0x0, 0x8(%rsp)
movl $0x0, %ebp
testq %rax, %rax
je 0x4cbc
xorl %ebp, %ebp
movl $0x1, %edx
movl $0x10, %ecx
cmpq $0x1, %rax
je 0x4ca0
movq 0x10(%r12), %rsi
movq (%rsi,%rcx), %rdi
cmpq -0x10(%rsi,%rcx), %rdi
jne 0x4ca0
incl %edx
movl %edx, %esi
jmp 0x4cb1
incl %ebp
movl $0x1, %esi
cmpl $0x2, %edx
jl 0x4cb1
addl %edx, 0x18(%r12)
addq $0x10, %rcx
movl %esi, %edx
decq %rax
jne 0x4c84
movl $0x1, %ebx
movl $0x1, %edi
movl $0x28, %esi
callq 0x2150
movq %rax, 0x10(%rsp)
movq %rax, %rdi
movl %ebp, %esi
callq 0x47eb
movslq 0x18(%r12), %rdi
movl $0x8, %esi
callq 0x2150
movq %rax, 0x20(%r12)
movq (%r12), %rax
testq %rax, %rax
je 0x4e1d
movl $0x1, %ebp
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
cmpq %rbx, %rax
je 0x4d34
movq 0x10(%r12), %rax
movq %rbx, %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rdx
cmpq -0x10(%rax,%rcx), %rdx
jne 0x4d34
incl %ebp
jmp 0x4e09
movq 0x10(%r12), %r13
movq %rbx, %r15
shlq $0x4, %r15
movq -0x10(%r13,%r15), %rsi
movq 0x20(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
movq 0x10(%rsp), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x4a95
cmpl $0x0, 0x1c(%rsp)
je 0x4e5d
movl %ebx, %ecx
subl %r14d, %ecx
cmpl %ebp, %ecx
jne 0x4e5d
movl %eax, %eax
cmpl $0x1, %ebp
jne 0x4d9f
movq 0x10(%rsp), %rdx
movq 0x18(%rdx), %rcx
orq $0x1, (%rcx,%rax,8)
addq %r15, %r13
movq -0x8(%r13), %rcx
movq 0x20(%rdx), %rdx
movq %rcx, (%rdx,%rax,8)
jmp 0x4e01
jl 0x4ddb
movq 0x10(%r12), %rsi
movslq %r14d, %rdi
movslq 0x8(%rsp), %rcx
movl %ebp, %edx
shlq $0x3, %rcx
addq 0x20(%r12), %rcx
shlq $0x4, %rdi
addq %rdi, %rsi
addq $0x8, %rsi
shlq $0x3, %rdx
xorl %edi, %edi
movq (%rsi,%rdi,2), %r8
movq %r8, (%rcx,%rdi)
addq $0x8, %rdi
cmpq %rdi, %rdx
jne 0x4dca
movq 0x8(%rsp), %rsi
movq %rsi, %rcx
shlq $0x20, %rcx
movslq %ebp, %rdx
orq %rcx, %rdx
movq 0x10(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq %rdx, (%rcx,%rax,8)
addl %ebp, %esi
movq %rsi, 0x8(%rsp)
movl $0x1, %ebp
movl %ebx, %r14d
leaq 0x1(%rbx), %rcx
movq (%r12), %rax
cmpq %rbx, %rax
movq %rcx, %rbx
ja 0x4d11
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r12)
movq 0x8(%rsp), %rax
cmpl %eax, 0x18(%r12)
jne 0x4e7c
movq 0x10(%r12), %rdi
callq 0x2040
xorps %xmm0, %xmm0
movups %xmm0, (%r12)
movq $0x0, 0x10(%r12)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3a52(%rip), %rdi      # 0x88b6
leaq 0x39ab(%rip), %rsi      # 0x8816
leaq 0x3a5f(%rip), %rcx      # 0x88d1
movl $0x7d, %edx
callq 0x2110
leaq 0x3a72(%rip), %rdi      # 0x88f5
leaq 0x398c(%rip), %rsi      # 0x8816
leaq 0x3a40(%rip), %rcx      # 0x88d1
movl $0x8c, %edx
callq 0x2110
nop