// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_commen_win(All_reads*, ul_idx_t const*, overlap_region_alloc*, unsigned long*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long*, unsigned long, char*, char*, kv_ul_ov_t*)
uint64_t gen_commen_win(All_reads *rref, const ul_idx_t *uref, overlap_region_alloc* ol, uint64_t *id_a, uint64_t id_n, uint64_t s, uint64_t e, uint64_t ql, uint64_t wl,
uint64_t *buf, uint64_t dp, char *str0, char *str1, kv_ul_ov_t *aln)///[s, e)
{
	if(!id_n) return id_n;
	uint64_t i, m, k, rm_n = 0, buf_n = 0, qs, qe, wid; char *qstring, *tstring;
	overlap_region *z; uint64_t ws, we; int64_t r_y[2], r_err, p_y[2], p_err;
	///shrink [qs, qe)
	qs = (s/wl)*wl; if(qs < s) qs += wl; if(qs >= ql) return id_n;
	qe = (e/wl)*wl; if(qe >= ql) qe = ql;
	if(qs >= qe) return id_n;
	//idx_a[] is sorted by aln[].qs
	for (k = 0; k < id_n; k++) {
		if(aln->a[id_a[k]].qs<=qs && aln->a[id_a[k]].qe>=qe) {
			buf[buf_n++] = id_a[k];
		}
		if(aln->a[id_a[k]].qe < e) rm_n++;
	}
	assert(buf_n == dp && buf_n > 1);

	if(buf_n > 0) {
		///fs = fe = (uint64_t)-1;
		for (k = qs; k < qe; k += wl) {
			ws = k; we = ws + wl; if(we > qe) we = qe;//[ws, we)
			// fprintf(stderr, ">>>[M::%s::] w[%lu, %lu), buf_n::%lu\n", __func__, ws, we, buf_n);
			///first overlap
			z = &(ol->list[aln->a[buf[0]].qn]);
			wid = get_win_id_by_s(z, ws, wl, NULL);
			if(!get_win_info(z, wid, &(r_y[0]), &(r_y[1]), &r_err)) continue;
			// fprintf(stderr, "###[M::%s::] y[%ld, %ld), off::%ld, y_err::%ld\n", __func__, r_y[0], r_y[1], r_y[1]-r_y[0], r_err);
			qstring = tstring = NULL;
			for (i = 1; i < buf_n; i++) {
				z = &(ol->list[aln->a[buf[i]].qn]);
				wid = get_win_id_by_s(z, ws, wl, NULL);
				if(!get_win_info(z, wid, &(p_y[0]), &(p_y[1]), &p_err)) break;
				// fprintf(stderr, "###[M::%s::] y[%ld, %ld), off::%ld, y_err::%ld\n", __func__, p_y[0], p_y[1], p_y[1]-p_y[0], p_err);
				if(((r_y[1]-r_y[0]) != (p_y[1]-p_y[0])) || (r_err != p_err)) break;
				if(r_err == 0) continue;
				if(r_err != -1) {///if this window ar all overlaps is unmapped
					if(!qstring) {
						qstring = retrive_str_piece(rref, uref, str0, r_y[0], r_y[1]+1-r_y[0], 
													ol->list[aln->a[buf[0]].qn].y_pos_strand, ol->list[aln->a[buf[0]].qn].y_id);
					}
					tstring = retrive_str_piece(rref, uref, str1, p_y[0], p_y[1]+1-p_y[0], z->y_pos_strand, z->y_id);
					if(memcmp(str0, str1, (we-ws))) break;
				}
			}
			if(i < buf_n) continue;
			for (i = 0; i < buf_n; i++) {
				z = &(ol->list[aln->a[buf[i]].qn]);
				wid = get_win_id_by_s(z, ws, wl, NULL);
				z->w_list.a[wid].extra_end = -1;
			}
			// if(fs == (uint64_t)-1) {
			// 	fs = ws; fe = we;
			// } else if(ws >= fs && ws <= fe) {
			// 	if(fe < we) fe = we;
			// } else {
			// 	kv_pushp(ul_ov_t, *aln, &p); p->el = 0; p->qs = fs; p->qe = fe;
			// 	fs = ws; fe = we;
			// }
		}
		// if(fs != (uint64_t)-1) {
		// 	kv_pushp(ul_ov_t, *aln, &p); p->el = 0; p->qs = fs; p->qe = fe;
		// }
	}
	if(rm_n) {
		for (i = m = 0; i < id_n; i++) {
			if(aln->a[id_a[i]].qe < e) continue;
			id_a[m++] = id_a[i];
		}
		id_n = m;
	}
	return id_n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, 0x18(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdi, 0x40(%rsp)
testq %r8, %r8
je 0x1b30b1
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rbx
movq %r9, %rax
xorl %edx, %edx
divq %rsi
leaq (%rsi,%r9), %r14
subq %rdx, %r14
testq %rdx, %rdx
cmoveq %r9, %r14
cmpq %rbx, %r14
jae 0x1b30ac
movq 0x100(%rsp), %r11
movq %r11, %rax
xorl %edx, %edx
divq %rsi
movq %r11, %rax
subq %rdx, %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
cmpq %r14, %rax
jbe 0x1b30ac
movq 0x138(%rsp), %rdx
movq 0x120(%rsp), %rax
movq (%rdx), %r10
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %edx, %edx
movq (%rcx,%rdx,8), %rsi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movl 0x4(%r10,%rdi), %r9d
cmpq %r9, %r14
jb 0x1b2cd6
addq %r10, %rdi
movl 0x8(%rdi), %edi
cmpq %rdi, %rbx
ja 0x1b2cd6
movq 0x118(%rsp), %rdi
movq %rsi, (%rdi,%r15,8)
incq %r15
movq (%rcx,%rdx,8), %rsi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movl 0x8(%r10,%rdi), %esi
cmpq %r11, %rsi
adcq $0x0, %r12
incq %rdx
cmpq %rdx, %r8
jne 0x1b2ca3
movq %r12, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %r8, 0x30(%rsp)
cmpq %rax, %r15
jne 0x1b30cc
cmpq $0x2, %r15
jb 0x1b30cc
movq %r15, 0x20(%rsp)
cmpq %rbx, %r14
movq 0x110(%rsp), %r10
movq 0x118(%rsp), %r11
jae 0x1b3052
movq %rbx, 0x90(%rsp)
leaq (%r14,%r10), %rax
cmpq %rbx, %rax
movq %rax, 0x98(%rsp)
cmovbq %rax, %rbx
movq %rbx, 0x10(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x138(%rsp), %rcx
movq (%rcx), %rcx
movq (%r11), %rdx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl (%rcx,%rsi), %ecx
imulq $0xa8, %rcx, %rcx
leaq (%rax,%rcx), %rdi
movl 0x4(%rax,%rcx), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r10
movq %r14, 0x28(%rsp)
leaq (%rdx,%r14), %rax
subq %rcx, %rax
cqto
idivq %r10
movq %rax, %rsi
leaq 0x60(%rsp), %rdx
leaq 0x68(%rsp), %rcx
leaq 0xc0(%rsp), %r8
callq 0x1b2b23
movq 0x118(%rsp), %r11
movq 0x110(%rsp), %r10
testq %rax, %rax
je 0x1b3039
cmpq $0x2, 0x20(%rsp)
jb 0x1b2fd3
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rax, 0x88(%rsp)
subq %rax, %rcx
movq 0xc0(%rsp), %rax
movq %rax, 0xa8(%rsp)
decq %rax
movq %rax, 0xa0(%rsp)
movq %rcx, 0xb0(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x80(%rsp)
movq 0x10(%rsp), %rax
subq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x1, %r14d
movq $0x0, 0x38(%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %r15
movq 0x138(%rsp), %rax
movq (%rax), %rbp
movq (%r11,%r14,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl (%rbp,%rcx), %eax
imulq $0xa8, %rax, %rax
leaq (%r15,%rax), %r13
movl 0x4(%r15,%rax), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r10
movq 0x28(%rsp), %rax
addq %rdx, %rax
subq %rcx, %rax
cqto
idivq %r10
movq %r13, %rdi
movq %rax, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0xb8(%rsp), %r8
callq 0x1b2b23
movq 0x118(%rsp), %r11
movq 0x110(%rsp), %r10
testq %rax, %rax
je 0x1b3039
movq 0x50(%rsp), %rbx
movq 0x58(%rsp), %r12
subq %rbx, %r12
cmpq %r12, 0xb0(%rsp)
jne 0x1b3039
movq 0xa8(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jne 0x1b3039
cmpq $-0x3, 0xa0(%rsp)
ja 0x1b2fc5
cmpq $0x0, 0x38(%rsp)
jne 0x1b2f6d
movq 0x118(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl (%rbp,%rcx), %eax
imulq $0xa8, %rax, %rax
movl 0x10(%r15,%rax), %ecx
movl 0x1c(%r15,%rax), %r9d
movq %rcx, (%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x128(%rsp), %rdx
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %r8
callq 0x1b2b9b
movq %rax, 0x38(%rsp)
incq %r12
movl 0x10(%r13), %eax
movl 0x1c(%r13), %r9d
movq %rax, (%rsp)
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
movq 0x130(%rsp), %r15
movq %r15, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x1b2b9b
movq 0x128(%rsp), %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x21a0
testl %eax, %eax
movq 0x110(%rsp), %r10
movq 0x118(%rsp), %r11
jne 0x1b3039
incq %r14
cmpq %r14, 0x20(%rsp)
jne 0x1b2e46
movq 0x18(%rsp), %rax
movq (%rax), %rsi
movq 0x138(%rsp), %rax
movq (%rax), %rdi
xorl %r8d, %r8d
movq (%r11,%r8,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl (%rdi,%rcx), %eax
imulq $0xa8, %rax, %r9
movl 0x4(%rsi,%r9), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r10
movq 0x28(%rsp), %rax
addq %rdx, %rax
subq %rcx, %rax
cqto
idivq %r10
movq 0x58(%rsi,%r9), %rcx
shlq $0x5, %rax
movw $0xffff, 0x12(%rcx,%rax) # imm = 0xFFFF
incq %r8
cmpq %r8, 0x20(%rsp)
jne 0x1b2fe9
movq 0x90(%rsp), %rbx
movq 0x98(%rsp), %r14
cmpq %rbx, %r14
jb 0x1b2d41
cmpq $0x0, 0x78(%rsp)
je 0x1b30c5
movq 0x138(%rsp), %rax
movq (%rax), %rcx
movq 0x30(%rsp), %r8
cmpq $0x1, %r8
adcq $0x0, %r8
xorl %eax, %eax
xorl %edx, %edx
movq 0x70(%rsp), %r9
movq 0x100(%rsp), %r10
movq (%r9,%rdx,8), %rsi
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rsi, %rdi
movl 0x8(%rcx,%rdi), %edi
cmpq %r10, %rdi
jb 0x1b30a2
movq %rsi, (%r9,%rax,8)
incq %rax
incq %rdx
cmpq %rdx, %r8
jne 0x1b3083
jmp 0x1b30b3
movq %r8, %rax
jmp 0x1b30b3
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rax
jmp 0x1b30b3
leaq 0x75ac0(%rip), %rdi     # 0x228b93
leaq 0x808b1(%rip), %rsi     # 0x23398b
leaq 0x82486(%rip), %rcx     # 0x235567
movl $0x1caf, %edx           # imm = 0x1CAF
callq 0x2110