// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: get_spec_ovlp_occ(eg_srt_t*, int, int, int, int, int*, int*, kvec_t_u64_warp*)
int32_t get_spec_ovlp_occ(eg_srt_t *a, int32_t a_n, int32_t st, int32_t vv, int32_t c_thres, int32_t *s, int32_t *e, kvec_t_u64_warp *res)
{
	int32_t i, dst = a[st].d, occ = 1, pp;
	(*s) = (*e) = st; res->a.n = 0;
	for (i = st + 1; i < a_n; i++) {
		if(a[i].d - dst <= vv) {
			(*e) = i; 
			if(a[i].id == a[st].id) continue;
			occ++; kv_push(uint64_t, res->a, (((uint64_t)(a[i].id))<<32)|i);
		} else {
			break;
		}
	}

	for (i = st - 1; i >= 0; i--) {
		if(dst - a[i].d <= vv) {
			(*s) = i; 
			if(a[i].id == a[st].id) continue;
			occ++; kv_push(uint64_t, res->a, (((uint64_t)(a[i].id))<<32)|i);
		} else {
			break;
		}
	}	
	if(occ >= c_thres) {
		radix_sort_gfa64(res->a.a, res->a.a + res->a.n);
		for (i = 0, pp = -1, occ = 0; i < (int32_t)res->a.n; i++) {
			if((int32_t)(res->a.a[i]>>32) != pp) {
				pp = (res->a.a[i]>>32);
				res->a.a[occ] = res->a.a[i];
				occ++;
			}
		}
		res->a.n = occ;
		if(occ >= c_thres) return occ;
		return 0;
	}
	else {
		return 0;
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x10(%rsp)
movq 0x68(%rsp), %rbx
movq 0x60(%rsp), %r10
movl %edx, 0xc(%rsp)
movslq %edx, %r13
leaq (%r13,%r13,2), %rax
movq %rdi, 0x18(%rsp)
leaq (%rdi,%rax,8), %r15
movl 0x10(%r15), %r12d
movl %r13d, (%r10)
movl %r13d, (%r9)
movq $0x0, (%rbx)
leal 0x1(%r13), %edx
movl $0x1, %r14d
cmpl %esi, %edx
movq %r9, 0x20(%rsp)
movl %ecx, 0x8(%rsp)
jge 0x1d8ab6
movl %esi, %r8d
incq %r13
movq 0x18(%rsp), %rdx
leaq (%rdx,%rax,8), %rbp
addq $0x2c, %rbp
negl %r8d
movl -0x4(%rbp), %eax
subl %r12d, %eax
cmpl %ecx, %eax
jg 0x1d8ab6
movl %r13d, (%r10)
movl (%rbp), %eax
cmpl 0x14(%r15), %eax
je 0x1d8aa3
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1d8a84
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
movl %r14d, 0x14(%rsp)
movq %r15, %r14
movl %r12d, %r15d
movq %r8, %r12
movq %r10, %rbx
callq 0x2370
movq %rbx, %r10
movq %r12, %r8
movl %r15d, %r12d
movq %r14, %r15
movl 0x14(%rsp), %r14d
movq 0x68(%rsp), %rbx
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %r9
movq %rax, 0x10(%rbx)
incl %r14d
movl (%rbp), %eax
shlq $0x20, %rax
orq %r13, %rax
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rdi,8)
incq %r13
addq $0x18, %rbp
movl %r8d, %eax
addl %r13d, %eax
jne 0x1d8a0c
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x1d8b65
movl %eax, %r13d
leaq (,%r13,2), %rax
addq %r13, %rax
movq 0x18(%rsp), %rdx
leaq (%rdx,%rax,8), %rbp
addq $-0x4, %rbp
movl %r12d, %eax
subl -0x4(%rbp), %eax
cmpl %ecx, %eax
jg 0x1d8b65
leal -0x1(%r13), %eax
movl %eax, (%r9)
movl (%rbp), %eax
cmpl 0x14(%r15), %eax
je 0x1d8b50
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1d8b2e
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %r9
movq %rax, 0x10(%rbx)
incl %r14d
movl (%rbp), %eax
shlq $0x20, %rax
addq %r13, %rax
decq %rax
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rdi,8)
decq %r13
leaq 0x1(%r13), %rax
addq $-0x18, %rbp
cmpq $0x1, %rax
jg 0x1d8add
xorl %eax, %eax
movl 0x10(%rsp), %ebp
cmpl %ebp, %r14d
jl 0x1d8bd1
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x194fef
xorl %eax, %eax
cmpl $0x0, (%rbx)
movl $0x0, %edx
jle 0x1d8bc6
movq 0x10(%rbx), %rcx
xorl %esi, %esi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
xorl %edx, %edx
movq (%rcx,%rsi,8), %r9
movq %r9, %rdi
shrq $0x20, %rdi
cmpl %edi, %r8d
jne 0x1d8baf
movl %r8d, %edi
jmp 0x1d8bb8
movslq %edx, %rdx
movq %r9, (%rcx,%rdx,8)
incl %edx
incq %rsi
movslq (%rbx), %r9
movl %edi, %r8d
cmpq %r9, %rsi
jl 0x1d8b9a
movslq %edx, %rcx
movq %rcx, (%rbx)
cmpl %ebp, %ecx
cmovgel %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq