// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movq %r9, %r10
movl %ecx, %ebp
movq %rdi, %r15
movq 0x78(%rsp), %r9
movq 0x70(%rsp), %rbx
movslq %edx, %r13
imulq $0x18, %r13, %rax
addq %rax, %rdi
movl 0x10(%r15,%rax), %r12d
movl %r13d, (%rbx)
movl %r13d, (%r10)
andq $0x0, (%r9)
movslq %esi, %rsi
leaq 0x2c(%r15), %rax
pushq $0x1
popq %r11
movq %rax, 0x30(%rsp)
imulq $0x18, %r13, %r14
incq %r13
addq %rax, %r14
cmpq %rsi, %r13
jge 0x19620f
movl -0x4(%r14), %eax
subl %r12d, %eax
cmpl %ebp, %eax
jg 0x19620f
movl %r13d, (%rbx)
movl (%r14), %ecx
incq %r13
addq $0x18, %r14
cmpl 0x14(%rdi), %ecx
je 0x196148
movq %rsi, 0x28(%rsp)
movq (%r9), %rbx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rbx
jne 0x1961e3
leaq (%rbx,%rbx), %rsi
testq %rbx, %rbx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r9)
shlq $0x3, %rsi
movq %rdi, 0x10(%rsp)
movq %rax, %rdi
movl %r8d, 0xc(%rsp)
movl %edx, 0x24(%rsp)
movq %r9, %rbx
movq %r10, 0x18(%rsp)
movl %r11d, 0x8(%rsp)
callq 0x2370
movl 0x8(%rsp), %r11d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r10
movq %rbx, %r9
movl 0x24(%rsp), %edx
movl 0xc(%rsp), %r8d
movq %rax, 0x10(%rbx)
movl -0x18(%r14), %ecx
movq (%rbx), %rbx
incl %r11d
decq %r13
shlq $0x20, %rcx
orq %r13, %rcx
leaq 0x1(%rbx), %rsi
movq %rsi, (%r9)
movq %rcx, (%rax,%rbx,8)
movq 0x70(%rsp), %rbx
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rax
jmp 0x19613e
movl %edx, %r14d
movq %r14, %rax
testl %eax, %eax
jle 0x1962c9
movq %rax, %r14
decq %r14
movl %r14d, %r13d
imulq $0x18, %r13, %rbx
movl %r12d, %ecx
subl 0x10(%r15,%rbx), %ecx
cmpl %ebp, %ecx
jg 0x1962c9
decl %eax
addq %r15, %rbx
movl %eax, (%r10)
movl 0x14(%rbx), %ecx
movq %r14, %rax
cmpl 0x14(%rdi), %ecx
je 0x196215
movq (%r9), %rdx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rdx
jne 0x1962af
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r9)
shlq $0x3, %rsi
movq %rdi, 0x10(%rsp)
movq %rax, %rdi
movl %r8d, 0xc(%rsp)
movq %r10, 0x18(%rsp)
movl %r11d, 0x8(%rsp)
callq 0x2370
movl 0x8(%rsp), %r11d
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %r10
movq 0x78(%rsp), %r9
movl 0xc(%rsp), %r8d
movq %rax, 0x10(%r9)
movl 0x14(%rbx), %ecx
movq (%r9), %rdx
incl %r11d
shlq $0x20, %rcx
orq %r13, %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r9)
movq %rcx, (%rax,%rdx,8)
jmp 0x196212
xorl %eax, %eax
cmpl %r8d, %r11d
jl 0x196327
movl %r8d, %ebx
movq (%r9), %rax
movq 0x10(%r9), %rdi
leaq (%rdi,%rax,8), %rsi
movq %r9, %r14
callq 0x156b0d
movq %r14, %r10
pushq $-0x1
popq %rcx
xorl %eax, %eax
xorl %edx, %edx
movslq (%r10), %rdi
movslq %edx, %rsi
cmpq %rdi, %rax
jge 0x19631d
movq 0x10(%r10), %r8
movq (%r8,%rax,8), %r9
movq %r9, %rdi
shrq $0x20, %rdi
cmpl %edi, %ecx
je 0x196318
movq %r9, (%r8,%rsi,8)
incl %esi
movl %esi, %edx
movl %edi, %ecx
incq %rax
jmp 0x1962f0
movq %rsi, (%r10)
xorl %eax, %eax
cmpl %ebx, %esi
cmovgel %esi, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq