// File: /workspace/github_c_makefile_star2_O3/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), %r14
leaq (%rsi,%rsi,2), %rax
shlq $0x4, %rax
movq (%r14,%rax), %rsi
testq %rsi, %rsi
je 0xab1d
addq %rax, %r14
movq 0x10(%r14), %rdi
shlq $0x4, %rsi
addq %rdi, %rsi
callq 0x5a49
movl $0x0, 0x18(%r14)
movq (%r14), %rax
movq $0x0, 0x8(%rsp)
movl $0x0, %ebp
testq %rax, %rax
je 0xa96e
leaq 0x1(%rax), %rdx
cmpq $0x3, %rdx
movl $0x2, %ecx
cmovaeq %rdx, %rcx
movl $0x1, %edx
movl $0x1, %r8d
xorl %esi, %esi
movl $0x10, %edi
xorl %ebp, %ebp
cmpq %rdx, %rax
je 0xa94a
movq 0x10(%r14), %r9
movq -0x10(%r9,%rdi), %r10
xorq (%r9,%rdi), %r10
cmpq $0x100, %r10            # imm = 0x100
jae 0xa94a
incl %r8d
movl %r8d, %r9d
jmp 0xa95f
incl %ebp
movl $0x1, %r9d
cmpl $0x2, %r8d
jl 0xa95f
addl %r8d, %esi
movl %esi, 0x18(%r14)
incq %rdx
addq $0x10, %rdi
movl %r9d, %r8d
cmpq %rdx, %rcx
jne 0xa927
movl $0x1, %r15d
movl $0x1, %esi
movl $0x28, %edx
xorl %edi, %edi
callq 0x124ec
movq %rax, %r12
movq %rax, %rdi
movl %ebp, %esi
callq 0x827d
movl 0x18(%r14), %ebx
movslq %ebx, %rdi
movl $0x8, %esi
callq 0x2230
movq %rax, 0x20(%r14)
movq (%r14), %rax
testq %rax, %rax
je 0xaaf9
movl $0x1, %ebp
xorl %r8d, %r8d
movq $0x0, 0x8(%rsp)
movq %r14, %rbx
movq 0x10(%r14), %r14
cmpq %rax, %r15
jne 0xa9db
shlq $0x4, %rax
movq -0x10(%r14,%rax), %rsi
jmp 0xaa01
movq %r15, %rcx
shlq $0x4, %rcx
movq -0x10(%r14,%rcx), %rsi
movq (%r14,%rcx), %rcx
xorq %rsi, %rcx
cmpq $0x100, %rcx            # imm = 0x100
jae 0xaa01
incl %ebp
movq %rbx, %r14
jmp 0xaae9
shrq $0x8, %rsi
movq 0x20(%rsp), %rax
movb (%rax), %cl
shrq %cl, %rsi
addq %rsi, %rsi
movq %r12, %r13
movq %r12, %rdi
leaq 0x14(%rsp), %rdx
movq %r8, %r12
callq 0x84fc
cmpl $0x0, 0x14(%rsp)
je 0xab2c
movq %r12, %rsi
movslq %ebp, %r12
leaq (%rsi,%r12), %rcx
cmpq %rcx, %r15
jne 0xab2c
movl %eax, %edx
cmpl $0x1, %ebp
jne 0xaa71
movq %r13, %r12
movq 0x18(%r13), %rax
orq $0x1, (%rax,%rdx,8)
movq %r15, %rax
shlq $0x4, %rax
addq %rax, %r14
movq -0x8(%r14), %rax
movq 0x20(%r13), %rcx
movq %rax, (%rcx,%rdx,8)
movq %rbx, %r14
jmp 0xaade
movq %rdx, 0x18(%rsp)
movq %rbx, %r14
movq 0x20(%rbx), %rax
movq 0x8(%rsp), %rcx
leaq (%rax,%rcx,8), %rdi
jl 0xaab0
movq 0x10(%r14), %rdx
movl %ebp, %ecx
shlq $0x4, %rsi
addq %rsi, %rdx
addq $0x8, %rdx
shlq $0x3, %rcx
xorl %esi, %esi
movq (%rdx,%rsi,2), %r8
movq %r8, (%rdi,%rsi)
addq $0x8, %rsi
cmpq %rsi, %rcx
jne 0xaa9f
movq 0x8(%rsp), %rbp
leaq (%r12,%rbp), %rbx
leaq (%rax,%rbx,8), %rsi
callq 0x5c97
shlq $0x20, %rbp
orq %r12, %rbp
movq %r13, %r12
movq 0x20(%r13), %rax
movq 0x18(%rsp), %rcx
movq %rbp, (%rax,%rcx,8)
movq %rbx, 0x8(%rsp)
movq (%r14), %rax
movl $0x1, %ebp
movq %r15, %r8
incq %r15
cmpq %rax, %r15
jbe 0xa9c4
movl 0x18(%r14), %ebx
movq %r12, 0x28(%r14)
cmpl 0x8(%rsp), %ebx
jne 0xab4b
movq 0x10(%r14), %rsi
xorl %edi, %edi
callq 0x12587
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movq $0x0, 0x10(%r14)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x22b1a(%rip), %rdi     # 0x2d64d
leaq 0x2277f(%rip), %rsi     # 0x2d2b9
leaq 0x22b27(%rip), %rcx     # 0x2d668
movl $0x101, %edx            # imm = 0x101
callq 0x21a0
leaq 0x22b3a(%rip), %rdi     # 0x2d68c
leaq 0x22760(%rip), %rsi     # 0x2d2b9
leaq 0x22b08(%rip), %rcx     # 0x2d668
movl $0x111, %edx            # imm = 0x111
callq 0x21a0