// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
xorl %r13d, %r13d
testl %ecx, %ecx
jle 0x1bd79
movq %r9, %rbx
movq %r8, %r14
movl %edx, 0xc(%rsp)
movl $0x80000001, %r15d      # imm = 0x80000001
movl %ecx, %r12d
movl %esi, (%rsp)
movl %ecx, %esi
shll $0x4, %esi
movq %rdi, 0x10(%rsp)
callq 0x126e9
movq %rax, %rbp
movl (%rsp), %eax
movl %r12d, %r9d
leaq (,%r9,8), %rcx
xorl %edx, %edx
movslq %r13d, %r13
movq %r13, %rsi
shlq $0x4, %rsi
movq (%rbx,%rsi), %rdi
movq 0x8(%rbx,%rsi), %rsi
movq %rdi, %r8
notq %r8
shlq $0x15, %rdi
addq %r8, %rdi
movq %rdi, %r8
shrq $0x18, %r8
xorq %rdi, %r8
imulq $0x109, %r8, %rdi       # imm = 0x109
movq %rdi, %r8
shrq $0xe, %r8
xorq %rdi, %r8
leaq (%r8,%r8,4), %rdi
leaq (%r8,%rdi,4), %rdi
movq %rdi, %r8
shrq $0x1c, %r8
xorq %rdi, %r8
movq %rsi, %rdi
notq %rdi
shlq $0x15, %rsi
addq %rdi, %rsi
movq %rsi, %rdi
shrq $0x18, %rdi
xorq %rsi, %rdi
imulq $0x109, %rdi, %rsi      # imm = 0x109
movq %rsi, %rdi
shrq $0xe, %rdi
xorq %rsi, %rdi
leaq (%rdi,%rdi,4), %rsi
leaq (%rdi,%rsi,4), %rsi
movq %rsi, %rdi
shrq $0x1c, %rdi
xorq %rsi, %rdi
addq %r8, %rdi
imulq %r15, %rdi
xorq %rax, %rdi
movq %rdi, %rsi
notq %rsi
shlq $0x15, %rdi
addq %rsi, %rdi
movq %rdi, %rsi
shrq $0x18, %rsi
xorq %rdi, %rsi
imulq $0x109, %rsi, %rsi      # imm = 0x109
movq %rsi, %rdi
shrq $0xe, %rdi
xorq %rsi, %rdi
leaq (%rdi,%rdi,4), %rsi
leaq (%rdi,%rsi,4), %rsi
movq %rsi, %rdi
shrq $0x1c, %rdi
xorl %esi, %edi
imull %r15d, %edi
xorq (%r14,%rdx), %rdi
movq %rdi, (%rbp,%rdx,2)
movq %r13, %rsi
shlq $0x20, %rsi
movslq (%r14,%rdx), %rdi
orq %rsi, %rdi
movq %rdi, 0x8(%rbp,%rdx,2)
addl (%r14,%rdx), %r13d
addq $0x8, %rdx
cmpq %rdx, %rcx
jne 0x1bb75
movq %rbx, %r15
movq %r9, %rsi
shlq $0x4, %rsi
addq %rbp, %rsi
movq %rbp, %rdi
movq %r9, %rbx
callq 0x5ae1
movq %rbx, %rdi
cmpl $0x1, %r12d
je 0x1bcd8
movl %r12d, %eax
shrl %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movq %rdi, %rcx
shlq $0x4, %rcx
addq $-0x10, %rcx
shlq $0x4, %rax
xorl %edx, %edx
movups (%rbp,%rdx), %xmm0
movaps %xmm0, 0x20(%rsp)
movups (%rbp,%rcx), %xmm0
movups %xmm0, (%rbp,%rdx)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rbp,%rcx)
addq $0x10, %rdx
addq $-0x10, %rcx
cmpq %rdx, %rax
jne 0x1bcad
movl $0x50, %esi
callq 0x2230
movq %rax, %r13
cmpl $0x2, %r12d
movl $0x1, %eax
cmovgel %r12d, %eax
movq %rax, (%rsp)
movq %rbp, %r12
addq $0x8, %r12
xorl %ebx, %ebx
movq %r13, %r14
movq %r15, 0x18(%rsp)
movl 0xc(%rsp), %r15d
movl %ebx, (%r14)
movl $0xffffffff, 0x20(%r14) # imm = 0xFFFFFFFF
movq -0x8(%r12), %rax
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, 0x38(%r14)
movl %ecx, 0xc(%r14)
movl %eax, 0x40(%r14)
movq (%r12), %rax
movl %eax, 0x4(%r14)
shrq $0x20, %rax
movl %eax, 0x28(%r14)
movl $0xbf800000, 0x44(%r14) # imm = 0xBF800000
movq %r14, %rdi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
movl 0x70(%rsp), %ecx
callq 0x1bd8b
incq %rbx
addq $0x10, %r12
addq $0x50, %r14
cmpq %rbx, (%rsp)
jne 0x1bd0c
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x1261e
movq %r13, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq