// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: update_shared_intervals(overlap_region_alloc*, ul_idx_t const*, ug_opt_t const*, All_reads*, UC_Read*, kvec_t_u64_warp*, st_mt_t*, long, long, kv_ul_ov_t*, unsigned long)
void update_shared_intervals(overlap_region_alloc* ol, const ul_idx_t *uref, const ug_opt_t *uopt, 
All_reads *rref, UC_Read* tu, kvec_t_u64_warp* idx, st_mt_t *sps, int64_t ql, int64_t wl, kv_ul_ov_t *aln, uint64_t rid)
{
	if(!aln->n) return;
	uint64_t i, k, own, srt_n; int64_t dp, old_dp, beg, end; overlap_region *z;
    for (i = 0; i < ol->length; i++) {
		z = &(ol->list[i]); append_unmatched_wins(z, wl); 
		own = z->w_list.n; z->align_length = (uint32_t)-1;
		for (k = 0; k < own; k++) {
			if(z->w_list.a[k].extra_end < 0) z->w_list.a[k].extra_end = 0;
		}		
    }

    kv_resize(uint64_t, idx->a, (aln->n<<1)); kv_resize(uint64_t, *sps, aln->n);
    for (i = srt_n = 0; i < aln->n; i++) {
		if(i == 0 || aln->a[i].qn != aln->a[i-1].qn) ol->list[aln->a[i].qn].align_length = i;
        idx->a.a[srt_n] = aln->a[i].qs<<1; idx->a.a[srt_n] <<= 32; idx->a.a[srt_n] += i; srt_n++;
        idx->a.a[srt_n] = ((aln->a[i].qe-1)<<1)+1; idx->a.a[srt_n] <<= 32; idx->a.a[srt_n] += i; srt_n++;
		aln->a[i].el = 1;
    }

    radix_sort_gfa64(idx->a.a, idx->a.a+srt_n); idx->a.n = srt_n; resize_UC_Read(tu, (wl<<1));
    for (i = 0, dp = 0, beg = 0, end = -1; i < srt_n; ++i) {///[beg, end]
		old_dp = dp;
        ///if idx->a.a[] is qe
        if ((idx->a.a[i]>>32)&1) {
			--dp; end = (idx->a.a[i]>>33)+1;
		}else {
			//meet a new overlap; the overlaps are pushed by the x_pos_s
			++dp; end = (idx->a.a[i]>>33);
			kv_push(uint64_t, idx->a, ((uint32_t)idx->a.a[i]));
		}
		///[beg, end)
		// if(rid == 92) {
		// 	fprintf(stderr, "[M::%s::input] beg::%ld, end::%ld, old_dp::%ld, dp::%ld\n", 
		// 	__func__, beg, end, old_dp, dp);
		// }
		if((end > beg) && (end - beg > wl) && (old_dp >= 2) ) {
			idx->a.n = srt_n + 
					gen_commen_win(rref, uref, ol, idx->a.a+srt_n, idx->a.n-srt_n, beg, end, ql, wl, sps->a, old_dp, tu->seq, tu->seq+wl, aln);
		}
        beg = end;
	}

	return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x8(%rsp)
movq %rcx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x1bcc46
movq 0x70(%rsp), %rbp
movq 0x10(%rsp), %r13
cmpq $0x0, 0x10(%r13)
movq %r9, (%rsp)
je 0x1bc988
xorl %ebx, %ebx
movq (%r13), %r14
imulq $0xa8, %rbx, %r12
leaq (%r14,%r12), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x49760
movq 0x48(%r14,%r12), %rax
movl $0xffffffff, 0x28(%r14,%r12) # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1bc972
movq 0x58(%r15), %rcx
addq $0x12, %rcx
cmpw $0x0, (%rcx)
jns 0x1bc969
movw $0x0, (%rcx)
addq $0x20, %rcx
decq %rax
jne 0x1bc95e
incq %rbx
cmpq 0x10(%r13), %rbx
jb 0x1bc929
movq 0x78(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rsp), %r9
movq 0x60(%rsp), %r14
leaq (%rax,%rax), %rcx
cmpq %rcx, 0x8(%r9)
movq 0x78(%rsp), %rbx
jae 0x1bc9f5
decq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r9)
movq 0x10(%r9), %rdi
leaq 0x8(,%rax,8), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%r9)
movq 0x8(%rbx), %rax
cmpq %rax, 0x8(%r14)
jae 0x1bca54
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%r14)
movq 0x8(%rbx), %rax
movabsq $0x100000000, %r10      # imm = 0x100000000
testq %rax, %rax
je 0x1bcad8
movl $0xc, %eax
xorl %ecx, %ecx
xorl %ebp, %ebp
movq (%rbx), %rdx
testq %rcx, %rcx
je 0x1bca80
movl -0x18(%rdx,%rax,2), %esi
cmpl -0x34(%rdx,%rax,2), %esi
jne 0x1bca82
jmp 0x1bca93
movl (%rdx), %esi
movq (%r13), %rdi
movl %esi, %esi
imulq $0xa8, %rsi, %rsi
movl %ecx, 0x28(%rdi,%rsi)
movq 0x10(%r9), %rsi
movl -0x14(%rdx,%rax,2), %edi
shlq $0x21, %rdi
addq %rcx, %rdi
movq %rdi, (%rsi,%rbp,8)
movl -0x10(%rdx,%rax,2), %edi
leal -0x2(,%rdi,2), %edi
shlq $0x20, %rdi
addq %rcx, %rdi
addq %r10, %rdi
movq %rdi, 0x8(%rsi,%rbp,8)
addq $0x2, %rbp
orb $0x40, 0x3(%rdx,%rax,2)
incq %rcx
addq $0xe, %rax
cmpq 0x8(%rbx), %rcx
jb 0x1bca6c
jmp 0x1bcada
xorl %ebp, %ebp
movq 0x10(%r9), %rdi
leaq (%rdi,%rbp,8), %rsi
callq 0x19dd99
movq (%rsp), %rdi
movq %rbp, (%rdi)
movq 0x70(%rsp), %rax
leaq (%rax,%rax), %r15
movq 0x8(%rsp), %rax
cmpq %r15, 0x10(%rax)
jge 0x1bcb1d
movq 0x8(%rsp), %rbx
movq (%rbx), %rdi
movq %r15, %rsi
callq 0x2370
movq (%rsp), %rdi
movq %rax, (%rbx)
movq %r15, 0x10(%rbx)
testq %rbp, %rbp
movabsq $0x100000000, %r8       # imm = 0x100000000
je 0x1bcc46
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebx, %ebx
movq %rbx, %r13
movq %r15, %r14
movq 0x10(%rdi), %rax
movq (%rax,%r12,8), %rcx
movq %rcx, %r15
shrq $0x21, %r15
testq %r8, %rcx
jne 0x1bcba7
movq (%rdi), %rdx
cmpq 0x8(%rdi), %rdx
jne 0x1bcb94
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdi)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movabsq $0x100000000, %r8       # imm = 0x100000000
movq (%rsp), %rdi
movq %rax, 0x10(%rdi)
movl (%rax,%r12,8), %ecx
movq (%rdi), %rdx
leaq 0x1(%r13), %rbx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rdi)
movq %rcx, (%rax,%rdx,8)
jmp 0x1bcbae
leaq -0x1(%r13), %rbx
incq %r15
movq %r15, %rcx
subq %r14, %rcx
jbe 0x1bcc3a
cmpq 0x70(%rsp), %rcx
setg %cl
cmpq $0x2, %r13
setge %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1bcc3a
leaq (%rax,%rbp,8), %rcx
movq (%rdi), %r8
subq %rbp, %r8
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x70(%rsp), %r11
leaq (%rax,%r11), %r10
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %r14, %r9
pushq 0x78(%rsp)
pushq %r10
pushq %rax
pushq %r13
movq 0x80(%rsp), %rax
pushq 0x10(%rax)
pushq %r11
pushq 0x98(%rsp)
pushq %r15
callq 0x1bc415
movabsq $0x100000000, %r8       # imm = 0x100000000
movq 0x40(%rsp), %rdi
addq $0x40, %rsp
addq %rbp, %rax
movq %rax, (%rdi)
incq %r12
cmpq %r12, %rbp
jne 0x1bcb38
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq