// File: /workspace/github_c_makefile_star2_O0/lh3[P]miniprot/hit.c
// Function: mp_sort_reg
void mp_sort_reg(void *km, int *n_regs, mp_reg1_t *r)
{
	int32_t i, n_aux, n = *n_regs, has_cigar = 0, no_cigar = 0;
	mp128_t *aux;
	mp_reg1_t *t;

	if (n <= 1) return;
	aux = (mp128_t*)kmalloc(km, n * 16);
	t = (mp_reg1_t*)kmalloc(km, n * sizeof(mp_reg1_t));
	for (i = n_aux = 0; i < n; ++i) {
		if (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].chn_sc, no_cigar = 1;
			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); free(r[i].feat);
			r[i].p = 0;
		}
	}
	assert(has_cigar + no_cigar == 1);
	radix_sort_mp128x(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(mp_reg1_t) * n_aux);
	*n_regs = n_aux;
	kfree(km, aux);
	kfree(km, t);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
cmpl $0x1, -0x24(%rbp)
jg 0x1a846
jmp 0x1aa8a
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %eax
shll $0x4, %eax
movslq %eax, %rsi
callq 0xaeb0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0x68, %rax, %rsi
callq 0xaeb0
movq %rax, -0x40(%rbp)
movl $0x0, -0x20(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1a9b9
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jle 0x1a94a
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x60(%rax)
je 0x1a8dc
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x28(%rbp)
jmp 0x1a8f8
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movl 0x24(%rax), %eax
movl %eax, -0x44(%rbp)
movl $0x1, -0x2c(%rbp)
movslq -0x44(%rbp), %rcx
shlq $0x20, %rcx
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rdx
imulq $0x68, %rdx, %rdx
addq %rdx, %rax
movl 0x2c(%rax), %eax
orq %rax, %rcx
movq -0x38(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x1c(%rbp), %rcx
movq -0x38(%rbp), %rax
movl -0x20(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x1a9a9
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x60(%rax)
je 0x1a9a7
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x60(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq 0x58(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq $0x0, 0x60(%rax)
jmp 0x1a9a9
jmp 0x1a9ab
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1a87f
movl -0x28(%rbp), %eax
addl -0x2c(%rbp), %eax
cmpl $0x1, %eax
jne 0x1a9c6
jmp 0x1a9e5
leaq 0x745e(%rip), %rdi      # 0x21e2b
leaq 0x73d4(%rip), %rsi      # 0x21da8
movl $0x76, %edx
leaq 0x7465(%rip), %rcx      # 0x21e45
callq 0x2180
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x4bd0
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jl 0x1aa52
movq -0x40(%rbp), %rdi
movl -0x20(%rbp), %eax
subl $0x1, %eax
subl -0x1c(%rbp), %eax
cltq
imulq $0x68, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
imulq $0x68, 0x8(%rax), %rax
addq %rax, %rsi
movl $0x68, %edx
callq 0x2200
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1aa06
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x20(%rbp), %rax
imulq $0x68, %rax, %rdx
callq 0x2200
movl -0x20(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0xac90
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0xac90
addq $0x50, %rsp
popq %rbp
retq