// File: /workspace/github_cpp_makefile_star2_O2/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), %r11d
testq %rdx, %rdx
je 0x160325
movq (%rdx), %rax
jmp 0x160327
xorl %eax, %eax
testq %rcx, %rcx
je 0x16032f
movq %r11, (%rcx)
testq %rdx, %rdx
je 0x160337
movq %r11, (%rdx)
cmpq %r11, %rax
jae 0x16035c
movq (%rdi), %r9
imulq $0x18, %rax, %r10
movl 0x4(%r9,%r10), %r9d
cmpq %rsi, %r9
jbe 0x16035c
testq %rcx, %rcx
je 0x160355
movq %rax, (%rcx)
xorl %ebx, %ebx
jmp 0x1604a8
movq %rax, %r9
leaq 0x1(%rax), %r12
imulq $0x18, %rax, %r10
leaq 0x1c(%r10), %rbx
cmpq %r11, %r12
ja 0x16046b
movq (%rdi), %r15
movl 0x4(%r15,%r10), %r14d
cmpq %rsi, %r14
ja 0x160471
movq %r12, %rax
cmpq %r12, %r11
je 0x16039e
leaq 0x1(%rax), %r12
leaq 0x18(%rbx), %r13
cmpl %r14d, (%r15,%rbx)
movq %r13, %rbx
je 0x16036b
cmpq %rsi, %r14
jne 0x16035c
xorl %ebx, %ebx
movq %r9, %r14
xorl %esi, %esi
cmpq %rax, %r14
jae 0x1604ba
movq (%rdi), %r15
cmpb $0x1, 0xc(%r15,%r10)
jne 0x16045f
movq 0x218(%rdi), %r12
movl 0x8(%r15,%r10), %r13d
imulq $0x28, %r13, %r13
cmpl $0x1, 0x1c(%r12,%r13)
jne 0x16045f
addq %r13, %r12
cmpl $0x2, 0x8(%r12)
jb 0x16045f
cmpl $0x2, 0xc(%r12)
jb 0x16045f
leaq (%rbx,%r9), %r12
cmpq %r12, %r14
je 0x16043e
leaq (%r15,%r10), %r13
imulq $0x18, %r12, %rbp
movq 0x10(%r15,%rbp), %r11
movq %r11, 0x10(%rsp)
movups (%r15,%rbp), %xmm0
movaps %xmm0, (%rsp)
movups (%r13), %xmm0
movups %xmm0, (%r15,%rbp)
movq 0x10(%r13), %r11
movq %r11, 0x10(%r15,%rbp)
movq (%rdi), %r11
movq 0x10(%rsp), %r15
movq %r15, 0x10(%r11,%r10)
movaps (%rsp), %xmm0
movups %xmm0, (%r11,%r10)
testq %rbx, %rbx
je 0x16045c
movq (%rdi), %r11
imulq $0x18, %r12, %r15
movl 0x10(%r11,%r15), %ebp
cmpl -0x8(%r11,%r15), %ebp
pushq $0x1
popq %r11
cmovbq %r11, %rsi
incq %rbx
incq %r14
addq $0x18, %r10
jmp 0x1603aa
xorl %ebx, %ebx
xorl %esi, %esi
jmp 0x160483
xorl %ebx, %ebx
movq %r9, %rax
movl $0x0, %esi
testq %rcx, %rcx
je 0x160483
movq %rax, (%rcx)
testq %r8, %r8
je 0x1604a8
testq %rbx, %rbx
je 0x1604a8
testq %rsi, %rsi
je 0x1604a8
imulq $0x18, %r9, %rax
addq (%rdi), %rax
imulq $0x18, %rbx, %rsi
addq %rax, %rsi
movq %rax, %rdi
callq 0x157e29
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rdx, %rdx
je 0x16047b
movq %r9, (%rdx)
jmp 0x16047b