// File: /workspace/github_c_makefile_star2_O3/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 %r14d, %r14d
testl %ecx, %ecx
jle 0x1bd51
movq %r8, %r15
movl %ecx, %ebx
movl %esi, %r13d
movl %edx, 0xc(%rsp)
movl $0x80000001, %ebp       # imm = 0x80000001
movl %ecx, %esi
shll $0x4, %esi
movq %rdi, 0x18(%rsp)
movq %r9, 0x10(%rsp)
callq 0x1264d
movq 0x10(%rsp), %r9
movq %rax, %r12
movl %r13d, %eax
movq %rbx, (%rsp)
movl %ebx, %r13d
leaq (,%r13,8), %rcx
xorl %edx, %edx
movslq %r14d, %r14
movq %r14, %rsi
shlq $0x4, %rsi
movq (%r9,%rsi), %rdi
movq 0x8(%r9,%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 %rbp, %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 %ebp, %edi
xorq (%r15,%rdx), %rdi
movq %rdi, (%r12,%rdx,2)
movq %r14, %rsi
shlq $0x20, %rsi
movslq (%r15,%rdx), %rdi
orq %rsi, %rdi
movq %rdi, 0x8(%r12,%rdx,2)
addl (%r15,%rdx), %r14d
addq $0x8, %rdx
cmpq %rdx, %rcx
jne 0x1bb6e
movq %r13, %r14
shlq $0x4, %r14
leaq (%r12,%r14), %rsi
movq %r12, %rdi
callq 0x5a49
movq (%rsp), %rcx
cmpl $0x1, %ecx
je 0x1bcc0
shrl %ecx
cmpl $0x1, %ecx
adcl $0x0, %ecx
addq $-0x10, %r14
shlq $0x4, %rcx
xorl %eax, %eax
movups (%r12,%rax), %xmm0
movaps %xmm0, 0x20(%rsp)
movups (%r12,%r14), %xmm0
movups %xmm0, (%r12,%rax)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%r12,%r14)
addq $0x10, %rax
addq $-0x10, %r14
cmpq %rax, %rcx
jne 0x1bc95
movl $0x50, %esi
movq %r13, %rdi
callq 0x2230
movq %rax, %r14
movq %r12, %rbp
addq $0x8, %rbp
movq %r13, (%rsp)
xorl %r13d, %r13d
movq %rax, %r15
movq 0x10(%rsp), %rbx
movl %r13d, (%r15)
movl $0xffffffff, 0x20(%r15) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq %rax, %rcx
shrq $0x20, %rcx
movl %ecx, 0x38(%r15)
movl %ecx, 0xc(%r15)
movl %eax, 0x40(%r15)
movq (%rbp), %rax
movl %eax, 0x4(%r15)
shrq $0x20, %rax
movl %eax, 0x28(%r15)
movl $0xbf800000, 0x44(%r15) # imm = 0xBF800000
movq %r15, %rdi
movl 0xc(%rsp), %esi
movq %rbx, %rdx
movl 0x70(%rsp), %ecx
callq 0x1bd63
incq %r13
addq $0x10, %rbp
addq $0x50, %r15
cmpq %r13, (%rsp)
jne 0x1bce6
movq 0x18(%rsp), %rdi
movq %r12, %rsi
callq 0x12587
movq %r14, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq