// File: /workspace/github_c_makefile_star2_O2/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 0x19a90
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, 0x8(%rsp)
movss %xmm0, (%rsp)
callq 0x10afc
movq %rax, 0x10(%rsp)
imulq $0x50, 0x8(%rsp), %rsi
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
callq 0x10afc
movq 0x8(%rsp), %r8
movq %rax, 0x18(%rsp)
cvtss2sd (%rsp), %xmm0
movsd 0xc532(%rip), %xmm1     # 0x26010
subsd %xmm0, %xmm1
movq %r14, 0x20(%rsp)
addq $0x48, %r14
xorl %ebx, %ebx
pushq $0x1
popq %r9
movsd 0xc51f(%rip), %xmm2     # 0x26018
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
movsd %xmm1, (%rsp)
movslq %r12d, %r13
cmpq %rbx, %r8
je 0x19bc4
movl -0xc(%r14), %ecx
btl $0xb, %ecx
jb 0x19b23
cmpl $0x0, -0x44(%r14)
jle 0x19b99
movq (%r14), %rax
leaq 0x8(%rax), %rdx
leaq -0x3c(%r14), %rsi
testq %rax, %rax
cmovnel %r9d, %r15d
cmovel %r9d, %ebp
cmoveq %rsi, %rdx
movl (%rdx), %eax
btl $0x19, %ecx
setae %cl
testl %eax, %eax
sets %dl
orb %cl, %dl
jne 0x19b67
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
cvttsd2si %xmm0, %eax
cmpl $0x2, %eax
jge 0x19b67
movl %r9d, %eax
shlq $0x20, %rax
movl -0x8(%r14), %ecx
orq %rax, %rcx
movq %r13, %rax
shlq $0x4, %rax
movq 0x10(%rsp), %rdx
movq %rcx, (%rdx,%rax)
incl %r13d
movq %rbx, 0x8(%rdx,%rax)
movl %r13d, %r12d
incq %rbx
addq $0x50, %r14
jmp 0x19b06
movq (%r14), %rdi
testq %rdi, %rdi
je 0x19b8d
movl %r9d, %r13d
callq 0x2040
movsd 0xc467(%rip), %xmm2     # 0x26018
movl %r13d, %r9d
movsd (%rsp), %xmm1
movq 0x8(%rsp), %r8
andq $0x0, (%r14)
jmp 0x19b8d
addl %r15d, %ebp
cmpl $0x1, %ebp
jne 0x19c71
movq %r13, %rsi
shlq $0x4, %rsi
movq 0x10(%rsp), %rbx
addq %rbx, %rsi
movq %rbx, %rdi
callq 0x47dc
leal -0x1(%r13), %eax
movslq %eax, %r8
movq %r8, %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %r9
addq $0x8, %r9
pushq $0xa
popq %rax
movq 0x18(%rsp), %r14
movq %r14, %rdx
movq 0x30(%rsp), %rbx
movq 0x20(%rsp), %r10
testq %r8, %r8
js 0x19c34
imulq $0x50, (%r9), %rsi
addq %r10, %rsi
movq %rax, %rcx
movq %rdx, %rdi
rep  movsq (%rsi), %es:(%rdi)
decq %r8
addq $0x50, %rdx
addq $-0x10, %r9
jmp 0x19c12
imulq $0x50, %r13, %rdx
movq %r10, %rdi
movq %r14, %rsi
callq 0x22a0
movq 0x28(%rsp), %rax
movl %r13d, (%rax)
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x10a07
movq %rbx, %rdi
movq %r14, %rsi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x10a07
leaq 0xfcf4(%rip), %rdi      # 0x2996c
leaq 0xfd07(%rip), %rsi      # 0x29986
leaq 0xfd06(%rip), %rcx      # 0x2998c
movl $0xd2, %edx
callq 0x21a0