// File: /workspace/github_c_makefile_star2_O1/lh3[P]minimap2/seed.c
// Function: mm_seed_select
void mm_seed_select(int32_t n, mm_seed_t *a, int len, int max_occ, int max_max_occ, int dist)
{ // for high-occ minimizers, choose up to max_high_occ in each high-occ streak
	extern void ks_heapdown_uint64_t(size_t i, size_t n, uint64_t*);
	extern void ks_heapmake_uint64_t(size_t n, uint64_t*);
	int32_t i, last0, m;
	uint64_t b[MAX_MAX_HIGH_OCC]; // this is to avoid a heap allocation

	if (n == 0 || n == 1) return;
	for (i = m = 0; i < n; ++i)
		if (a[i].n > max_occ) ++m;
	if (m == 0) return; // no high-frequency k-mers; do nothing
	for (i = 0, last0 = -1; i <= n; ++i) {
		if (i == n || a[i].n <= max_occ) {
			if (i - last0 > 1) {
				int32_t ps = last0 < 0? 0 : (uint32_t)a[last0].q_pos>>1;
				int32_t pe = i == n? len : (uint32_t)a[i].q_pos>>1;
				int32_t j, k, st = last0 + 1, en = i;
				int32_t max_high_occ = (int32_t)((double)(pe - ps) / dist + .499);
				if (max_high_occ > 0) {
					if (max_high_occ > MAX_MAX_HIGH_OCC)
						max_high_occ = MAX_MAX_HIGH_OCC;
					for (j = st, k = 0; j < en && k < max_high_occ; ++j, ++k)
						b[k] = (uint64_t)a[j].n<<32 | j;
					ks_heapmake_uint64_t(k, b); // initialize the binomial heap
					for (; j < en; ++j) { // if there are more, choose top max_high_occ
						if (a[j].n < (int32_t)(b[0]>>32)) { // then update the heap
							b[0] = (uint64_t)a[j].n<<32 | j;
							ks_heapdown_uint64_t(0, k, b);
						}
					}
					for (j = 0; j < k; ++j) a[(uint32_t)b[j]].flt = 1;
				}
				for (j = st; j < en; ++j) a[j].flt ^= 1;
				for (j = st; j < en; ++j)
					if (a[j].n > max_max_occ)
						a[j].flt = 1;
			}
			last0 = i;
		}
	}
}

// Assembly:
cmpl $0x2, %edi
jb 0x1db08
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movl %edi, %r15d
testl %edi, %edi
jle 0x1d8e9
leaq (,%r15,8), %rax
leaq (%rax,%rax,2), %rax
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpl (%rsi,%r10), %ecx
adcl $0x0, %r11d
addq $0x18, %r10
cmpq %r10, %rax
jne 0x1d8d0
testl %r11d, %r11d
sete %al
jmp 0x1d8eb
movb $0x1, %al
testl %edi, %edi
sets %r10b
orb %al, %r10b
jne 0x1daf7
cvtsi2sd %r9d, %xmm0
movsd %xmm0, 0x38(%rsp)
movl $0x80000000, %r13d      # imm = 0x80000000
incl %edi
leaq 0x8(%rsi), %rax
movq %rax, 0x20(%rsp)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl %r8d, 0x14(%rsp)
movl %ecx, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x30(%rsp)
movq %r15, 0x28(%rsp)
cmpq %r15, %r12
je 0x1d94c
leaq (%r12,%r12,2), %rax
cmpl %ecx, (%rsi,%rax,8)
ja 0x1daeb
movl %r12d, %eax
subl %ebx, %eax
cmpl $0x2, %eax
jl 0x1dae8
testl %ebx, %ebx
js 0x1d96c
movl %ebx, %eax
leaq (%rax,%rax,2), %rax
movl 0x4(%rsi,%rax,8), %eax
shrl %eax
jmp 0x1d96e
xorl %eax, %eax
movl %edx, %r9d
cmpq %r15, %r12
je 0x1d982
leaq (%r12,%r12,2), %r9
movl 0x4(%rsi,%r9,8), %r9d
shrl %r9d
subl %eax, %r9d
incl %ebx
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
divsd 0x38(%rsp), %xmm0
addsd 0xc683(%rip), %xmm0     # 0x2a020
cvttsd2si %xmm0, %eax
movslq %ebx, %rbp
testl %eax, %eax
jle 0x1da85
xorl %ecx, %ecx
cmpq %rbp, %r12
jle 0x1d9f5
movl $0x80, %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
leaq (%rsi,%rcx,8), %rdx
movq %rbp, %rsi
xorl %ecx, %ecx
movl (%rdx), %edi
shlq $0x20, %rdi
orq %rsi, %rdi
movq %rdi, 0x40(%rsp,%rcx,8)
incq %rsi
incq %rcx
cmpq %r12, %rsi
jge 0x1d9f3
addq $0x18, %rdx
cmpq %rax, %rcx
jb 0x1d9d1
addl %ecx, %ebx
movl %ecx, %r14d
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
callq 0x5f59
movslq %ebx, %rbx
cmpq %rbx, %r12
jle 0x1da4c
leaq (%rbx,%rbx,2), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax,8), %r15
movl (%r15), %eax
cmpl 0x44(%rsp), %eax
jae 0x1da3e
shlq $0x20, %rax
orq %rbx, %rax
movq %rax, 0x40(%rsp)
xorl %edi, %edi
movq %r14, %rsi
leaq 0x40(%rsp), %rdx
callq 0x5efb
incq %rbx
movl %ebx, %eax
addq $0x18, %r15
cmpq %r12, %rax
jne 0x1da1a
testq %r14, %r14
movl 0x14(%rsp), %r8d
movl 0x10(%rsp), %ecx
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rsi
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %r15
je 0x1da85
xorl %eax, %eax
movl 0x40(%rsp,%rax,8), %r9d
leaq (%r9,%r9,2), %r9
orq %r13, 0x8(%rsi,%r9,8)
incq %rax
cmpq %rax, %r14
jne 0x1da6f
cmpq %rbp, %r12
jle 0x1dab4
leaq (,%rbp,2), %rax
addq %rbp, %rax
movq 0x20(%rsp), %r9
leaq (%r9,%rax,8), %rax
leaq 0x1(%rbp), %r9
xorq %r13, (%rax)
movl %r9d, %r10d
addq $0x18, %rax
incq %r9
cmpq %r12, %r10
jne 0x1daa2
cmpq %rbp, %r12
jle 0x1dae8
leaq (,%rbp,2), %rax
addq %rbp, %rax
movq 0x20(%rsp), %r9
leaq (%r9,%rax,8), %rax
incq %rbp
cmpl %r8d, -0x8(%rax)
jbe 0x1dad9
orq %r13, (%rax)
movl %ebp, %r9d
addq $0x18, %rax
incq %rbp
cmpq %r12, %r9
jne 0x1dad0
movl %r12d, %ebx
incq %r12
cmpq %rdi, %r12
jne 0x1d93a
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq