// File: /workspace/github_c_makefile_star2_O3/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
movq $0x0, (%r8)
movl $0x0, (%r9)
xorl %r13d, %r13d
testl %esi, %esi
je 0x159b4
movq %rdx, %rbx
movl %esi, %eax
movq %rdi, %rbp
movq %r8, 0x20(%rsp)
movq %r9, 0x8(%rsp)
movl %ecx, 0x18(%rsp)
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rdx, %rsi
movq %rdx, %rdi
movq %rax, %r15
callq 0xf27f
movl %r15d, %eax
movq %rax, 0x28(%rsp)
movl $0x0, %r14d
movq %r15, 0x10(%rsp)
testl %r15d, %r15d
jle 0x15722
movq 0x28(%rsp), %rax
shlq $0x4, %rax
leaq 0x10(%rax), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl $0x10, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %rdi, %rax
je 0x15708
movq -0x10(%rbx,%rdi), %r8
xorq (%rbx,%rdi), %r8
cmpq $0x100, %r8             # imm = 0x100
jae 0x15708
incl %esi
jmp 0x15719
incl %r13d
cmpl $0x2, %esi
cmovll %edx, %esi
addl %esi, %r14d
movl $0x1, %esi
addq $0x10, %rdi
cmpq %rdi, %rcx
jne 0x156ed
movl $0x1, %r12d
movl $0x1, %esi
movl $0x20, %edx
movq %rbp, %rdi
callq 0x2f84
movq %rax, %r15
movq %rbp, 0x18(%rax)
movq %rax, %rdi
movl %r13d, %esi
callq 0x15d1f
movl %r14d, 0x34(%rsp)
movslq %r14d, %r13
movl $0x8, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x2f84
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %rcx
movq %rax, (%rcx)
movq 0x8(%rsp), %rax
movl %r13d, (%rax)
movq 0x10(%rsp), %rdx
testl %edx, %edx
jle 0x159b9
movl 0x18(%rsp), %eax
movq %rax, 0x20(%rsp)
incl %edx
movq 0x28(%rsp), %rax
shlq $0x4, %rax
addq %rbx, %rax
movq %rax, 0x50(%rsp)
leaq -0x8(%rbx), %rax
movq %rax, 0x48(%rsp)
movq %rbx, 0x18(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x8(%rsp)
movl $0x1, %r14d
xorl %r13d, %r13d
movq %rdx, 0x10(%rsp)
cmpq 0x28(%rsp), %r12
jne 0x157e2
movq 0x50(%rsp), %rax
movq -0x10(%rax), %rbx
jmp 0x1580a
movq %r12, %rax
shlq $0x4, %rax
movq 0x18(%rsp), %rcx
movq -0x10(%rcx,%rax), %rbx
movq (%rcx,%rax), %rax
xorq %rbx, %rax
cmpq $0x100, %rax            # imm = 0x100
jae 0x1580a
incl %r14d
jmp 0x159a6
shrq $0x8, %rbx
movq 0x20(%rsp), %rcx
shrq %cl, %rbx
cmpq $0x0, 0x10(%r15)
je 0x15829
movb (%r15), %cl
movl $0x1, %ebp
shll %cl, %ebp
jmp 0x1582b
xorl %ebp, %ebp
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%r15)
jae 0x15841
movl (%r15), %ecx
jmp 0x1585e
leal 0x1(%rbp), %esi
movq %r15, %rdi
callq 0x15d1f
testl %eax, %eax
js 0x158e7
movl (%r15), %ecx
movl $0x1, %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(%r15), %rax
movl %ebp, %ecx
movl %ecx, %esi
shrl $0x5, %esi
movl (%rax,%rsi,4), %r8d
movl $0x1, %edi
shll %cl, %edi
btl %ecx, %r8d
jae 0x158c3
movq 0x10(%r15), %r10
movl %ecx, %r11d
shlq $0x4, %r11
movq (%r10,%r11), %r10
xorq %rdx, %r10
cmpq $0x2, %r10
jb 0x158c3
incl %ecx
andl %r9d, %ecx
cmpl %ebp, %ecx
jne 0x15878
movl %ebp, %esi
shrl $0x5, %esi
movl $0x1, %edi
movl %ebp, %ecx
shll %cl, %edi
movl (%rax,%rsi,4), %r8d
jmp 0x158c5
movl %ecx, %ebp
testl %r8d, %edi
jne 0x159df
movq 0x10(%r15), %rcx
movl %ebp, %r9d
shlq $0x4, %r9
movq %rdx, (%rcx,%r9)
orl %r8d, %edi
movl %edi, (%rax,%rsi,4)
incl 0x4(%r15)
leal (%r14,%r13), %eax
cmpq %rax, %r12
jne 0x159df
movl %ebp, %ebx
cmpl $0x1, %r14d
jne 0x15920
movq 0x10(%r15), %rax
shlq $0x4, %rbx
orq $0x1, (%rax,%rbx)
movq %r12, %rcx
shlq $0x4, %rcx
movq 0x48(%rsp), %rdx
movq (%rdx,%rcx), %rcx
movq %rcx, 0x8(%rax,%rbx)
jmp 0x15998
jl 0x1595d
movslq %r13d, %rax
movslq 0x8(%rsp), %r13
movl %r14d, %ecx
movq 0x38(%rsp), %rdx
leaq (%rdx,%r13,8), %rdx
shlq $0x4, %rax
addq 0x40(%rsp), %rax
shlq $0x3, %rcx
xorl %esi, %esi
movq (%rax,%rsi,2), %rdi
movq %rdi, (%rdx,%rsi)
addq $0x8, %rsi
cmpq %rsi, %rcx
jne 0x15945
movq 0x8(%rsp), %rax
jmp 0x15965
movq 0x8(%rsp), %rax
movslq %eax, %r13
movq 0x38(%rsp), %rcx
leaq (%rcx,%r13,8), %rdi
addl %r14d, %eax
movq %rax, 0x8(%rsp)
cltq
leaq (%rcx,%rax,8), %rsi
callq 0x47e4
shlq $0x20, %r13
movslq %r14d, %rax
orq %r13, %rax
movq 0x10(%r15), %rcx
shlq $0x4, %rbx
movq %rax, 0x8(%rcx,%rbx)
movl $0x1, %r14d
movl %r12d, %r13d
movq 0x10(%rsp), %rdx
incq %r12
cmpq %rdx, %r12
jne 0x157d0
jmp 0x159c2
xorl %r15d, %r15d
jmp 0x159cd
movq $0x0, 0x8(%rsp)
movq 0x8(%rsp), %rax
cmpl %eax, 0x34(%rsp)
jne 0x159fe
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1373a(%rip), %rdi     # 0x29120
leaq 0x1374e(%rip), %rsi     # 0x2913b
leaq 0x1374f(%rip), %rcx     # 0x29143
movl $0x94, %edx
callq 0x2160
leaq 0x13788(%rip), %rdi     # 0x2918d
leaq 0x1372f(%rip), %rsi     # 0x2913b
leaq 0x13730(%rip), %rcx     # 0x29143
movl $0xa3, %edx
callq 0x2160