// File: /workspace/github_c_makefile_star2_O2/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 0xdd15
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 0x7460
movq %rax, 0x8(%rsp)
addq $0x8, %rax
leaq 0x40(%r14), %rcx
xorl %edx, %edx
cmpq %rdx, %r12
je 0xdc0f
testq %r15, %r15
je 0xdbde
movq 0x28(%r15), %rsi
movl -0x10(%rcx), %r8d
movl %r8d, %edi
shrl %edi
imulq $0x18, %rdi, %rdi
testb $0x1, %r8b
jne 0xdbe9
xorl %r8d, %r8d
jmp 0xdbf1
movslq -0x40(%rcx), %rsi
movl 0x4(%r13,%rsi,8), %esi
jmp 0xdbfb
leaq (%rsi,%rdi), %r8
movq 0x8(%r8), %r8
movq (%rsi,%rdi), %rsi
addq (%rcx), %rsi
addq %r8, %rsi
movq %rsi, -0x8(%rax)
movq %rdx, (%rax)
incq %rdx
addq $0x10, %rax
addq $0x68, %rcx
jmp 0xdbb8
movq 0x8(%rsp), %r15
addq %r15, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3cab
leaq (,%r12,8), %rsi
movq 0x10(%rsp), %rdi
callq 0x7460
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
cmpq %rsi, %r12
je 0xdd04
movslq -0x10(%rax), %rdi
imulq $0x68, %rdi, %r9
addq %r14, %r9
movl %ebp, %r8d
testq %rsi, %rsi
je 0xdca7
imulq $0x68, -0x20(%rax), %r10
movl 0x30(%r14,%r10), %r11d
movl %ebp, %r8d
cmpl 0x30(%r9), %r11d
jne 0xdca7
addq %r14, %r10
movl 0x38(%r10), %r11d
movl %ebp, %r8d
cmpl 0x34(%r9), %r11d
jl 0xdca7
movq 0x40(%r9), %r8
subq 0x48(%r10), %r8
cmpq %rcx, %r8
jl 0xdc9f
movl %ebp, %r8d
cmpl %r15d, %r8d
jg 0xdca7
movl %r15d, %r8d
movq %rcx, %r10
cmpq %rdx, %rsi
jge 0xdcec
imulq $0x68, (%rax), %r11
movl 0x30(%r14,%r11), %ebx
movq %rcx, %r10
cmpl 0x30(%r9), %ebx
jne 0xdcec
addq %r14, %r11
movl 0x38(%r9), %ebx
movq %rcx, %r10
cmpl 0x34(%r11), %ebx
jl 0xdcec
movq 0x40(%r11), %r10
subq 0x48(%r9), %r10
cmpq %rcx, %r10
jl 0xdce1
movl %ebp, %r10d
cmpl %r15d, %r10d
jg 0xdce9
movl %r15d, %r10d
movslq %r10d, %r10
shlq $0x20, %r8
orq %r10, %r8
movq %r8, (%r13,%rdi,8)
incq %rsi
addq $0x10, %rax
jmp 0xdc50
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x736b
jmp 0xdd18
xorl %r13d, %r13d
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop