// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
andq $0x0, (%r8)
andl $0x0, (%r9)
xorl %r14d, %r14d
testl %esi, %esi
je 0x12baf
movq %rdx, %rbx
movl %esi, %r15d
movq %rdi, %rbp
movq %r8, 0x10(%rsp)
movl %ecx, 0x4(%rsp)
movq %r9, 0x8(%rsp)
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rdx, %rsi
movq %rdx, %rdi
callq 0xcb7f
movl %r15d, %eax
testl %r15d, %r15d
cmovlel %r14d, %r15d
leal 0x1(%r15), %ecx
movq %rcx, 0x50(%rsp)
shlq $0x4, %r15
movq %rax, 0x48(%rsp)
shlq $0x4, %rax
movq %rax, 0x20(%rsp)
addq $-0x10, %rax
pushq $0x1
popq %rcx
xorl %edx, %edx
xorl %r13d, %r13d
movl %ecx, %esi
xorl %r12d, %r12d
cmpq %rdx, %r15
je 0x1293f
cmpq %rdx, %rax
je 0x1292a
movq (%rbx,%rdx), %rdi
xorq 0x10(%rbx,%rdx), %rdi
cmpq $0x100, %rdi            # imm = 0x100
jae 0x1292a
incl %esi
jmp 0x12939
incl %r13d
cmpl $0x2, %esi
cmovll %r14d, %esi
addl %esi, %r12d
movl %ecx, %esi
addq $0x10, %rdx
jmp 0x1290a
pushq $0x1
popq %r15
pushq $0x20
popq %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x24f0
movq %rax, %r14
movq %rbp, 0x18(%rax)
movq %rax, %rdi
movl %r13d, %esi
callq 0x12f56
movl %r12d, 0x1c(%rsp)
movslq %r12d, %r13
pushq $0x8
popq %rdx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x24f0
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movl %r13d, (%rax)
movl 0x4(%rsp), %eax
movq %rax, 0x10(%rsp)
addq %rbx, 0x20(%rsp)
leaq -0x8(%rbx), %rax
movq %rax, 0x38(%rsp)
movq %rbx, 0x40(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x30(%rsp)
pushq $0x1
popq %r13
movq $0x0, 0x8(%rsp)
movl $0x0, 0x4(%rsp)
movl %r13d, %r12d
cmpq 0x50(%rsp), %r15
je 0x12ba5
cmpq 0x48(%rsp), %r15
jne 0x129e8
movq 0x20(%rsp), %rax
movq -0x10(%rax), %rbx
jmp 0x12a10
movq %r15, %rax
shlq $0x4, %rax
movq 0x40(%rsp), %rcx
movq -0x10(%rcx,%rax), %rbx
movq (%rcx,%rax), %rax
xorq %rbx, %rax
cmpq $0x100, %rax            # imm = 0x100
jae 0x12a10
incl %r12d
jmp 0x12b9d
shrq $0x8, %rbx
movq 0x10(%rsp), %rcx
shrq %cl, %rbx
cmpq $0x0, 0x10(%r14)
je 0x12a2d
movb (%r14), %cl
movl %r13d, %ebp
shll %cl, %ebp
jmp 0x12a2f
xorl %ebp, %ebp
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%r14)
jae 0x12a45
movl (%r14), %ecx
jmp 0x12a60
leal 0x1(%rbp), %esi
movq %r14, %rdi
callq 0x12f56
testl %eax, %eax
js 0x12ae5
movl (%r14), %ecx
movl %r13d, %ebp
shll %cl, %ebp
movl %ebp, %r9d
imull $0x9e3779b9, %ebx, %ebp # imm = 0x9E3779B9
negb %cl
shrl %cl, %ebp
leaq (%rbx,%rbx), %rdx
decl %r9d
movq 0x8(%r14), %rax
movl %ebp, %ecx
movl %ecx, %esi
shrl $0x5, %esi
movl (%rax,%rsi,4), %r8d
movl %r13d, %edi
shll %cl, %edi
btl %ecx, %r8d
jae 0x12ac1
movq 0x10(%r14), %r10
movl %ecx, %r11d
shlq $0x4, %r11
movq (%r10,%r11), %r10
xorq %rdx, %r10
cmpq $0x2, %r10
jb 0x12ac1
incl %ecx
andl %r9d, %ecx
cmpl %ebp, %ecx
jne 0x12a7a
movl %ebp, %esi
shrl $0x5, %esi
movl %r13d, %edi
movl %ebp, %ecx
shll %cl, %edi
movl (%rax,%rsi,4), %r8d
jmp 0x12ac3
movl %ecx, %ebp
testl %r8d, %edi
jne 0x12bc1
movq 0x10(%r14), %rcx
movl %ebp, %r9d
shlq $0x4, %r9
movq %rdx, (%rcx,%r9)
orl %r8d, %edi
movl %edi, (%rax,%rsi,4)
incl 0x4(%r14)
movq 0x8(%rsp), %rax
addl %r12d, %eax
cmpq %rax, %r15
jne 0x12bc1
movl %ebp, %ebx
cmpl $0x1, %r12d
jne 0x12b22
movq 0x10(%r14), %rax
shlq $0x4, %rbx
orq $0x1, (%rax,%rbx)
movq %r15, %rcx
shlq $0x4, %rcx
movq 0x38(%rsp), %rdx
movq (%rdx,%rcx), %rcx
movq %rcx, 0x8(%rax,%rbx)
jmp 0x12b92
movslq 0x4(%rsp), %rbp
movslq 0x8(%rsp), %rax
movl $0x0, %ecx
cmovgel %r12d, %ecx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rbp,8), %rdi
shlq $0x3, %rcx
shlq $0x4, %rax
addq 0x30(%rsp), %rax
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x12b60
movq (%rax,%rdx,2), %rsi
movq %rsi, (%rdi,%rdx)
addq $0x8, %rdx
jmp 0x12b4d
movl 0x4(%rsp), %eax
addl %r12d, %eax
movl %eax, 0x4(%rsp)
cltq
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
callq 0x3d53
shlq $0x20, %rbp
movslq %r12d, %rax
orq %rbp, %rax
movq 0x10(%r14), %rcx
shlq $0x4, %rbx
movq %rax, 0x8(%rcx,%rbx)
movl %r15d, %eax
movq %rax, 0x8(%rsp)
movl %r13d, %r12d
incq %r15
jmp 0x129cb
movl 0x4(%rsp), %eax
cmpl %eax, 0x1c(%rsp)
jne 0x12be0
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11568(%rip), %rdi     # 0x24130
leaq 0x1157c(%rip), %rsi     # 0x2414b
leaq 0x1157d(%rip), %rcx     # 0x24153
movl $0x94, %edx
callq 0x2160
leaq 0x115b6(%rip), %rdi     # 0x2419d
leaq 0x1155d(%rip), %rsi     # 0x2414b
leaq 0x1155e(%rip), %rcx     # 0x24153
movl $0xa3, %edx
callq 0x2160