// File: /workspace/github_c_makefile_star2_O3/lh3[P]miniprot/hit.c
// Function: mp_reg_gen_from_block
mp_reg1_t *mp_reg_gen_from_block(void *km, const mp_idx_t *mi, int32_t n_u, const uint64_t *u, const uint64_t *a, int32_t *n_reg)
{
	int32_t i, k, nr;
	mp_reg1_t *reg;
	reg = Kcalloc(km, mp_reg1_t, n_u);
	for (i = k = nr = 0; i < n_u; ++i) {
		uint32_t n = (uint32_t)u[i];
		int32_t ts, te, is, ie;
		mp_reg1_t *r = &reg[nr++];
		r->off = k, r->cnt = n;
		is = k, ie = k + n - 1;
		ts = mp_idx_block2pos(mi, a[is]>>32);
		te = mp_idx_block2pos(mi, a[ie]>>32);
		assert(ts <= te);
		if (ts == te) { // on the same contig
			r->vid = ts;
		} else { // on different contigs
			int32_t j, js, je;
			for (j = k; j < k + n; ++j)
				if (a[j]>>32 >= mi->bo[ts+1])
					break;
			assert(j < k + n);
			js = j;
			for (j = k + n - 1; j >= js; --j)
				if (a[j]>>32 < mi->bo[te])
					break;
			je = j + 1;
			if (js - k > k + n - je) {
				r->vid = ts, ie = js - 1;
			} else {
				r->vid = te, is = je;
			}
			//fprintf(stderr, "SPLIT: %d<%d %d<=%d<=%d<=%d\n", ts, te, k, js, je, k + n);
		}
		r->vs = ((a[is]>>32) - mi->bo[r->vid]) << mi->opt.bbit;
		r->ve = ((a[ie]>>32) - mi->bo[r->vid] + 1) << mi->opt.bbit;
		r->qs = (uint32_t)a[is];
		r->qe = (uint32_t)a[ie] + 0;
		r->chn_sc = ts == te? u[i]>>32 : (uint32_t)((double)(u[i]>>32) * (ie - is + 1) / n + .499);
		r->chn_sc_ungap = mp_cal_chn_sc_ungap_approx(r, a, mi->opt.kmer);
		k += n;
	}
	*n_reg = nr;
	return reg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %r14
movq %r8, 0x8(%rsp)
movq %rcx, 0x38(%rsp)
movl %edx, %ebp
movq %rsi, 0x60(%rsp)
movslq %edx, %rbx
movl $0x68, %edx
movq %rbx, %rsi
callq 0x8344
movq %rax, 0x20(%rsp)
testl %ebx, %ebx
jle 0xec64
movq %r14, 0x40(%rsp)
movl %ebp, 0x1c(%rsp)
movl %ebp, %eax
movq %rax, 0x58(%rsp)
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x60(%rsp), %rbx
movq 0x38(%rsp), %rax
movl (%rax,%rcx,8), %edx
leaq 0x1(%rcx), %rax
movq %rax, 0x70(%rsp)
movq %rcx, 0x10(%rsp)
imulq $0x68, %rcx, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax), %rsi
movq %rsi, 0x28(%rsp)
movl %r14d, (%rcx,%rax)
movl %edx, 0x4(%rcx,%rax)
leal (%r14,%rdx), %r12d
movq %rdx, 0x68(%rsp)
leal -0x1(%r14,%rdx), %r15d
movslq %r14d, %rax
movq 0x8(%rsp), %rbp
movq %rax, 0x30(%rsp)
movl 0x4(%rbp,%rax,8), %esi
movq %rbx, %rdi
callq 0x4fcb
movl %eax, 0x4(%rsp)
movl %r15d, %r13d
movslq %r15d, %rax
movl 0x4(%rbp,%rax,8), %esi
movq %rax, %rbp
movq %rbx, %rdi
callq 0x4fcb
movl 0x4(%rsp), %r10d
cmpl %eax, %r10d
jg 0xec9c
movl %r14d, %edx
jne 0xea78
movq 0x28(%rsp), %r14
movl %r10d, 0x30(%r14)
movq 0x30(%rbx), %rcx
movl %r10d, %edi
movl %edx, %esi
movq 0x10(%rsp), %r9
movl %r13d, %r15d
movq 0x30(%rsp), %r13
jmp 0xeb68
movq %rbp, %rcx
cmpl %r12d, %r14d
movabsq $0x100000000, %rbp      # imm = 0x100000000
movl %r13d, %r15d
movq 0x30(%rsp), %r13
jae 0xec7d
movq 0x30(%rbx), %rdi
movslq 0x4(%rsp), %rsi
movq %rdi, 0x50(%rsp)
movl 0x4(%rdi,%rsi,4), %r9d
leal -0x1(%rdx), %esi
movq %r13, %r8
shlq $0x20, %r8
movq 0x8(%rsp), %rdi
leaq (%rdi,%r13,8), %r10
xorl %edi, %edi
cmpl %r9d, 0x4(%r10,%rdi,8)
jae 0xead9
incq %rdi
addq %rbp, %r8
leal (%rdx,%rdi), %r11d
cmpl %r11d, %r12d
ja 0xeabe
jmp 0xec7d
addl %edi, %r14d
movl %esi, %r9d
movl %r12d, %esi
cmpl %r14d, %r15d
movq %rcx, %rbp
movq 0x50(%rsp), %rcx
jl 0xeb27
leaq (%r9,%rdi), %rsi
movq %rsi, 0x48(%rsp)
movslq %eax, %rsi
movl (%rcx,%rsi,4), %r11d
sarq $0x20, %r8
leaq 0x1(%rbp), %r14
movl %r15d, %esi
movq 0x8(%rsp), %r10
cmpl %r11d, -0x4(%r10,%r14,8)
jb 0xeb25
decl %esi
decq %r14
cmpq %r8, %r14
jg 0xeb0a
movq 0x48(%rsp), %rsi
incl %esi
movl %r12d, %r8d
subl %esi, %r8d
cmpl %r8d, %edi
movq 0x28(%rsp), %r14
jbe 0xeb55
movl 0x4(%rsp), %r10d
movl %r10d, 0x30(%r14)
addq %rdi, %r9
movslq %r9d, %rbp
movl %r10d, %edi
movl %edx, %esi
movl %r9d, %r15d
movq 0x10(%rsp), %r9
jmp 0xeb68
movl %eax, 0x30(%r14)
movslq %esi, %r13
movl %eax, %edi
movq 0x10(%rsp), %r9
movl 0x4(%rsp), %r10d
movq 0x8(%rsp), %r8
movl 0x4(%r8,%r13,8), %edx
movl %edi, %edi
movl (%rcx,%rdi,4), %edi
subq %rdi, %rdx
movb (%rbx), %cl
shlq %cl, %rdx
movq %rdx, 0x40(%r14)
movl 0x4(%r8,%rbp,8), %edx
subq %rdi, %rdx
incq %rdx
shlq %cl, %rdx
movq %rdx, 0x48(%r14)
movl (%r8,%r13,8), %ecx
movl %ecx, 0x34(%r14)
movl (%r8,%rbp,8), %ecx
movl %ecx, 0x38(%r14)
movq 0x38(%rsp), %rcx
movl 0x4(%rcx,%r9,8), %ecx
cmpl %eax, %r10d
je 0xebe5
cvtsi2sd %rcx, %xmm0
subl %esi, %r15d
incl %r15d
cvtsi2sd %r15d, %xmm1
mulsd %xmm0, %xmm1
movl 0x68(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
addsd 0x4440(%rip), %xmm1     # 0x13020
cvttsd2si %xmm1, %rcx
movl %ecx, 0x24(%r14)
movl 0x8(%rbx), %eax
movslq 0x4(%r14), %rcx
cmpq $0x2, %rcx
jl 0xec3d
movslq (%r14), %rdx
movq 0x8(%rsp), %rsi
leaq (%rsi,%rdx,8), %rsi
movl $0x1, %edi
movl %eax, %edx
movq -0x8(%rsi,%rdi,8), %r8
movq (%rsi,%rdi,8), %r9
movl %r9d, %r10d
subl %r8d, %r10d
cmpl %eax, %r10d
cmovgel %eax, %r10d
leal (%r10,%rdx), %r11d
xorq %r8, %r9
shrq $0x20, %r9
leal 0x2(%r10,%rdx), %edx
cmovnel %r11d, %edx
incq %rdi
cmpq %rdi, %rcx
jne 0xec09
jmp 0xec3f
movl %eax, %edx
movl %edx, 0x28(%r14)
movq 0x70(%rsp), %rax
movq %rax, %rcx
movl %r12d, %r14d
cmpq 0x58(%rsp), %rax
jne 0xe9d1
movq 0x40(%rsp), %r14
movl 0x1c(%rsp), %eax
jmp 0xec66
xorl %eax, %eax
movl %eax, (%r14)
movq 0x20(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x65de(%rip), %rdi      # 0x15262
leaq 0x655e(%rip), %rsi      # 0x151e9
leaq 0x655d(%rip), %rcx      # 0x151ef
movl $0x35, %edx
callq 0x2150
leaq 0x653d(%rip), %rdi      # 0x151e0
leaq 0x653f(%rip), %rsi      # 0x151e9
leaq 0x653e(%rip), %rcx      # 0x151ef
movl $0x2d, %edx
callq 0x2150