// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x14(%rbp), %rsi
movl $0x68, %edx
callq 0xab60
movq %rax, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x1a617
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
movq -0x48(%rbp), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x3c(%rbp)
movslq %ecx, %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl -0x38(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, (%rax)
movl -0x4c(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x38(%rbp), %eax
movl %eax, -0x58(%rbp)
movl -0x38(%rbp), %eax
addl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %esi
callq 0x5260
movl %eax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, %esi
callq 0x5260
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jg 0x1a390
jmp 0x1a3af
leaq 0x7a08(%rip), %rdi      # 0x21d9f
leaq 0x7a0a(%rip), %rsi      # 0x21da8
movl $0x2d, %edx
leaq 0x7a04(%rip), %rcx      # 0x21dae
callq 0x2180
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0x1a3c6
movl -0x50(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x1a4cf
movl -0x38(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1a411
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movl -0x50(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
jb 0x1a404
jmp 0x1a411
jmp 0x1a406
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1a3cc
movl -0x6c(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x1a420
jmp 0x1a43f
leaq 0x79fa(%rip), %rdi      # 0x21e21
leaq 0x797a(%rip), %rsi      # 0x21da8
movl $0x35, %edx
leaq 0x7974(%rip), %rcx      # 0x21dae
callq 0x2180
movl -0x6c(%rbp), %eax
movl %eax, -0x70(%rbp)
movl -0x38(%rbp), %eax
addl -0x4c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x70(%rbp), %eax
jl 0x1a48c
movq -0x28(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x54(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
cmpq %rcx, %rax
jae 0x1a47f
jmp 0x1a48c
jmp 0x1a481
movl -0x6c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x1a451
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movl -0x70(%rbp), %eax
subl -0x38(%rbp), %eax
movl -0x38(%rbp), %ecx
addl -0x4c(%rbp), %ecx
subl -0x74(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x1a4bd
movl -0x50(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x70(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1a4cd
movl -0x54(%rbp), %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x30(%rax)
movl -0x74(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x1a4cf
movq -0x28(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x68(%rbp), %rdx
movl 0x30(%rdx), %edx
movl (%rcx,%rdx,4), %ecx
subq %rcx, %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shlq %cl, %rax
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x68(%rbp), %rdx
movl 0x30(%rdx), %edx
movl (%rcx,%rdx,4), %ecx
subq %rcx, %rax
addq $0x1, %rax
movq -0x10(%rbp), %rcx
movl (%rcx), %ecx
shlq %cl, %rax
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x28(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x34(%rax)
movq -0x28(%rbp), %rax
movslq -0x5c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %ecx
addl $0x0, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x38(%rax)
movl -0x50(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0x1a590
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movq %rax, -0x80(%rbp)
jmp 0x1a5d6
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %eax
cvtsi2sd %rax, %xmm0
movl -0x5c(%rbp), %eax
movl -0x58(%rbp), %ecx
subl %ecx, %eax
incl %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm0
movl -0x4c(%rbp), %eax
cvtsi2sd %rax, %xmm1
divsd %xmm1, %xmm0
movsd 0x5a61(%rip), %xmm1     # 0x20028
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x68(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x1a630
movl %eax, %ecx
movq -0x68(%rbp), %rax
movl %ecx, 0x28(%rax)
movl -0x4c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1a2ed
movl -0x3c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)