// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %r8, %r13
movq %rcx, 0x30(%rsp)
movl %edx, %ebp
movq %rsi, 0x10(%rsp)
movslq %edx, %rbx
movl $0x68, %edx
movq %rbx, %rsi
callq 0x7f34
movq %rax, 0x20(%rsp)
testl %ebx, %ebx
jle 0xe8f1
movq %r15, 0x38(%rsp)
movl %ebp, %eax
movq %rax, 0x40(%rsp)
xorl %ecx, %ecx
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
movabsq $0x100000000, %r12      # imm = 0x100000000
movq 0x30(%rsp), %rax
movl (%rax,%rcx,8), %esi
leaq 0x1(%rcx), %rax
movq %rax, 0x50(%rsp)
movq %rcx, 0x28(%rsp)
imulq $0x68, %rcx, %rax
movq 0x20(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, 0x18(%rsp)
movl %ebp, (%rcx,%rax)
movl %esi, 0x4(%rcx,%rax)
leal (%rbp,%rsi), %eax
movl %eax, 0xc(%rsp)
movq %rsi, 0x48(%rsp)
leal -0x1(%rbp,%rsi), %r15d
movslq %ebp, %rax
movl 0x4(%r13,%rax,8), %esi
movq %r14, %rdi
callq 0x4c67
movl %eax, %ebx
movl %r15d, 0x8(%rsp)
movslq %r15d, %r15
movl 0x4(%r13,%r15,8), %esi
movq %r14, %rdi
callq 0x4c67
cmpl %eax, %ebx
jg 0xe929
movl %ebx, %edx
movl %ebp, %ecx
jne 0xe72a
movq 0x18(%rsp), %r15
movl %edx, %ebx
movl %edx, 0x30(%r15)
movl %ecx, %esi
movq 0x28(%rsp), %r10
movl 0x8(%rsp), %r11d
movl 0xc(%rsp), %ebp
jmp 0xe7e6
movl 0xc(%rsp), %ebp
cmpl %ebp, %ecx
jae 0xe90a
movl %edx, %ebx
movq 0x10(%rsp), %rdx
movq 0x30(%rdx), %r9
movslq %ebx, %rdx
movl 0x4(%r9,%rdx,4), %esi
movslq %ecx, %rdi
leal -0x1(%rdi), %edx
movq %rcx, %r8
shlq $0x20, %r8
leaq (,%rdi,8), %r10
addq %r13, %r10
xorl %edi, %edi
cmpl %esi, 0x4(%r10,%rdi,8)
jae 0xe77e
incq %rdi
addq %r12, %r8
leal (%rcx,%rdi), %r11d
cmpl %r11d, %ebp
ja 0xe763
jmp 0xe90a
leal (%rcx,%rdi), %r10d
movl %ebp, %esi
movl 0x8(%rsp), %r11d
cmpl %r10d, %r11d
jl 0xe7bb
movl %edx, %r10d
addq %rdi, %r10
movslq %eax, %rsi
movl (%r9,%rsi,4), %r9d
sarq $0x20, %r8
incq %r15
movl %r11d, %esi
cmpl %r9d, -0x4(%r13,%r15,8)
jb 0xe7b9
decl %esi
decq %r15
cmpq %r8, %r15
jg 0xe7a5
movl %r10d, %esi
incl %esi
movl %ebp, %r8d
subl %esi, %r8d
cmpl %r8d, %edi
movq 0x28(%rsp), %r10
jbe 0xe7dd
movq 0x18(%rsp), %r15
movl %ebx, 0x30(%r15)
addl %edi, %edx
movl %ecx, %esi
movl %edx, %r11d
jmp 0xe7e6
movq 0x18(%rsp), %r15
movl %eax, 0x30(%r15)
movslq %esi, %rdx
movl 0x4(%r13,%rdx,8), %edi
movq 0x10(%rsp), %r9
movq 0x30(%r9), %rcx
movl 0x30(%r15), %r8d
movl (%rcx,%r8,4), %r8d
subq %r8, %rdi
movb (%r9), %cl
shlq %cl, %rdi
movq %rdi, 0x40(%r15)
movslq %r11d, %rdi
movl 0x4(%r13,%rdi,8), %r9d
subq %r8, %r9
incq %r9
shlq %cl, %r9
movq %r9, 0x48(%r15)
movl (%r13,%rdx,8), %ecx
movl %ecx, 0x34(%r15)
movl (%r13,%rdi,8), %ecx
movl %ecx, 0x38(%r15)
movq 0x30(%rsp), %rcx
movl 0x4(%rcx,%r10,8), %ecx
cmpl %eax, %ebx
je 0xe872
cvtsi2sd %rcx, %xmm0
subl %esi, %r11d
incl %r11d
cvtsi2sd %r11d, %xmm1
mulsd %xmm0, %xmm1
movl 0x48(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd %xmm0, %xmm1
addsd 0x37b3(%rip), %xmm1     # 0x12020
cvttsd2si %xmm1, %rcx
movl %ecx, 0x24(%r15)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
movslq 0x4(%r15), %rcx
cmpq $0x2, %rcx
jl 0xe8d1
movslq (%r15), %rdx
leaq (,%rdx,8), %rsi
addq %r13, %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 0xe89d
jmp 0xe8d3
movl %eax, %edx
movl %edx, 0x28(%r15)
movq 0x50(%rsp), %rax
movq %rax, %rcx
cmpq 0x40(%rsp), %rax
jne 0xe694
movq 0x38(%rsp), %r15
jmp 0xe8f3
xorl %eax, %eax
movl %eax, (%r15)
movq 0x20(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x58cc(%rip), %rdi      # 0x141dd
leaq 0x584c(%rip), %rsi      # 0x14164
leaq 0x584b(%rip), %rcx      # 0x1416a
movl $0x35, %edx
callq 0x2150
leaq 0x582b(%rip), %rdi      # 0x1415b
leaq 0x582d(%rip), %rsi      # 0x14164
leaq 0x582c(%rip), %rcx      # 0x1416a
movl $0x2d, %edx
callq 0x2150