// File: chhylp123[P]hifiasm/inter.cpp
// Function: rescue_trans_ul_chains(ul_idx_t const*, overlap_region*, haplotype_evdience*, long, ma_utg_t*, kv_ul_ov_t*, double, long, long, unsigned long*, void*)
int64_t rescue_trans_ul_chains(const ul_idx_t *uref, overlap_region* o, haplotype_evdience *he_a, int64_t he_n, ma_utg_t *u, 
kv_ul_ov_t *chains, double diff_ec_ul, int64_t winLen, int64_t rescue_trans, uint64_t *cis_occ, void *km)
{
	uint64_t ys, ye, i, l;
	int64_t k, ff, ss, t0 = 0;
	utg_ct_t p; 
	if(cis_occ) (*cis_occ) = 0;

	if(o->y_pos_strand == 0) {
		ys = o->y_pos_s; ye = o->y_pos_e + 1;
		for (i = k = l = 0; i < u->n; i++) {
			p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
			l += (uint32_t)u->a[i];
			if(p.e <= ys) continue; 
			if(p.s >= ye) break;
			ff = 1;
			if(he_a && he_n) {
				for (; k < he_n; k++) {
					if(he_a[k].cov >= p.s && he_a[k].cov < p.e) {
						ff = 0;
						break;
					}
					if(he_a[k].cov >= p.e) break;
				}
			}
			// if(ff == debug_utg_ct_t(uref, o, 0, 0, 0, &p, he_a, he_n)) fprintf(stderr, "ERROR\n");
			if(ff) {
				///push ovlp
				t0 += gen_contain_chain(uref, &p, o, chains, diff_ec_ul, winLen, km);
			} else if(rescue_trans) {
				if(gen_contain_chain(uref, &p, o, chains, diff_ec_ul, winLen, km)){
					t0++; chains->a[chains->n-1].el = 0; if(cis_occ) (*cis_occ)++;
					chains->a[chains->n-1].sec = get_het_occ(he_a, he_n, k, uref->ug->u.a[o->y_id].len, &p, o->y_pos_strand);
				}
			}
			// if(!ff)	t0++;	
		}
	} else {
		ys = uref->ug->u.a[o->y_id].len - (o->y_pos_e+1); 
        ye = uref->ug->u.a[o->y_id].len - o->y_pos_s;
        for (i = l = 0, k = he_n - 1; i < u->n; i++) {
            p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
			l += (uint32_t)u->a[i];
            if(p.e <= ys) continue; 
            if(p.s >= ye) break;
			ff = 1;
			if(he_a && he_n) {
				for (; k >= 0; k--) {
					ss = uref->ug->u.a[o->y_id].len - he_a[k].cov - 1;
					if(ss >= p.s && ss < p.e) {
						ff = 0;
						break;
					}
					if(ss >= p.e) break;
				}
			}
            // if(ff == debug_utg_ct_t(uref, o, 0, 0, 0, &p, he_a, he_n)) fprintf(stderr, "ERROR\n");
            if(ff) {
                ///push ovlp
                t0 += gen_contain_chain(uref, &p, o, chains, diff_ec_ul, winLen, km);
            } else if(rescue_trans) {
				if(gen_contain_chain(uref, &p, o, chains, diff_ec_ul, winLen, km)){
					t0++; chains->a[chains->n-1].el = 0; if(cis_occ) (*cis_occ)++;
					chains->a[chains->n-1].sec = get_het_occ(he_a, he_n, k, uref->ug->u.a[o->y_id].len, &p, o->y_pos_strand);
				}
			}
            // if(!ff)  t0++;
        }
	}
	// if(debug_utg_ct_t(uref, o, NULL, 0, u, he_a, he_n)!=t0) fprintf(stderr, "ERROR\n");
	// fprintf(stderr, "t0->%ld\n", t0);
    return t0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq 0x28(%rbp), %rax
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq $0x0, -0x78(%rbp)
cmpq $0x0, 0x20(%rbp)
je 0x28f182
movq 0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
jne 0x28f423
movq -0x10(%rbp), %rax
movl 0x14(%rax), %eax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x28f41e
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x84(%rbp)
movq -0x58(%rbp), %rax
movl %eax, -0x80(%rbp)
movq -0x58(%rbp), %rax
leaq 0x1360cd(%rip), %rcx    # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x50(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x7c(%rbp), %eax
cmpq -0x40(%rbp), %rax
ja 0x28f24a
jmp 0x28f40d
movl -0x80(%rbp), %eax
cmpq -0x48(%rbp), %rax
jb 0x28f258
jmp 0x28f41e
movq $0x1, -0x68(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x28f2d4
cmpq $0x0, -0x20(%rbp)
je 0x28f2d4
jmp 0x28f270
movq -0x60(%rbp), %rax
cmpq -0x20(%rbp), %rax
jge 0x28f2d2
movq -0x18(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x80(%rbp), %eax
jb 0x28f2ac
movq -0x18(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x7c(%rbp), %eax
jae 0x28f2ac
movq $0x0, -0x68(%rbp)
jmp 0x28f2d2
movq -0x18(%rbp), %rax
imulq $0x18, -0x60(%rbp), %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
cmpl -0x7c(%rbp), %eax
jb 0x28f2c2
jmp 0x28f2d2
jmp 0x28f2c4
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x28f270
jmp 0x28f2d4
cmpq $0x0, -0x68(%rbp)
je 0x28f30d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x38(%rbp), %xmm0
movq 0x10(%rbp), %r8
movq 0x28(%rbp), %r9
leaq -0x84(%rbp), %rsi
callq 0x28e230
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x28f40b
cmpq $0x0, 0x18(%rbp)
je 0x28f409
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x38(%rbp), %xmm0
movq 0x10(%rbp), %r8
movq 0x28(%rbp), %r9
leaq -0x84(%rbp), %rsi
callq 0x28e230
cmpq $0x0, %rax
je 0x28f407
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
cmpq $0x0, 0x20(%rbp)
je 0x28f391
movq 0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %r9d
leaq -0x84(%rbp), %r8
callq 0x28e9f0
movl %eax, %edx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
jmp 0x28f409
jmp 0x28f40b
jmp 0x28f40d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x28f1c3
jmp 0x28f720
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
movl 0x18(%rcx), %ecx
addl $0x1, %ecx
subl %ecx, %eax
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x10(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x20(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
cmpq %rcx, %rax
jae 0x28f71e
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x84(%rbp)
movq -0x58(%rbp), %rax
movl %eax, -0x80(%rbp)
movq -0x58(%rbp), %rax
leaq 0x135df2(%rip), %rcx    # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq 0x18(%rdx), %rdx
movq -0x50(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
shrq $0x21, %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x7c(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x7c(%rbp), %eax
cmpq -0x40(%rbp), %rax
ja 0x28f525
jmp 0x28f70d
movl -0x80(%rbp), %eax
cmpq -0x48(%rbp), %rax
jb 0x28f533
jmp 0x28f71e
movq $0x1, -0x68(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x28f5d4
cmpq $0x0, -0x20(%rbp)
je 0x28f5d4
jmp 0x28f553
cmpq $0x0, -0x60(%rbp)
jl 0x28f5d2
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rbp), %rcx
imulq $0x18, -0x60(%rbp), %rdx
addq %rdx, %rcx
subl 0x10(%rcx), %eax
subl $0x1, %eax
movl %eax, %eax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl -0x80(%rbp), %ecx
cmpq %rcx, %rax
jl 0x28f5b4
movq -0x70(%rbp), %rax
movl -0x7c(%rbp), %ecx
cmpq %rcx, %rax
jge 0x28f5b4
movq $0x0, -0x68(%rbp)
jmp 0x28f5d2
movq -0x70(%rbp), %rax
movl -0x7c(%rbp), %ecx
cmpq %rcx, %rax
jl 0x28f5c2
jmp 0x28f5d2
jmp 0x28f5c4
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x28f553
jmp 0x28f5d4
cmpq $0x0, -0x68(%rbp)
je 0x28f60d
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x38(%rbp), %xmm0
movq 0x10(%rbp), %r8
movq 0x28(%rbp), %r9
leaq -0x84(%rbp), %rsi
callq 0x28e230
addq -0x78(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x28f70b
cmpq $0x0, 0x18(%rbp)
je 0x28f709
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movq -0x30(%rbp), %rcx
movsd -0x38(%rbp), %xmm0
movq 0x10(%rbp), %r8
movq 0x28(%rbp), %r9
leaq -0x84(%rbp), %rsi
callq 0x28e230
cmpq $0x0, %rax
je 0x28f707
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0xbfffffff, %ecx       # imm = 0xBFFFFFFF
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
cmpq $0x0, 0x20(%rbp)
je 0x28f691
movq 0x20(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %r9d
leaq -0x84(%rbp), %r8
callq 0x28e9f0
movl %eax, %edx
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq -0x30(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq $0x1, %rcx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andl $0xc0000000, %ecx       # imm = 0xC0000000
orl %edx, %ecx
movl %ecx, 0x18(%rax)
jmp 0x28f709
jmp 0x28f70b
jmp 0x28f70d
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x28f49e
jmp 0x28f720
movq -0x78(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)