// File: /workspace/github_c_makefile_star2_O1/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 0x1c4a1
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 0x126e9
movq %rax, %r12
movq 0x10(%rsp), %rax
shlq $0x4, %rax
leaq (%rax,%rax,4), %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x126e9
movq 0x10(%rsp), %r8
movq %rax, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x8(%rsp), %xmm0
movsd 0xdb2f(%rip), %xmm1     # 0x2a028
subsd %xmm0, %xmm1
movq %r14, 0x20(%rsp)
addq $0x48, %r14
xorl %ebx, %ebx
movl $0x1, %r9d
movsd 0xdb0a(%rip), %xmm2     # 0x2a020
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %r13d, %r13d
movsd %xmm1, 0x8(%rsp)
movl -0xc(%r14), %ecx
btl $0xb, %ecx
jb 0x1c535
cmpl $0x0, -0x44(%r14)
jle 0x1c5b0
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 0x1c57e
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cmpl $0x2, %eax
jge 0x1c57e
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 0x1c524
jmp 0x1c5df
movq (%r14), %rdi
testq %rdi, %rdi
je 0x1c59e
callq 0x2040
movsd 0xda5b(%rip), %xmm2     # 0x2a020
movl $0x1, %r9d
movsd 0x8(%rsp), %xmm1
movq 0x10(%rsp), %r8
movq $0x0, (%r14)
jmp 0x1c59e
addl %r13d, %r15d
cmpl $0x1, %r15d
jne 0x1c6a2
movslq %ebp, %r14
movq %r14, %rbx
shlq $0x4, %rbx
leaq (%r12,%rbx), %rsi
movq %r12, %rdi
callq 0x5ae1
testl %r14d, %r14d
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %r14
jle 0x1c663
movl %ebp, %ecx
leaq 0x1(%rcx), %rdx
leaq (%rbx,%rbx,4), %rax
addq $-0x50, %rax
shlq $0x4, %rcx
leaq (%rcx,%rcx,4), %rsi
subq %rsi, %rax
addq %r14, %rax
addq $0x50, %rax
leaq (%r12,%rcx), %r8
addq $-0x8, %r8
movq (%r8), %rcx
leaq (%rcx,%rcx,4), %rsi
shlq $0x4, %rsi
addq %r9, %rsi
movl $0xa, %ecx
movq %rax, %rdi
rep  movsq (%rsi), %es:(%rdi)
decq %rdx
addq $0x50, %rax
addq $-0x10, %r8
cmpq $0x1, %rdx
jg 0x1c639
leaq (%rbx,%rbx,4), %rdx
movq %r9, %rdi
movq %r14, %rsi
callq 0x22a0
movq 0x28(%rsp), %rax
movl %ebp, (%rax)
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1261e
movq %rbx, %rdi
movq %r14, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1261e
leaq 0x11283(%rip), %rdi     # 0x2d92c
leaq 0x11296(%rip), %rsi     # 0x2d946
leaq 0x11295(%rip), %rcx     # 0x2d94c
movl $0xd2, %edx
callq 0x21a0