// File: /workspace/github_cpp_makefile_star2_O3/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 0x1e2b7a
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 0x1e2b7a
movl %r13d, (%r10)
movl (%rbp), %edi
cmpl 0x14(%r15), %edi
je 0x1e2b67
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x1e2b52
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movl %r14d, 0x14(%rsp)
movq %r15, %rbx
movl %r12d, %r15d
movq %r8, %r12
movq %r10, %r14
callq 0x2370
movq %r14, %r10
movq %r12, %r8
movl %r15d, %r12d
movq %rbx, %r15
movq 0x68(%rsp), %rbx
movl 0x14(%rsp), %r14d
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %r9
movq %rax, 0x10(%rbx)
movl (%rbp), %edi
movq (%rbx), %rdx
incl %r14d
shlq $0x20, %rdi
orq %r13, %rdi
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
movq %rdi, (%rax,%rdx,8)
incq %r13
addq $0x18, %rbp
movl %r8d, %eax
addl %r13d, %eax
jne 0x1e2ad1
movl 0xc(%rsp), %eax
testl %eax, %eax
jle 0x1e2c28
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 0x1e2c28
leal -0x1(%r13), %eax
movl %eax, (%r9)
movl (%rbp), %edx
cmpl 0x14(%r15), %edx
je 0x1e2c13
movq (%rbx), %rdi
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdi
jne 0x1e2bfb
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movl 0x8(%rsp), %ecx
movq 0x20(%rsp), %r9
movq %rax, 0x10(%rbx)
movl (%rbp), %edx
movq (%rbx), %rdi
incl %r14d
shlq $0x20, %rdx
addq %r13, %rdx
decq %rdx
leaq 0x1(%rdi), %rsi
movq %rsi, (%rbx)
movq %rdx, (%rax,%rdi,8)
decq %r13
leaq 0x1(%r13), %rax
addq $-0x18, %rbp
cmpq $0x1, %rax
ja 0x1e2ba1
xorl %eax, %eax
movl 0x10(%rsp), %ebp
cmpl %ebp, %r14d
jl 0x1e2c99
movq (%rbx), %rax
movq 0x10(%rbx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x19dd99
movq (%rbx), %rcx
xorl %eax, %eax
movl $0x0, %esi
testl %ecx, %ecx
jle 0x1e2c8e
movq 0x10(%rbx), %rdx
xorl %edi, %edi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %esi, %esi
movq (%rdx,%rdi,8), %r10
movq %r10, %r8
shrq $0x20, %r8
cmpl %r8d, %r9d
jne 0x1e2c74
movl %r9d, %r8d
jmp 0x1e2c80
movslq %esi, %rsi
movq %r10, (%rdx,%rsi,8)
incl %esi
movq (%rbx), %rcx
incq %rdi
movslq %ecx, %r10
movl %r8d, %r9d
cmpq %r10, %rdi
jl 0x1e2c5f
movslq %esi, %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