// File: /workspace/github_c_makefile_star2_O0/lh3[P]minimap2/map.c
// Function: collect_seed_hits_heap
static mm128_t *collect_seed_hits_heap(void *km, const mm_mapopt_t *opt, int max_occ, const mm_idx_t *mi, const char *qname, const mm128_v *mv, int qlen, int64_t *n_a, int *rep_len,
								  int *n_mini_pos, uint64_t **mini_pos)
{
	int i, n_m, heap_size = 0;
	int64_t j, n_for = 0, n_rev = 0;
	mm_seed_t *m;
	mm128_t *a, *heap;

	m = mm_collect_matches(km, &n_m, qlen, max_occ, opt->max_max_occ, opt->occ_dist, mi, mv, n_a, rep_len, n_mini_pos, mini_pos);

	heap = (mm128_t*)kmalloc(km, n_m * sizeof(mm128_t));
	a = (mm128_t*)kmalloc(km, *n_a * sizeof(mm128_t));

	for (i = 0, heap_size = 0; i < n_m; ++i) {
		if (m[i].n > 0) {
			heap[heap_size].x = m[i].cr[0];
			heap[heap_size].y = (uint64_t)i<<32;
			++heap_size;
		}
	}
	ks_heapmake_heap(heap_size, heap);
	while (heap_size > 0) {
		mm_seed_t *q = &m[heap->y>>32];
		mm128_t *p;
		uint64_t r = heap->x;
		int32_t is_self, rpos = (uint32_t)r >> 1;
		if (!skip_seed(opt->flag, r, q, qname, qlen, mi, &is_self)) {
			if ((r&1) == (q->q_pos&1)) { // forward strand
				p = &a[n_for++];
				p->x = (r&0xffffffff00000000ULL) | rpos;
				p->y = (uint64_t)q->q_span << 32 | q->q_pos >> 1;
			} else { // reverse strand
				p = &a[(*n_a) - (++n_rev)];
				p->x = 1ULL<<63 | (r&0xffffffff00000000ULL) | rpos;
				p->y = (uint64_t)q->q_span << 32 | (qlen - ((q->q_pos>>1) + 1 - q->q_span) - 1);
			}
			p->y |= (uint64_t)q->seg_id << MM_SEED_SEG_SHIFT;
			if (q->is_tandem) p->y |= MM_SEED_TANDEM;
			if (is_self) p->y |= MM_SEED_SELF;
		}
		// update the heap
		if ((uint32_t)heap->y < q->n - 1) {
			++heap[0].y;
			heap[0].x = m[heap[0].y>>32].cr[(uint32_t)heap[0].y];
		} else {
			heap[0] = heap[heap_size - 1];
			--heap_size;
		}
		ks_heapdown_heap(0, heap_size, heap);
	}
	kfree(km, m);
	kfree(km, heap);

	// reverse anchors on the reverse strand, as they are in the descending order
	for (j = 0; j < n_rev>>1; ++j) {
		mm128_t t = a[(*n_a) - 1 - j];
		a[(*n_a) - 1 - j] = a[(*n_a) - (n_rev - j)];
		a[(*n_a) - (n_rev - j)] = t;
	}
	if (*n_a > n_for + n_rev) {
		memmove(a + n_for, a + (*n_a) - n_rev, n_rev * sizeof(mm128_t));
		*n_a = n_for + n_rev;
	}
	return a;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xd8, %rsp
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movl %edx, -0x2c(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movq %r9, -0x48(%rbp)
movl $0x0, -0x54(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movl 0x10(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl 0xdc(%rax), %r8d
movq -0x28(%rbp), %rax
movl 0xe0(%rax), %r9d
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %r14
movq 0x18(%rbp), %rbx
movq 0x20(%rbp), %r11
movq 0x28(%rbp), %r10
movq 0x30(%rbp), %rax
leaq -0x50(%rbp), %rsi
movq %r15, (%rsp)
movq %r14, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
movq %r11, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movq %rax, 0x28(%rsp)
callq 0x2d1b0
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x50(%rbp), %rsi
shlq $0x4, %rsi
callq 0x1aae0
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
movq 0x18(%rbp), %rax
movq (%rax), %rsi
shlq $0x4, %rsi
callq 0x1aae0
movq %rax, -0x80(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x10ecc
movq -0x78(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jbe 0x10ebf
movq -0x78(%rbp), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rcx
movq -0x88(%rbp), %rax
movslq -0x54(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x4c(%rbp), %rcx
shlq $0x20, %rcx
movq -0x88(%rbp), %rax
movslq -0x54(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x10ec1
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x10e51
movslq -0x54(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0xf1b0
cmpl $0x0, -0x54(%rbp)
jle 0x111e8
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
shrl %eax
movl %eax, -0xa8(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
movq -0xa0(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x40(%rbp), %rcx
movl 0x10(%rbp), %r8d
movq -0x38(%rbp), %r9
leaq -0xa4(%rbp), %rax
movq %rax, (%rsp)
callq 0x13140
cmpl $0x0, %eax
jne 0x11131
movq -0xa0(%rbp), %rax
andq $0x1, %rax
movq -0x90(%rbp), %rcx
movl 0x4(%rcx), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
jne 0x11006
movq -0x80(%rbp), %rax
movq -0x68(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x68(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq -0xa0(%rbp), %rcx
movslq -0xa8(%rbp), %rax
orq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
shlq $0x20, %rcx
movq -0x90(%rbp), %rax
movl 0x4(%rax), %eax
shrl %eax
movl %eax, %eax
orq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x110b4
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
movq -0x70(%rbp), %rdx
addq $0x1, %rdx
movq %rdx, -0x70(%rbp)
subq %rdx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
andq -0xa0(%rbp), %rcx
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %rcx
movslq -0xa8(%rbp), %rax
orq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
shlq $0x20, %rcx
movl 0x10(%rbp), %eax
movq -0x90(%rbp), %rdx
movl 0x4(%rdx), %edx
shrl %edx
addl $0x1, %edx
movq -0x90(%rbp), %rsi
movq 0x8(%rsi), %rsi
andq $0x7fffffff, %rsi       # imm = 0x7FFFFFFF
subl %esi, %edx
subl %edx, %eax
subl $0x1, %eax
movl %eax, %eax
orq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
shlq $0x30, %rcx
movq -0x98(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0x1110d
movq -0x98(%rbp), %rax
movabsq $0x40000000000, %rcx    # imm = 0x40000000000
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
cmpl $0x0, -0xa4(%rbp)
je 0x1112f
movq -0x98(%rbp), %rax
movabsq $0x80000000000, %rcx    # imm = 0x80000000000
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x11131
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x90(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x1119a
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x78(%rbp), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq -0x88(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
jmp 0x111cf
movq -0x88(%rbp), %rax
movq -0x88(%rbp), %rcx
movl -0x54(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x54(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x54(%rbp)
movslq -0x54(%rbp), %rsi
movq -0x88(%rbp), %rdx
xorl %eax, %eax
movl %eax, %edi
callq 0xf0a0
jmp 0x10edc
movq -0x20(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x1a8c0
movq -0x20(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1a8c0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x70(%rbp), %rcx
sarq %rcx
cmpq %rcx, %rax
jge 0x112d8
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
subq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
subq $0x1, %rcx
subq -0x60(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x80(%rbp), %rcx
movq 0x18(%rbp), %rdx
movq (%rdx), %rdx
movq -0x70(%rbp), %rsi
subq -0x60(%rbp), %rsi
subq %rsi, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rax
movq 0x18(%rbp), %rcx
movq (%rcx), %rcx
movq -0x70(%rbp), %rdx
subq -0x60(%rbp), %rdx
subq %rdx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0xb8(%rbp), %rcx
movq %rcx, (%rax)
movq -0xb0(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1120d
movq 0x18(%rbp), %rax
movq (%rax), %rax
movq -0x68(%rbp), %rcx
addq -0x70(%rbp), %rcx
cmpq %rcx, %rax
jle 0x11336
movq -0x80(%rbp), %rdi
movq -0x68(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq -0x80(%rbp), %rsi
movq 0x18(%rbp), %rax
movq (%rax), %rax
shlq $0x4, %rax
addq %rax, %rsi
xorl %eax, %eax
subq -0x70(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movq -0x70(%rbp), %rdx
shlq $0x4, %rdx
callq 0x2330
movq -0x68(%rbp), %rcx
addq -0x70(%rbp), %rcx
movq 0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x80(%rbp), %rax
addq $0xd8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)