// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_shared_trace(overlap_region_alloc*, unsigned long*, unsigned long, unsigned long, unsigned long, ul_idx_t const*, ug_opt_t const*, long, double, long*, kv_ul_ov_t*)
uint64_t gen_shared_trace(overlap_region_alloc* ol, uint64_t *id_a, uint64_t id_n, uint64_t s, uint64_t e, 
const ul_idx_t *uref, const ug_opt_t *uopt, int64_t bw, double diff_ec_ul, int64_t *is_srt, kv_ul_ov_t *res)///[s, e]
{
	if(!id_n) return 0;
	uint64_t i, m, k, os, oe, ovlp, rm_n = 0; ul_ov_t p, q, *li, *lj, *t; 
	for (i = m = 0; i < id_n; i++) {
		if(ol->list[id_a[i]].x_pos_e < s) continue;
		id_a[m++] = id_a[i];
	}
	id_n = m;
	if(!id_n) return 0;
	//idx_a[] is sorted by ol->list[].x_pos_s
	for (k = 0; k < id_n; k++) {
		convert_ul_ov_t(&p, &(ol->list[id_a[k]]), uref->ug); p.qn = id_a[k];
		if(ol->list[id_a[k]].x_pos_e <= e) rm_n++;
		
		for (i = 0; i < id_n && ol->list[id_a[i]].x_pos_s <= ol->list[id_a[k]].x_pos_e; i++) {
			if(i == k) continue;
			convert_ul_ov_t(&q, &(ol->list[id_a[i]]), uref->ug); q.qn = id_a[i];
			if(p.qe > q.qe) li = &p, lj = &q;
			else if(p.qe == q.qe && p.qs >= q.qs) li = &p, lj = &q;
			else lj = &p, li = &q;
			os = MAX(li->qs, lj->qs), oe = MIN(li->qe, lj->qe);
			ovlp = ((oe > os)? (oe - os):0);
			if(!ovlp) continue;//no overlap
			t = NULL;
			if(res->n > 0 && res->a[res->n-1].qn == p.qn) {
				if(res->a[res->n-1].qs<=os && res->a[res->n-1].qe>=oe) continue;
				t = &(res->a[res->n-1]);
			}
			// fprintf(stderr, "\nk::%lu::utg%.6dl[M::%s::utg%.6dl->utg%.6dl]\n",
			// 		k, (int32_t)ol->list[id_a[k]].y_id+1,  __func__, (int32_t)li->tn+1, (int32_t)lj->tn+1);
			//not contain; graph does not has contained overlaps
			//but at boundary, migh be lj->qs == li->qs
			if(lj->qs <= li->qs+G_CHAIN_INDEL) {
				if(govlp_check(uref, uopt, bw, diff_ec_ul, li, lj)) continue;
			} else if((lj->qe+G_CHAIN_INDEL>=li->qe) && (lj->qs+G_CHAIN_INDEL>=li->qs)) {
				if(govlp_check(uref, uopt, bw, diff_ec_ul, lj, li)) continue;
			}
			if(t && t->qs<=os && t->qe >= os) {
				///assert(t->qs<=os && t->qe<oe); 
				if(oe > t->qe) t->qe = oe;
			} else {
				kv_pushp(ul_ov_t, *res, &t);
				t->qn = p.qn; t->qs = os; t->qe = oe;
			}
		}
		if(res->n > 0 && res->a[res->n-1].qn == p.qn) {
			ol->list[p.qn].align_length++;
			if(ol->list[p.qn].align_length > 1) (*is_srt) = 0;
		}
	}

	if(rm_n) {
		for (i = m = 0; i < id_n; i++) {
			if(ol->list[id_a[i]].x_pos_e <= e) continue;
			id_a[m++] = id_a[i];
		}
		id_n = m;
	}
	return id_n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2ae19c
movq $0x0, -0x8(%rbp)
jmp 0x2ae855
movq $0x0, -0x78(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x2ae214
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rdx
imulq $0xa8, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x28(%rbp), %rax
jae 0x2ae1e3
jmp 0x2ae206
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2ae1b4
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x2ae230
movq $0x0, -0x8(%rbp)
jmp 0x2ae855
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x2ae7ce
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
imulq $0xa8, (%rax,%rcx,8), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq -0x94(%rbp), %rdi
callq 0x720e0
movq -0x18(%rbp), %rax
movq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x58(%rbp), %rdx
imulq $0xa8, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x30(%rbp), %rax
ja 0x2ae2b4
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rcx
xorl %eax, %eax
cmpq -0x20(%rbp), %rcx
movb %al, -0xc9(%rbp)
jae 0x2ae311
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rdx
imulq $0xa8, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
movq -0x18(%rbp), %rdx
movq -0x58(%rbp), %rsi
imulq $0xa8, (%rdx,%rsi,8), %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
setbe %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x2ae320
jmp 0x2ae742
movq -0x48(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x2ae32f
jmp 0x2ae731
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
imulq $0xa8, (%rax,%rcx,8), %rax
addq %rax, %rsi
movq -0x38(%rbp), %rax
movq (%rax), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x720e0
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0xb0(%rbp)
movl -0x8c(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jbe 0x2ae39a
leaq -0x94(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x2ae3f2
movl -0x8c(%rbp), %eax
cmpl -0xa8(%rbp), %eax
jne 0x2ae3d4
movl -0x90(%rbp), %eax
cmpl -0xac(%rbp), %eax
jb 0x2ae3d4
leaq -0x94(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
jmp 0x2ae3f0
leaq -0x94(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x2ae3f2
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xc0(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2ae41a
movq -0xb8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xd0(%rbp)
jmp 0x2ae42a
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %eax
movq -0xc0(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2ae45e
movq -0xb8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xd4(%rbp)
jmp 0x2ae46e
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xd4(%rbp)
movl -0xd4(%rbp), %eax
movl %eax, %eax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jbe 0x2ae495
movq -0x68(%rbp), %rax
subq -0x60(%rbp), %rax
movq %rax, -0xe0(%rbp)
jmp 0x2ae4a0
xorl %eax, %eax
movq %rax, -0xe0(%rbp)
jmp 0x2ae4a0
movq -0xe0(%rbp), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x2ae4b7
jmp 0x2ae731
movq $0x0, -0xc8(%rbp)
movq 0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x2ae561
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x94(%rbp), %eax
jne 0x2ae561
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
cmpq -0x60(%rbp), %rax
ja 0x2ae540
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x68(%rbp), %rax
jb 0x2ae540
jmp 0x2ae731
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %eax
movq -0xb8(%rbp), %rcx
movl 0x4(%rcx), %ecx
addl $0x80, %ecx
cmpl %ecx, %eax
ja 0x2ae5af
movq -0x38(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x18(%rbp), %rdx
movsd -0x40(%rbp), %xmm0
movq -0xb8(%rbp), %rcx
movq -0xc0(%rbp), %r8
callq 0x72aa0
cmpl $0x0, %eax
je 0x2ae5ad
jmp 0x2ae731
jmp 0x2ae617
movq -0xc0(%rbp), %rax
movl 0x8(%rax), %eax
addl $0x80, %eax
movq -0xb8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jb 0x2ae615
movq -0xc0(%rbp), %rax
movl 0x4(%rax), %eax
addl $0x80, %eax
movq -0xb8(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2ae615
movq -0x38(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x18(%rbp), %rdx
movsd -0x40(%rbp), %xmm0
movq -0xc0(%rbp), %rcx
movq -0xb8(%rbp), %r8
callq 0x72aa0
cmpl $0x0, %eax
je 0x2ae613
jmp 0x2ae731
jmp 0x2ae615
jmp 0x2ae617
cmpq $0x0, -0xc8(%rbp)
je 0x2ae669
movq -0xc8(%rbp), %rax
movl 0x4(%rax), %eax
cmpq -0x60(%rbp), %rax
ja 0x2ae669
movq -0xc8(%rbp), %rax
movl 0x8(%rax), %eax
cmpq -0x60(%rbp), %rax
jb 0x2ae669
movq -0x68(%rbp), %rax
movq -0xc8(%rbp), %rcx
movl 0x8(%rcx), %ecx
cmpq %rcx, %rax
jbe 0x2ae664
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x2ae72f
jmp 0x2ae66b
movq 0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2ae6d8
movq 0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2ae69c
movq 0x28(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xe8(%rbp)
jmp 0x2ae6aa
movl $0x2, %eax
movq %rax, -0xe8(%rbp)
jmp 0x2ae6aa
movq -0xe8(%rbp), %rcx
movq 0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x28(%rbp), %rax
movq (%rax), %rdi
movq 0x28(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xc8(%rbp)
movl -0x94(%rbp), %ecx
movq -0xc8(%rbp), %rax
movl %ecx, (%rax)
movq -0x60(%rbp), %rax
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x68(%rbp), %rax
movl %eax, %ecx
movq -0xc8(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x2ae731
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2ae2bc
movq 0x28(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x2ae7bb
movq 0x28(%rbp), %rax
movq (%rax), %rax
movq 0x28(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
cmpl -0x94(%rbp), %eax
jne 0x2ae7bb
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x94(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x94(%rbp), %ecx
imulq $0xa8, %rcx, %rcx
addq %rcx, %rax
cmpl $0x1, 0x28(%rax)
jbe 0x2ae7b9
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
jmp 0x2ae7bb
jmp 0x2ae7bd
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x2ae238
cmpq $0x0, -0x78(%rbp)
je 0x2ae84d
movq $0x0, -0x50(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x2ae845
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq -0x48(%rbp), %rdx
imulq $0xa8, (%rcx,%rdx,8), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
cmpq -0x30(%rbp), %rax
ja 0x2ae814
jmp 0x2ae837
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x18(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x50(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x2ae7e5
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)