// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
cmpl $0x0, -0x1c(%rbp)
jg 0x29c33
movq $0x0, -0x8(%rbp)
jmp 0x29ee0
movq -0x10(%rbp), %rdi
movl -0x1c(%rbp), %eax
shll $0x4, %eax
movslq %eax, %rsi
callq 0x1aae0
movq %rax, -0x38(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x29d1b
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x29ef0
movq %rax, -0x70(%rbp)
movq -0x30(%rbp), %rax
movslq -0x58(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdi
callq 0x29ef0
movq -0x70(%rbp), %rdi
addq %rax, %rdi
movl -0x14(%rbp), %eax
xorq %rax, %rdi
callq 0x29ef0
movl %eax, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl -0x5c(%rbp), %eax
xorq %rax, %rcx
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x58(%rbp), %rcx
shlq $0x20, %rcx
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rdx
movq (%rax,%rdx,8), %rax
cltq
orq %rax, %rcx
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addl -0x58(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x29c57
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
movslq -0x1c(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0x5ad0
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl -0x1c(%rbp), %ecx
sarl %ecx
cmpl %ecx, %eax
jge 0x29dd0
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x48(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %edx
subl $0x1, %edx
subl -0x54(%rbp), %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
subl $0x1, %ecx
subl -0x54(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x48(%rbp), %rcx
movq %rcx, (%rax)
movq -0x40(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x29d3a
movslq -0x1c(%rbp), %rdi
movl $0x50, %esi
callq 0x2220
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x29ecb
movq -0x50(%rbp), %rax
movslq -0x54(%rbp), %rcx
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x54(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movl $0xffffffff, 0x20(%rax) # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x68(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x38(%rbp), %rax
movslq -0x54(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x68(%rbp), %rax
movss 0x2dcf3(%rip), %xmm0    # 0x57b98
movss %xmm0, 0x44(%rax)
movq -0x68(%rbp), %rdi
movl -0x18(%rbp), %esi
movq -0x30(%rbp), %rdx
movl 0x10(%rbp), %ecx
callq 0x29fa0
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x29de9
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1a8c0
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)