// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: update_ava_het_site(haplotype_evdience_alloc*, unsigned long, unsigned long*, unsigned long*, unsigned long)
uint64_t update_ava_het_site(haplotype_evdience_alloc *h, uint64_t oid, uint64_t *beg, uint64_t *end, uint64_t is_srt)
{
	uint64_t k, l, i, occ = 0, n = h->length, need_srt = 0; SnpStats *s = NULL;
	haplotype_evdience tt;
	l = beg? (*beg):0; if(end) (*end) = n; if(beg) (*beg) = n;
	if(l < n && h->list[l].overlapID > oid){
		if(end) (*end) = l;
		return 0;
	}
	for (k = l + 1; k <= n; ++k) {  
		if(h->list[l].overlapID > oid) {
			if(end) (*end) = l;
			break;
		}
        if (k == n || h->list[k].overlapID != h->list[l].overlapID) {
			if(h->list[l].overlapID == oid) {
				for (i = l; i < k; i++) {
					if(h->list[i].type!=1) continue; 
					s = &(h->snp_stat.a[h->list[i].overlapSite]);
					if(s->score == 1 && (!(s->occ_0 < 2 || s->occ_1 < 2))) {
						if(l+occ != i) {
							tt = h->list[l+occ];
							h->list[l+occ] = h->list[i];
							h->list[i] = tt;
						}
						if((occ>0) && (h->list[l+occ].cov<h->list[l+occ-1].cov)) need_srt = 1;
						occ++;
					}
				}
				if(beg) (*beg) = l;
				if(end) (*end) = k;
				break;
			}
            l = k;
        }
    }
	// if(oid == 160) {
	// 	fprintf(stderr, "###[M::%s] l:%lu, occ:%lu\n", __func__, l, occ);
	// 	for (k = l; k < l + occ; k++) {
	// 		fprintf(stderr, "h->list[%lu]:%u\n", k, h->list[k].cov);
	// 	}
	// }
	if(occ && is_srt && need_srt) {
		radix_sort_hap_ev_cov_srt(h->list+l, h->list+l+occ);
	}

	return occ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x10(%rdi), %r10d
testq %rdx, %rdx
je 0x19f242
movq (%rdx), %rax
jmp 0x19f244
xorl %eax, %eax
testq %rcx, %rcx
je 0x19f24c
movq %r10, (%rcx)
testq %rdx, %rdx
je 0x19f254
movq %r10, (%rdx)
cmpq %r10, %rax
jae 0x19f279
movq (%rdi), %r9
leaq (%rax,%rax,2), %r11
movl 0x4(%r9,%r11,8), %r9d
cmpq %rsi, %r9
jbe 0x19f279
testq %rcx, %rcx
je 0x19f272
movq %rax, (%rcx)
xorl %ebx, %ebx
jmp 0x19f414
leaq 0x1(%rax), %r9
cmpq %r10, %r9
jbe 0x19f286
xorl %ebx, %ebx
jmp 0x19f2f1
movq (%rdi), %r11
negq %r10
leaq (%rax,%rax,2), %rbx
leaq (%r11,%rbx,8), %r14
addq $0x1c, %r14
xorl %ebx, %ebx
leaq (%rax,%rax,2), %r15
movl 0x4(%r11,%r15,8), %r12d
cmpq %rsi, %r12
ja 0x19f2de
movq %r10, %r15
addq %r9, %r15
je 0x19f2ba
cmpl %r12d, (%r14)
jne 0x19f2ba
movq %rax, %r15
jmp 0x19f2c2
movq %r9, %r15
cmpq %rsi, %r12
je 0x19f2f8
leaq (%r10,%r9), %r12
incq %r12
incq %r9
addq $0x18, %r14
movq %r15, %rax
cmpq $0x1, %r12
jne 0x19f29a
movq %r15, %rax
jmp 0x19f2f1
xorl %ebx, %ebx
movq %rax, %r9
movl $0x0, %esi
testq %rcx, %rcx
jne 0x19f3e7
xorl %esi, %esi
jmp 0x19f3ea
cmpq %r9, %rax
jae 0x19f3d6
leaq (,%rax,8), %rsi
leaq (%rsi,%rsi,2), %r10
xorl %esi, %esi
xorl %ebx, %ebx
movq %rax, %r14
movq (%rdi), %r15
cmpb $0x1, 0xc(%r15,%r10)
jne 0x19f3c4
movq 0x218(%rdi), %r12
movl 0x8(%r15,%r10), %r13d
leaq (%r13,%r13,4), %r13
cmpl $0x1, 0x1c(%r12,%r13,8)
jne 0x19f3c4
leaq (%r12,%r13,8), %r12
cmpl $0x2, 0x8(%r12)
jb 0x19f3c4
cmpl $0x2, 0xc(%r12)
jb 0x19f3c4
leaq (%rbx,%rax), %r12
cmpq %r12, %r14
je 0x19f3a1
leaq (%r15,%r10), %r13
leaq (%r12,%r12,2), %rbp
movq 0x10(%r15,%rbp,8), %r11
movq %r11, 0x10(%rsp)
movups (%r15,%rbp,8), %xmm0
movaps %xmm0, (%rsp)
movups (%r13), %xmm0
movups %xmm0, (%r15,%rbp,8)
movq 0x10(%r13), %r11
movq %r11, 0x10(%r15,%rbp,8)
movq (%rdi), %r11
movq 0x10(%rsp), %r15
movq %r15, 0x10(%r11,%r10)
movaps (%rsp), %xmm0
movups %xmm0, (%r11,%r10)
testq %rbx, %rbx
je 0x19f3c1
movq (%rdi), %r11
leaq (%r12,%r12,2), %r15
movl 0x10(%r11,%r15,8), %ebp
cmpl -0x8(%r11,%r15,8), %ebp
movl $0x1, %r11d
cmovbq %r11, %rsi
incq %rbx
incq %r14
addq $0x18, %r10
cmpq %r9, %r14
jb 0x19f314
jmp 0x19f3da
xorl %ebx, %ebx
xorl %esi, %esi
testq %rdx, %rdx
je 0x19f3e2
movq %rax, (%rdx)
testq %rcx, %rcx
je 0x19f3ea
movq %r9, (%rcx)
testq %r8, %r8
je 0x19f414
testq %rbx, %rbx
je 0x19f414
testq %rsi, %rsi
je 0x19f414
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq (%rdi), %rax
leaq (%rbx,%rbx,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rax, %rdi
callq 0x19640b
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq