// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
testq %r8, %r8
je 0x1bc8a4
movq %rdx, %r10
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %rbx
movq %r9, %rax
xorl %edx, %edx
divq %rsi
leaq (%rsi,%r9), %r15
subq %rdx, %r15
testq %rdx, %rdx
cmoveq %r9, %r15
cmpq %rbx, %r15
jae 0x1bc89f
movq 0xc0(%rsp), %r11
movq %r11, %rax
xorl %edx, %edx
divq %rsi
movq %r11, %rax
subq %rdx, %rax
cmpq %rbx, %rax
cmovbq %rax, %rbx
cmpq %r15, %rax
jbe 0x1bc89f
movq %r10, 0x18(%rsp)
movq 0xf8(%rsp), %rax
movq (%rax), %r10
xorl %eax, %eax
xorl %r14d, %r14d
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, %r15
jb 0x1bc4df
addq %r10, %rdi
movl 0x8(%rdi), %edi
cmpq %rdi, %rbx
ja 0x1bc4df
movq 0xd8(%rsp), %rdi
movq %rsi, (%rdi,%rax,8)
incq %rax
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, %r14
incq %rdx
cmpq %rdx, %r8
jne 0x1bc4a8
movq %rcx, 0x40(%rsp)
movq %r8, 0x10(%rsp)
cmpq 0xe0(%rsp), %rax
jne 0x1bc8bf
cmpq $0x2, %rax
jb 0x1bc8bf
cmpq %rbx, %r15
movq 0x18(%rsp), %r10
movq 0xd0(%rsp), %r11
jae 0x1bc850
movq %rbx, 0x50(%rsp)
movq %r14, 0x48(%rsp)
leaq (%r15,%r11), %r8
cmpq %rbx, %r8
cmovbq %r8, %rbx
movq %rbx, 0x30(%rsp)
movq (%r10), %rsi
movq 0xf8(%rsp), %rax
movq (%rax), %rax
movq 0xd8(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl (%rax,%rdx), %eax
imulq $0xa8, %rax, %rdi
movl 0x4(%rsi,%rdi), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
leaq (%rdx,%r15), %rax
subq %rcx, %rax
cqto
idivq %r11
movq 0x58(%rsi,%rdi), %rcx
testq %rax, %rax
movq %r8, 0x68(%rsp)
je 0x1bc5d9
shlq $0x5, %rax
movslq 0xc(%rcx,%rax), %rdi
cmpq $-0x1, %rdi
je 0x1bc5e3
movslq -0x14(%rcx,%rax), %rsi
cmpq $-0x1, %rsi
je 0x1bc838
movq %rsi, %rdx
cmpl %edx, %edi
jle 0x1bc838
incq %rdx
movswq 0x14(%rcx,%rax), %r8
jmp 0x1bc5f8
cmpl $-0x1, 0xc(%rcx)
jne 0x1bc838
movq $-0x2, %r8
movq $-0x3, %rdi
movq $-0x3, %rdx
movq %rdx, 0x60(%rsp)
subq %rdx, %rdi
leaq -0x1(%r8), %r9
leaq 0x1(%rdi), %rax
movq %rax, 0x58(%rsp)
subq %r15, 0x30(%rsp)
movl $0x1, %r12d
movq $0x0, 0x38(%rsp)
movq %r15, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movq %r9, 0x70(%rsp)
movq (%r10), %rbx
movq 0xf8(%rsp), %rax
movq (%rax), %rsi
movq 0xd8(%rsp), %rax
movq (%rax,%r12,8), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl (%rsi,%rcx), %eax
imulq $0xa8, %rax, %r13
movl 0x4(%rbx,%r13), %ecx
movq %rcx, %rax
xorl %edx, %edx
idivq %r11
leaq (%rdx,%r15), %rax
subq %rcx, %rax
cqto
idivq %r11
movq 0x58(%rbx,%r13), %rcx
testq %rax, %rax
je 0x1bc6b7
shlq $0x5, %rax
movslq 0xc(%rcx,%rax), %rbp
cmpq $-0x1, %rbp
je 0x1bc6c1
movslq -0x14(%rcx,%rax), %r14
cmpq $-0x1, %r14
je 0x1bc838
cmpl %r14d, %ebp
jle 0x1bc838
incq %r14
movswq 0x14(%rcx,%rax), %rax
jmp 0x1bc6d6
cmpl $-0x1, 0xc(%rcx)
jne 0x1bc838
movq $-0x2, %rax
movq $-0x3, %rbp
movq $-0x3, %r14
subq %r14, %rbp
cmpq %rbp, %rdi
jne 0x1bc838
cmpq %rax, %r8
jne 0x1bc838
cmpq $-0x3, %r9
ja 0x1bc7bf
movq %rdi, %r15
cmpq $0x0, 0x38(%rsp)
jne 0x1bc753
movq 0xd8(%rsp), %rax
movq (%rax), %rax
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rax, %rcx
movl (%rsi,%rcx), %eax
imulq $0xa8, %rax, %rax
movl 0x10(%rbx,%rax), %ecx
movl 0x1c(%rbx,%rax), %r9d
movq %rcx, (%rsp)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0xe8(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %r8
callq 0x1bc3a6
movq %rax, 0x38(%rsp)
addq %r13, %rbx
incq %rbp
movl 0x10(%rbx), %eax
movl 0x1c(%rbx), %r9d
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0xf0(%rsp), %rbx
movq %rbx, %rdx
movq %r14, %rcx
movq %rbp, %r8
callq 0x1bc3a6
movq 0xe8(%rsp), %rdi
movq %rbx, %rsi
movq 0x30(%rsp), %rdx
callq 0x21a0
testl %eax, %eax
movq 0x18(%rsp), %r10
movq 0xd0(%rsp), %r11
movq %r15, %rdi
movq 0x80(%rsp), %r15
movq 0x78(%rsp), %r8
movq 0x70(%rsp), %r9
jne 0x1bc838
incq %r12
cmpq %r12, 0xe0(%rsp)
jne 0x1bc633
movq (%r10), %rsi
movq 0xf8(%rsp), %rax
movq (%rax), %rdi
xorl %r8d, %r8d
movq 0xd8(%rsp), %rax
movq (%rax,%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 %r11
leaq (%rdx,%r15), %rax
subq %rcx, %rax
cqto
idivq %r11
movq 0x58(%rsi,%r9), %rcx
shlq $0x5, %rax
movw $0xffff, 0x12(%rcx,%rax) # imm = 0xFFFF
incq %r8
cmpq %r8, 0xe0(%rsp)
jne 0x1bc7e1
movq 0x50(%rsp), %rbx
movq 0x68(%rsp), %r15
cmpq %rbx, %r15
movq 0x48(%rsp), %r14
jb 0x1bc540
testq %r14, %r14
je 0x1bc8b8
movq 0xf8(%rsp), %rax
movq (%rax), %rcx
xorl %eax, %eax
xorl %edx, %edx
movq 0x10(%rsp), %r8
movq 0x40(%rsp), %r9
movq 0xc0(%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 0x1bc895
movq %rsi, (%r9,%rax,8)
incq %rax
incq %rdx
cmpq %rdx, %r8
jne 0x1bc876
jmp 0x1bc8a6
movq %r8, %rax
jmp 0x1bc8a6
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
jmp 0x1bc8a6
leaq 0x783dd(%rip), %rdi     # 0x234ca3
leaq 0x8338e(%rip), %rsi     # 0x23fc5b
leaq 0x84f63(%rip), %rcx     # 0x241837
movl $0x1caf, %edx           # imm = 0x1CAF
callq 0x2110