// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %r9, 0x30(%rsp)
movq %r8, %r14
movq %rcx, %r13
movq %rsi, %r12
movslq %edx, %rbx
pushq $0x68
popq %rdx
movq %rbx, %rsi
callq 0x72e4
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
testl %ebx, %ebx
cmovlel %ecx, %ebx
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
movq %r13, 0x40(%rsp)
cmpq 0x20(%rsp), %rcx
je 0xd1a3
movl (%r13,%rcx,8), %edx
leaq 0x1(%rcx), %rax
movq %rax, 0x50(%rsp)
movq %rcx, 0x10(%rsp)
imulq $0x68, %rcx, %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rax), %rbp
movl %ebx, (%rcx,%rax)
movl %edx, 0x4(%rcx,%rax)
leal (%rbx,%rdx), %r15d
movq %rdx, 0x48(%rsp)
leal -0x1(%rbx,%rdx), %r13d
movslq %ebx, %rax
movq %rax, 0x28(%rsp)
movl 0x4(%r14,%rax,8), %esi
movq %r12, %rdi
callq 0x3fca
movl %eax, 0x8(%rsp)
movl %r13d, 0xc(%rsp)
movslq %r13d, %rax
movq %rax, %r13
movl 0x4(%r14,%rax,8), %esi
movq %r12, %rdi
callq 0x3fca
movl 0x8(%rsp), %r9d
cmpl %eax, %r9d
jg 0xd1e0
movl %ebx, %edx
jne 0xd023
movl %r9d, 0x30(%rbp)
movq 0x30(%r12), %rcx
movl %r9d, %esi
movq 0x10(%rsp), %r8
movq 0x28(%rsp), %rbx
jmp 0xd0d2
movq %rbx, 0x38(%rsp)
movslq %r9d, %r8
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
shlq $0x20, %rdi
leaq (%r14,%rbx,8), %r9
xorl %esi, %esi
leal (%rdx,%rsi), %ecx
cmpl %ecx, %r15d
jbe 0xd1c3
movl 0x4(%r9,%rsi,8), %r10d
movq 0x30(%r12), %rcx
cmpl 0x4(%rcx,%r8,4), %r10d
jae 0xd06c
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rcx, %rdi
incq %rsi
jmp 0xd03d
movslq %eax, %r9
sarq $0x20, %rdi
xorl %r8d, %r8d
movq %r13, %r10
cmpq %rdi, %r10
jl 0xd091
movl 0x4(%r14,%r10,8), %r11d
cmpl (%rcx,%r9,4), %r11d
jb 0xd091
decq %r10
incl %r8d
jmp 0xd079
cmpl %r8d, %esi
jbe 0xd0ba
movl 0x8(%rsp), %r9d
movl %r9d, 0x30(%rbp)
movq 0x38(%rsp), %rdi
decl %edi
addq %rsi, %rdi
movslq %edi, %r13
movl %r9d, %esi
movl %edi, 0xc(%rsp)
movq 0x10(%rsp), %r8
jmp 0xd0d2
movl %r15d, %edx
subl %r8d, %edx
movl %eax, 0x30(%rbp)
movslq %edx, %rbx
movl %eax, %esi
movq 0x10(%rsp), %r8
movl 0x8(%rsp), %r9d
movl 0x4(%r14,%rbx,8), %edi
movl %esi, %esi
movl (%rcx,%rsi,4), %esi
subq %rsi, %rdi
movb (%r12), %cl
shlq %cl, %rdi
movq %rdi, 0x40(%rbp)
movl 0x4(%r14,%r13,8), %edi
subq %rsi, %rdi
incq %rdi
shlq %cl, %rdi
movq %rdi, 0x48(%rbp)
movl (%r14,%rbx,8), %ecx
movl %ecx, 0x34(%rbp)
movl (%r14,%r13,8), %ecx
movl %ecx, 0x38(%rbp)
movq 0x40(%rsp), %r13
movl 0x4(%r13,%r8,8), %ecx
cmpl %eax, %r9d
je 0xd148
cvtsi2sd %rcx, %xmm0
movl 0xc(%rsp), %eax
subl %edx, %eax
incl %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm0, %xmm1
movl 0x48(%rsp), %eax
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
addsd 0x3ee5(%rip), %xmm1     # 0x11028
cvttsd2si %xmm1, %rcx
movl %ecx, 0x24(%rbp)
movl 0x8(%r12), %eax
movl 0x4(%rbp), %ecx
pushq $0x1
popq %rsi
movl %eax, %edx
cmpl %ecx, %esi
jge 0xd193
movslq (%rbp), %rdi
addq %rsi, %rdi
movq -0x8(%r14,%rdi,8), %r8
movq (%r14,%rdi,8), %rdi
movl %edi, %r9d
subl %r8d, %r9d
cmpl %eax, %r9d
jl 0xd17a
movl %eax, %r9d
leal (%r9,%rdx), %r10d
xorq %r8, %rdi
shrq $0x20, %rdi
leal 0x2(%r9,%rdx), %edx
cmovnel %r10d, %edx
incq %rsi
jmp 0xd158
movl %edx, 0x28(%rbp)
movq 0x50(%rsp), %rcx
movl %r15d, %ebx
jmp 0xcf85
movq 0x30(%rsp), %rax
movq 0x20(%rsp), %rcx
movl %ecx, (%rax)
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6063(%rip), %rdi      # 0x1322d
leaq 0x5fe3(%rip), %rsi      # 0x131b4
leaq 0x5fe2(%rip), %rcx      # 0x131ba
pushq $0x35
popq %rdx
callq 0x2150
leaq 0x5fc4(%rip), %rdi      # 0x131ab
leaq 0x5fc6(%rip), %rsi      # 0x131b4
leaq 0x5fc5(%rip), %rcx      # 0x131ba
pushq $0x2d
jmp 0xd1da