// File: /workspace/github_c_makefile_star2_O0/lh3[P]minigraph/index.c
// Function: mg_idx_a2h
void *mg_idx_a2h(void *km, int32_t n_a, mg128_t *a, int suflen, uint64_t **q_, int32_t *n_)
{
	int32_t N, n, n_keys;
	int32_t j, start_a, start_q;
	idxhash_t *h;
	uint64_t *q;

	*q_ = 0, *n_ = 0;
	if (n_a == 0) return 0;

	// sort by minimizer
	radix_sort_128x(a, a + n_a);

	// count and preallocate
	for (j = 1, n = 1, n_keys = 0, N = 0; j <= n_a; ++j) {
		if (j == n_a || a[j].x>>8 != a[j-1].x>>8) {
			++n_keys;
			if (n > 1) N += n;
			n = 1;
		} else ++n;
	}
	h = mg_hidx_init2(km);
	mg_hidx_resize(h, n_keys);
	KCALLOC(km, q, N);
	*q_ = q, *n_ = N;

	// create the hash table
	for (j = 1, n = 1, start_a = start_q = 0; j <= n_a; ++j) {
		if (j == n_a || a[j].x>>8 != a[j-1].x>>8) {
			khint_t itr;
			int absent;
			mg128_t *p = &a[j-1];
			itr = mg_hidx_put(h, p->x>>8>>suflen<<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)
					q[start_q + k] = a[start_a + k].y;
				radix_sort_gfa64(&q[start_q], &q[start_q + n]); // sort by position; needed as in-place radix_sort_128x() is not stable
				kh_val(h, itr) = (uint64_t)start_q<<32 | n;
				start_q += n;
			}
			start_a = j, n = 1;
		} else ++n;
	}
	assert(N == start_q);
	return h;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x38(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, -0x14(%rbp)
jne 0x209a9
movq $0x0, -0x8(%rbp)
jmp 0x20caf
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x14(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x15f50
movl $0x1, -0x48(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x20a5a
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x20a23
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x8, %rax
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
je 0x20a44
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x40(%rbp)
jle 0x20a3b
movl -0x40(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x20a4d
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x20a4f
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x209dd
movq -0x10(%rbp), %rdi
callq 0x20cc0
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x20ce0
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
movl $0x8, %edx
callq 0x2540
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x48(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
jg 0x20c7e
movl -0x48(%rbp), %eax
cmpl -0x14(%rbp), %eax
je 0x20b07
movq -0x20(%rbp), %rax
movslq -0x48(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x8, %rax
movq -0x20(%rbp), %rcx
movl -0x48(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x8, %rcx
cmpq %rcx, %rax
je 0x20c65
movq -0x20(%rbp), %rax
movl -0x48(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x58(%rbp), %rdi
movq -0x70(%rbp), %rax
movq (%rax), %rsi
shrq $0x8, %rsi
movl -0x24(%rbp), %eax
movl %eax, %ecx
shrq %cl, %rsi
shlq %rsi
leaq -0x68(%rbp), %rdx
callq 0x20d10
movl %eax, -0x64(%rbp)
cmpl $0x0, -0x68(%rbp)
je 0x20b5a
movl -0x48(%rbp), %eax
movl -0x4c(%rbp), %ecx
addl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jne 0x20b5a
jmp 0x20b79
leaq 0x1c4ef(%rip), %rdi     # 0x3d050
leaq 0x1c503(%rip), %rsi     # 0x3d06b
movl $0x94, %edx
leaq 0x1c4ff(%rip), %rcx     # 0x3d073
callq 0x2170
cmpl $0x1, -0x40(%rbp)
jne 0x20bbe
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
orq $0x1, %rcx
movq %rcx, (%rax)
movq -0x70(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x20c56
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x20c01
movq -0x20(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl -0x74(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq -0x60(%rbp), %rax
movl -0x50(%rbp), %ecx
addl -0x74(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x20bc5
movq -0x60(%rbp), %rdi
movslq -0x50(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x60(%rbp), %rsi
movl -0x50(%rbp), %eax
addl -0x40(%rbp), %eax
cltq
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5440
movslq -0x50(%rbp), %rcx
shlq $0x20, %rcx
movslq -0x40(%rbp), %rax
orq %rax, %rcx
movq -0x58(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x64(%rbp), %edx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x40(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x20c6e
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x20c70
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x20ab9
movl -0x3c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jne 0x20c88
jmp 0x20ca7
leaq 0x1c42e(%rip), %rdi     # 0x3d0bd
leaq 0x1c3d5(%rip), %rsi     # 0x3d06b
movl $0xa3, %edx
leaq 0x1c3d1(%rip), %rcx     # 0x3d073
callq 0x2170
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)