// File: /workspace/github_c_makefile_star2_O2/lh3[P]minimap2/hit.c
// Function: mm_gen_regs
mm_reg1_t *mm_gen_regs(void *km, uint32_t hash, int qlen, int n_u, uint64_t *u, mm128_t *a, int is_qstrand) // convert chains to hits
{
	mm128_t *z, tmp;
	mm_reg1_t *r;
	int i, k;

	if (n_u <= 0) return 0;

	// sort by score
	z = (mm128_t*)kmalloc(km, n_u * 16);
	for (i = k = 0; i < n_u; ++i) {
		uint32_t h;
		h = (uint32_t)hash64((hash64(a[k].x) + hash64(a[k].y)) ^ hash);
		z[i].x = u[i] ^ h; // u[i] -- higher 32 bits: chain score; lower 32 bits: number of seeds in the chain
		z[i].y = (uint64_t)k << 32 | (int32_t)u[i];
		k += (int32_t)u[i];
	}
	radix_sort_128x(z, z + n_u);
	for (i = 0; i < n_u>>1; ++i) // reverse, s.t. larger score first
		tmp = z[i], z[i] = z[n_u-1-i], z[n_u-1-i] = tmp;

	// populate r[]
	r = (mm_reg1_t*)calloc(n_u, sizeof(mm_reg1_t));
	for (i = 0; i < n_u; ++i) {
		mm_reg1_t *ri = &r[i];
		ri->id = i;
		ri->parent = MM_PARENT_UNSET;
		ri->score = ri->score0 = z[i].x >> 32;
		ri->hash = (uint32_t)z[i].x;
		ri->cnt = (int32_t)z[i].y;
		ri->as = z[i].y >> 32;
		ri->div = -1.0f;
		mm_reg_set_coor(ri, qlen, a, is_qstrand);
	}
	kfree(km, z);
	return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x10(%rsp)
movq %r8, 0x30(%rsp)
xorl %ebx, %ebx
testl %ecx, %ecx
jle 0x193e1
movl %ecx, %r14d
movl %esi, %r13d
movl %edx, 0xc(%rsp)
movl %ecx, %esi
shll $0x4, %esi
movq %rdi, 0x20(%rsp)
callq 0x10afc
movq %rax, %r12
movl %r13d, %eax
movq %rax, 0x28(%rsp)
movq %r14, 0x18(%rsp)
movl %r14d, %eax
movq %rax, (%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x38(%rsp)
xorl %r15d, %r15d
cmpq %r15, 0x38(%rsp)
je 0x19301
movslq %ebx, %rbx
movq %rbx, %r14
shlq $0x4, %r14
movq %r12, %rbp
movq 0x10(%rsp), %r12
movq (%r12,%r14), %rdi
callq 0x193f3
movq %rax, %r13
movq 0x8(%r12,%r14), %rdi
movq %rbp, %r12
callq 0x193f3
addq %rax, %r13
xorq 0x28(%rsp), %r13
movq %r13, %rdi
callq 0x193f3
movl %eax, %eax
movq 0x30(%rsp), %rdx
xorq (%rdx,%r15), %rax
movq %rax, (%rbp,%r15,2)
movq %rbx, %rax
shlq $0x20, %rax
movslq (%rdx,%r15), %rcx
orq %rax, %rcx
movq %rcx, 0x8(%rbp,%r15,2)
addl (%rdx,%r15), %ebx
addq $0x8, %r15
jmp 0x19292
movq (%rsp), %rbx
shlq $0x4, %rbx
leaq (%rbx,%r12), %rsi
movq %r12, %rdi
callq 0x47dc
movq 0x18(%rsp), %rdx
shrl %edx
shlq $0x4, %rdx
leaq (%rbx,%r12), %rax
addq $-0x10, %rax
xorl %ecx, %ecx
movl 0xc(%rsp), %r14d
cmpq %rcx, %rdx
je 0x19358
movups (%r12,%rcx), %xmm0
movaps %xmm0, 0x40(%rsp)
movups (%rax), %xmm0
movups %xmm0, (%r12,%rcx)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rax)
addq $0x10, %rcx
addq $-0x10, %rax
jmp 0x1932f
pushq $0x50
popq %rsi
movq (%rsp), %rdi
callq 0x2230
movq %rax, %rbx
movq %r12, %r13
addq $0x8, %r13
xorl %ebp, %ebp
movq %rax, %r15
cmpq %rbp, (%rsp)
je 0x193d4
movl %ebp, (%r15)
orl $-0x1, 0x20(%r15)
movq -0x8(%r13), %rax
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, 0x38(%r15)
movl %ecx, 0xc(%r15)
movl %eax, 0x40(%r15)
movq (%r13), %rax
movl %eax, 0x4(%r15)
shrq $0x20, %rax
movl %eax, 0x28(%r15)
movl $0xbf800000, 0x44(%r15) # imm = 0xBF800000
movq %r15, %rdi
movl %r14d, %esi
movq 0x10(%rsp), %rdx
movl 0x90(%rsp), %ecx
callq 0x19433
incq %rbp
addq $0x10, %r13
addq $0x50, %r15
jmp 0x19373
movq 0x20(%rsp), %rdi
movq %r12, %rsi
callq 0x10a07
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq