// File: /workspace/github_c_makefile_star2_O1/lh3[P]miniprot/hit.c
// Function: mp_cal_max_ext
uint64_t *mp_cal_max_ext(void *km, const mp_ntdb_t *nt, int32_t n_reg, mp_reg1_t *reg, const uint64_t *a, int32_t min_ext, int32_t max_ext)
{
	mp128_t *b;
	uint64_t *ext;
	int32_t i;
	if (n_reg <= 0) return 0;
	b = Kmalloc(km, mp128_t, n_reg);
	for (i = 0; i < n_reg; ++i) {
		mp_reg1_t *r = &reg[i];
		b[i].x = nt? r->vs + nt->ctg[r->vid>>1].off + (r->vid&1? nt->ctg[r->vid>>1].len : 0) : a[r->off] >> 32;
		b[i].y = i;
	}
	radix_sort_mp128x(b, b + n_reg);
	ext = Kmalloc(km, uint64_t, n_reg);
	for (i = 0; i < n_reg; ++i) {
		int32_t left = max_ext, right = max_ext, j = b[i].y;
		mp_reg1_t *r = &reg[j];
		if (i > 0) {
			mp_reg1_t *q = &reg[b[i-1].y];
			if (q->vid == r->vid && q->qe >= r->qs) {
				left = r->vs - q->ve < max_ext? r->vs - q->ve : max_ext;
				left = left > min_ext? left : min_ext;
			}
		}
		if (i < n_reg - 1) {
			mp_reg1_t *q = &reg[b[i+1].y];
			if (q->vid == r->vid && r->qe >= q->qs) {
				right = q->vs - r->ve < max_ext? q->vs - r->ve : max_ext;
				right = right > min_ext? right : min_ext;
			}
		}
		ext[j] = (uint64_t)left<<32 | right;
	}
	kfree(km, b);
	return ext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, 0x4(%rsp)
testl %edx, %edx
jle 0xf51a
movq %r8, %r13
movq %rcx, %r14
movq %rsi, %r15
movl 0x50(%rsp), %ebp
movl %edx, (%rsp)
movl %edx, %r12d
movq %r12, %rbx
shlq $0x4, %rbx
movq %rdi, 0x10(%rsp)
movq %rbx, %rsi
callq 0x80a1
movq %rax, 0x8(%rsp)
addq $0x8, %rax
leaq 0x40(%r14), %rcx
xorl %edx, %edx
testq %r15, %r15
je 0xf3e5
movq 0x28(%r15), %rsi
movl -0x10(%rcx), %r8d
movl %r8d, %edi
shrl %edi
leaq (%rdi,%rdi,2), %rdi
testb $0x1, %r8b
jne 0xf3f0
xorl %r8d, %r8d
jmp 0xf3f8
movslq -0x40(%rcx), %rsi
movl 0x4(%r13,%rsi,8), %esi
jmp 0xf402
leaq (%rsi,%rdi,8), %r8
movq 0x8(%r8), %r8
movq (%rsi,%rdi,8), %rsi
addq (%rcx), %rsi
addq %r8, %rsi
movq %rsi, -0x8(%rax)
movq %rdx, (%rax)
incq %rdx
addq $0x10, %rax
addq $0x68, %rcx
cmpq %rdx, %r12
jne 0xf3c4
movq 0x8(%rsp), %r15
addq %r15, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x4928
leaq (,%r12,8), %rsi
movq 0x10(%rsp), %rdi
callq 0x80a1
movq %rax, %r13
movq %r15, %rax
addq $0x18, %rax
movslq %ebp, %rcx
movl (%rsp), %edx
decl %edx
movslq %edx, %rdx
xorl %esi, %esi
movl 0x4(%rsp), %r15d
movslq -0x10(%rax), %rdi
imulq $0x68, %rdi, %r9
addq %r14, %r9
movl %ebp, %r8d
testq %rsi, %rsi
je 0xf4a8
imulq $0x68, -0x20(%rax), %r10
movl 0x30(%r14,%r10), %r11d
movl %ebp, %r8d
cmpl 0x30(%r9), %r11d
jne 0xf4a8
addq %r14, %r10
movl 0x38(%r10), %r11d
movl %ebp, %r8d
cmpl 0x34(%r9), %r11d
jl 0xf4a8
movq 0x40(%r9), %r8
subq 0x48(%r10), %r8
cmpq %rcx, %r8
jl 0xf4a0
movl %ebp, %r8d
cmpl %r15d, %r8d
jg 0xf4a8
movl %r15d, %r8d
movl %ebp, %r10d
cmpq %rdx, %rsi
jge 0xf4ea
imulq $0x68, (%rax), %r11
movl 0x30(%r14,%r11), %ebx
movl %ebp, %r10d
cmpl 0x30(%r9), %ebx
jne 0xf4ea
addq %r14, %r11
movl 0x38(%r9), %ebx
movl %ebp, %r10d
cmpl 0x34(%r11), %ebx
jl 0xf4ea
movq 0x40(%r11), %r10
subq 0x48(%r9), %r10
cmpq %rcx, %r10
jl 0xf4e2
movl %ebp, %r10d
cmpl %r15d, %r10d
jg 0xf4ea
movl %r15d, %r10d
shlq $0x20, %r8
movslq %r10d, %r9
orq %r8, %r9
movq %r9, (%r13,%rdi,8)
incq %rsi
addq $0x10, %rax
cmpq %rsi, %r12
jne 0xf45a
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x7fd6
jmp 0xf51d
xorl %r13d, %r13d
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop