// File: /workspace/github_cpp_makefile_star2_O2/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 $0xb8, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdi, 0x30(%rsp)
testq %r8, %r8
je 0x171f44
movq 0x100(%rsp), %rbp
movq 0xf8(%rsp), %r12
movq %r9, %rax
xorl %edx, %edx
divq %rbp
leaq (%r9,%rbp), %rax
subq %rdx, %rax
testq %rdx, %rdx
cmoveq %r9, %rax
cmpq %r12, %rax
jae 0x1722a3
movq %rcx, %r13
movq %rax, %rcx
movq 0xf0(%rsp), %r15
movq %r15, %rax
xorl %edx, %edx
divq %rbp
movq %r15, %rax
subq %rdx, %rax
cmpq %r12, %rax
cmovbq %rax, %r12
cmpq %rcx, %rax
jbe 0x1722a3
movq %rcx, %r14
movq 0x128(%rsp), %rax
movq (%rax), %rcx
xorl %edx, %edx
movq $0x0, 0x28(%rsp)
xorl %eax, %eax
cmpq %rdx, %r8
je 0x171f4c
movq (%r13,%rdx,8), %rsi
imulq $0x1c, %rsi, %rdi
movl 0x4(%rcx,%rdi), %r9d
cmpq %r9, %r14
jb 0x171f2e
addq %rcx, %rdi
movl 0x8(%rdi), %edi
cmpq %rdi, %r12
ja 0x171f2e
movq 0x108(%rsp), %rdi
movq %rsi, (%rdi,%rax,8)
incq %rax
movq (%r13,%rdx,8), %rsi
imulq $0x1c, %rsi, %rsi
movl 0x8(%rcx,%rsi), %esi
cmpq %r15, %rsi
adcq $0x0, 0x28(%rsp)
incq %rdx
jmp 0x171ef7
xorl %r8d, %r8d
jmp 0x1722a3
movq %r8, 0x20(%rsp)
cmpq 0x110(%rsp), %rax
jne 0x1722b8
cmpq $0x2, %rax
jb 0x1722b8
movq %r13, 0x10(%rsp)
movq %r12, 0x8(%rsp)
cmpq %r12, %r14
jae 0x172259
movq %r14, %rbx
addq %rbp, %r14
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x128(%rsp), %rcx
movq (%rcx), %rcx
movq 0x108(%rsp), %rdx
imulq $0x1c, (%rdx), %rdx
movl (%rcx,%rdx), %ecx
imulq $0xa8, %rcx, %rcx
leaq (%rax,%rcx), %rdi
movl 0x4(%rax,%rcx), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %rbp
leaq (%rdx,%rbx), %rax
subq %rcx, %rax
cqto
idivq %rbp
movq %rax, %rsi
leaq 0x60(%rsp), %rdx
leaq 0x68(%rsp), %rcx
leaq 0xb0(%rsp), %r8
callq 0x171d8e
testq %rax, %rax
je 0x171f73
cmpq %r12, %r14
cmovbq %r14, %r12
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
movq %rax, 0x78(%rsp)
subq %rax, %rcx
movq 0xb0(%rsp), %rax
movq %rax, 0x98(%rsp)
decq %rax
movq %rax, 0x90(%rsp)
movq %rcx, 0xa0(%rsp)
leaq 0x1(%rcx), %rax
movq %rax, 0x70(%rsp)
subq %rbx, %r12
movq %r12, 0x80(%rsp)
pushq $0x1
popq %r13
movq $0x0, 0x40(%rsp)
movq %rbx, %r8
movq %r14, %r15
movq %rbx, 0x88(%rsp)
movq %r14, 0x18(%rsp)
movq 0x48(%rsp), %rax
movq (%rax), %r12
movq 0x128(%rsp), %rax
movq (%rax), %rbx
cmpq %r13, 0x110(%rsp)
je 0x1721ef
movq 0x108(%rsp), %rax
imulq $0x1c, (%rax,%r13,8), %rax
movl (%rbx,%rax), %eax
imulq $0xa8, %rax, %rax
leaq (%r12,%rax), %r14
movl 0x4(%r12,%rax), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %rbp
leaq (%rdx,%r8), %rax
subq %rcx, %rax
cqto
idivq %rbp
movq %r14, %rdi
movq %rax, %rsi
leaq 0x50(%rsp), %rdx
leaq 0x58(%rsp), %rcx
leaq 0xa8(%rsp), %r8
callq 0x171d8e
testq %rax, %rax
je 0x17223f
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbp
subq %r15, %rbp
movq 0xa8(%rsp), %rax
cmpq %rbp, 0xa0(%rsp)
jne 0x1721cb
cmpq %rax, 0x98(%rsp)
jne 0x1721cb
cmpq $-0x3, 0x90(%rsp)
ja 0x1721ae
cmpq $0x0, 0x40(%rsp)
jne 0x172163
movq 0x108(%rsp), %rax
imulq $0x1c, (%rax), %rax
movl (%rbx,%rax), %eax
imulq $0xa8, %rax, %rax
movl 0x10(%r12,%rax), %ecx
movl 0x1c(%r12,%rax), %r9d
movq %rcx, (%rsp)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq 0x70(%rsp), %r8
callq 0x171df0
movq %rax, 0x40(%rsp)
incq %rbp
movl 0x10(%r14), %eax
movl 0x1c(%r14), %r9d
movq %rax, (%rsp)
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x120(%rsp), %rbx
movq %rbx, %rdx
movq %r15, %rcx
movq %rbp, %r8
callq 0x171df0
movq 0x118(%rsp), %rdi
movq %rbx, %rsi
movq 0x80(%rsp), %rdx
callq 0x21a0
testl %eax, %eax
jne 0x1721cb
incq %r13
movq 0x100(%rsp), %rbp
movq 0x18(%rsp), %r15
movq 0x88(%rsp), %r8
jmp 0x172056
movq 0x10(%rsp), %r13
movq 0xf0(%rsp), %r15
movq 0x100(%rsp), %rbp
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %r14
jmp 0x171f73
xorl %esi, %esi
cmpq %rsi, 0x110(%rsp)
je 0x17223f
movq 0x108(%rsp), %rax
imulq $0x1c, (%rax,%rsi,8), %rax
movl (%rbx,%rax), %eax
imulq $0xa8, %rax, %rdi
movl 0x4(%r12,%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %rbp
leaq (%rdx,%r8), %rax
subq %rcx, %rax
cqto
idivq %rbp
movq 0x58(%r12,%rdi), %rcx
shlq $0x5, %rax
orw $-0x1, 0x12(%rcx,%rax)
incq %rsi
jmp 0x1721f1
movq 0x10(%rsp), %r13
movq %r15, %r14
movq 0xf0(%rsp), %r15
movq 0x8(%rsp), %r12
jmp 0x171f73
cmpq $0x0, 0x28(%rsp)
je 0x17229e
movq 0x128(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
xorl %edx, %edx
movq 0x20(%rsp), %r8
cmpq %rcx, %r8
je 0x172299
movq (%r13,%rcx,8), %rsi
imulq $0x1c, %rsi, %rdi
movl 0x8(%rax,%rdi), %edi
cmpq %r15, %rdi
jb 0x172294
movq %rsi, (%r13,%rdx,8)
incq %rdx
incq %rcx
jmp 0x172275
movq %rdx, %r8
jmp 0x1722a3
movq 0x20(%rsp), %r8
movq %r8, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x74934(%rip), %rdi     # 0x1e6bf3
leaq 0x7f85d(%rip), %rsi     # 0x1f1b23
leaq 0x81432(%rip), %rcx     # 0x1f36ff
movl $0x1caf, %edx           # imm = 0x1CAF
callq 0x2110