// File: /workspace/github_c_makefile_star2_O3/lh3[P]minimap2/hit.c
// Function: mm_hit_sort
void mm_hit_sort(void *km, int *n_regs, mm_reg1_t *r, float alt_diff_frac)
{
	int32_t i, n_aux, n = *n_regs, has_cigar = 0, no_cigar = 0;
	mm128_t *aux;
	mm_reg1_t *t;

	if (n <= 1) return;
	aux = (mm128_t*)kmalloc(km, n * 16);
	t = (mm_reg1_t*)kmalloc(km, n * sizeof(mm_reg1_t));
	for (i = n_aux = 0; i < n; ++i) {
		if (r[i].inv || r[i].cnt > 0) { // squeeze out elements with cnt==0 (soft deleted)
			int score;
			if (r[i].p) score = r[i].p->dp_max, has_cigar = 1;
			else score = r[i].score, no_cigar = 1;
			if (r[i].is_alt) score = mm_alt_score(score, alt_diff_frac);
			aux[n_aux].x = (uint64_t)score << 32 | r[i].hash;
			aux[n_aux++].y = i;
		} else if (r[i].p) {
			free(r[i].p);
			r[i].p = 0;
		}
	}
	assert(has_cigar + no_cigar == 1);
	radix_sort_128x(aux, aux + n_aux);
	for (i = n_aux - 1; i >= 0; --i)
		t[n_aux - 1 - i] = r[aux[i].y];
	memcpy(r, t, sizeof(mm_reg1_t) * n_aux);
	*n_regs = n_aux;
	kfree(km, aux);
	kfree(km, t);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movslq (%rsi), %rax
cmpq $0x2, %rax
jge 0x1c4b9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r14
movq %rdi, %rbx
movq %rsi, 0x28(%rsp)
movl %eax, %esi
shll $0x4, %esi
movq %rax, 0x10(%rsp)
movss %xmm0, 0x8(%rsp)
callq 0x1264d
movq %rax, %r12
movq 0x10(%rsp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,4), %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x1264d
movq 0x10(%rsp), %r8
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd 0xeb17(%rip), %xmm1     # 0x2b028
subsd %xmm0, %xmm1
movq %r14, 0x20(%rsp)
addq $0x48, %r14
xorl %ebx, %ebx
movl $0x1, %r9d
movsd 0xeaf2(%rip), %xmm2     # 0x2b020
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
movsd %xmm1, 0x8(%rsp)
movl -0xc(%r14), %ecx
btl $0xb, %ecx
jb 0x1c54d
cmpl $0x0, -0x44(%r14)
jle 0x1c5c8
movq (%r14), %rax
leaq 0x8(%rax), %rdx
leaq -0x3c(%r14), %rsi
testq %rax, %rax
cmovnel %r9d, %r13d
cmovel %r9d, %r15d
cmoveq %rsi, %rdx
movl (%rdx), %eax
btl $0x19, %ecx
setae %cl
testl %eax, %eax
sets %dl
orb %cl, %dl
jne 0x1c596
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cmpl $0x2, %eax
jge 0x1c596
movl $0x1, %eax
shlq $0x20, %rax
movl -0x8(%r14), %ecx
orq %rax, %rcx
movslq %ebp, %rbp
movq %rbp, %rax
shlq $0x4, %rax
movq %rcx, (%r12,%rax)
incl %ebp
movq %rbx, 0x8(%r12,%rax)
incq %rbx
addq $0x50, %r14
cmpq %rbx, %r8
jne 0x1c53c
jmp 0x1c5f7
movq (%r14), %rdi
testq %rdi, %rdi
je 0x1c5b6
callq 0x2040
movsd 0xea43(%rip), %xmm2     # 0x2b020
movl $0x1, %r9d
movsd 0x8(%rsp), %xmm1
movq 0x10(%rsp), %r8
movq $0x0, (%r14)
jmp 0x1c5b6
addl %r13d, %r15d
cmpl $0x1, %r15d
jne 0x1c6b7
movslq %ebp, %r14
movq %r14, %rbx
shlq $0x4, %rbx
leaq (%r12,%rbx), %rsi
movq %r12, %rdi
callq 0x5a49
testl %r14d, %r14d
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r15
jle 0x1c678
leal -0x1(%r14), %eax
incq %r14
shlq $0x4, %rax
leaq (%rax,%rax,4), %rax
leaq (%rbx,%rbx,4), %rcx
subq %rcx, %rax
addq %r15, %rax
addq $0x50, %rax
leaq (%r12,%rbx), %rdx
addq $-0x8, %rdx
movq (%rdx), %rcx
leaq (%rcx,%rcx,4), %rsi
shlq $0x4, %rsi
addq %r8, %rsi
movl $0xa, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
decq %r14
addq $0x50, %rax
addq $-0x10, %rdx
cmpq $0x1, %r14
jg 0x1c64e
leaq (%rbx,%rbx,4), %rdx
movq %r8, %rdi
movq %r15, %rsi
callq 0x22a0
movq 0x28(%rsp), %rax
movl %ebp, (%rax)
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12587
movq %rbx, %rdi
movq %r15, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x12587
leaq 0x12316(%rip), %rdi     # 0x2e9d4
leaq 0x12329(%rip), %rsi     # 0x2e9ee
leaq 0x12328(%rip), %rcx     # 0x2e9f4
movl $0xd2, %edx
callq 0x21a0