// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq $0x0, (%r8)
movl $0x0, (%r9)
xorl %r13d, %r13d
testl %esi, %esi
je 0x15711
movl %esi, %ebx
movq %rdi, %rbp
movq %r8, (%rsp)
movq %r9, 0x10(%rsp)
movl %ecx, 0x18(%rsp)
movslq %esi, %rsi
shlq $0x4, %rsi
addq %rdx, %rsi
movq %rdx, %rdi
movq %rdx, 0x8(%rsp)
callq 0xeec3
movq 0x8(%rsp), %r9
movl %ebx, %eax
movq %rax, 0x38(%rsp)
movl $0x0, %r10d
testl %ebx, %ebx
jle 0x1549b
movq 0x38(%rsp), %rax
shlq $0x4, %rax
leaq 0x10(%rax), %rcx
movl $0x1, %esi
xorl %edx, %edx
movl $0x10, %edi
xorl %r10d, %r10d
xorl %r13d, %r13d
cmpq %rdi, %rax
je 0x15481
movq -0x10(%r9,%rdi), %r8
xorq (%r9,%rdi), %r8
cmpq $0x100, %r8             # imm = 0x100
jae 0x15481
incl %esi
jmp 0x15492
incl %r13d
cmpl $0x2, %esi
cmovll %edx, %esi
addl %esi, %r10d
movl $0x1, %esi
addq $0x10, %rdi
cmpq %rdi, %rcx
jne 0x15466
movl $0x1, %r12d
movl $0x1, %esi
movl $0x20, %edx
movq %rbp, %rdi
movl %r10d, %r14d
callq 0x3054
movq %rax, %r15
movq %rbp, 0x18(%rax)
movq %rax, %rdi
movl %r13d, %esi
callq 0x15a6c
movl %r14d, 0x24(%rsp)
movslq %r14d, %r13
movl $0x8, %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3054
movq %rax, 0x28(%rsp)
movq (%rsp), %rcx
movq %rax, (%rcx)
movq 0x10(%rsp), %rax
movl %r13d, (%rax)
testl %ebx, %ebx
jle 0x15716
movl 0x18(%rsp), %eax
movq %rax, 0x18(%rsp)
incl %ebx
movq 0x8(%rsp), %r10
leaq 0x8(%r10), %rax
movq %rax, 0x40(%rsp)
movq $0x0, (%rsp)
movl $0x1, %r13d
xorl %edx, %edx
movq %rbx, 0x30(%rsp)
cmpq 0x38(%rsp), %r12
je 0x15552
movq %r12, %rax
shlq $0x4, %rax
movq -0x10(%r10,%rax), %rcx
xorq (%r10,%rax), %rcx
cmpq $0x100, %rcx            # imm = 0x100
jae 0x15552
incl %r13d
jmp 0x15703
movq %r12, %r14
shlq $0x4, %r14
movq -0x10(%r10,%r14), %rbx
shrq $0x8, %rbx
movq 0x18(%rsp), %rcx
shrq %cl, %rbx
cmpq $0x0, 0x10(%r15)
movq %rdx, 0x10(%rsp)
je 0x15582
movb (%r15), %cl
movl $0x1, %ebp
shll %cl, %ebp
jmp 0x15584
xorl %ebp, %ebp
movl %ebp, %eax
shrl %eax
movl %ebp, %ecx
shrl $0x2, %ecx
addl %eax, %ecx
cmpl %ecx, 0x4(%r15)
jb 0x155b7
leal 0x1(%rbp), %esi
movq %r15, %rdi
callq 0x15a6c
testl %eax, %eax
js 0x1563b
movb (%r15), %cl
movl $0x1, %ebp
shll %cl, %ebp
movq 0x8(%rsp), %r10
leaq (%rbx,%rbx), %rax
imull $0x9e3779b9, %ebx, %esi # imm = 0x9E3779B9
movb (%r15), %dl
xorl %ecx, %ecx
subb %dl, %cl
shrl %cl, %esi
movl %ebp, %ecx
decl %ecx
movq 0x8(%r15), %rdx
movl %esi, %ebp
movl %ebp, %edi
shrl $0x5, %edi
movl (%rdx,%rdi,4), %edi
btl %ebp, %edi
jae 0x15601
movq 0x10(%r15), %rdi
movl %ebp, %r8d
shlq $0x4, %r8
movq (%rdi,%r8), %rdi
xorq %rax, %rdi
cmpq $0x2, %rdi
jb 0x15601
incl %ebp
andl %ecx, %ebp
cmpl %esi, %ebp
jne 0x155d4
movl %ebp, %esi
shrl $0x5, %esi
movl (%rdx,%rsi,4), %edi
movl $0x1, %r8d
movl %ebp, %ecx
shll %cl, %r8d
btl %ebp, %edi
jae 0x1561d
xorl %eax, %eax
jmp 0x15642
movq 0x10(%r15), %rcx
movl %ebp, %r9d
shlq $0x4, %r9
movq %rax, (%rcx,%r9)
orl %edi, %r8d
movl %r8d, (%rdx,%rsi,4)
incl 0x4(%r15)
movb $0x1, %al
jmp 0x15642
movb $0x1, %al
movq 0x8(%rsp), %r10
movq 0x10(%rsp), %rcx
testb %al, %al
je 0x1573a
leal (%rcx,%r13), %eax
cmpq %rax, %r12
jne 0x1573a
movl %ebp, %ebp
cmpl $0x1, %r13d
jne 0x15688
addq %r10, %r14
movq 0x10(%r15), %rax
shlq $0x4, %rbp
orq $0x1, (%rax,%rbp)
movq -0x8(%r14), %rcx
movq %rcx, 0x8(%rax,%rbp)
movl $0x1, %r13d
movl %r12d, %edx
jmp 0x156fe
movslq (%rsp), %rbx
jl 0x156bd
movslq %ecx, %rax
movl %r13d, %ecx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rbx,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 0x156ac
movq 0x28(%rsp), %rcx
leaq (%rcx,%rbx,8), %rdi
leal (%rbx,%r13), %eax
movq %rax, (%rsp)
cltq
leaq (%rcx,%rax,8), %rsi
callq 0x48ff
shlq $0x20, %rbx
movslq %r13d, %rax
orq %rbx, %rax
movq 0x10(%r15), %rcx
shlq $0x4, %rbp
movq %rax, 0x8(%rcx,%rbp)
movl $0x1, %r13d
movl %r12d, %edx
movq 0x8(%rsp), %r10
movq 0x30(%rsp), %rbx
incq %r12
cmpq %rbx, %r12
jne 0x1552a
jmp 0x1571e
xorl %r15d, %r15d
jmp 0x15728
movq $0x0, (%rsp)
movq (%rsp), %rax
cmpl %eax, 0x24(%rsp)
jne 0x15759
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1398f(%rip), %rdi     # 0x290d0
leaq 0x139a3(%rip), %rsi     # 0x290eb
leaq 0x139a4(%rip), %rcx     # 0x290f3
movl $0x94, %edx
callq 0x2160
leaq 0x139dd(%rip), %rdi     # 0x2913d
leaq 0x13984(%rip), %rsi     # 0x290eb
leaq 0x13985(%rip), %rcx     # 0x290f3
movl $0xa3, %edx
callq 0x2160