// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: asg_arc_push_contain_trans(asg_t*, ma_hit_t_alloc*, long, long, double, long, R_to_U*, unsigned char*)
void asg_arc_push_contain_trans(asg_t *g, ma_hit_t_alloc* ov, int64_t min_ovlp, int64_t max_hang, double max_hang_rate, int64_t fuzz, R_to_U *ri, uint8_t *mark)
{
	uint32_t n_vtx = g->n_seq<<1, cnt = 0, nc, cc, qn, tn, avi, awi;
	uint32_t v, w, i, k, nv, nw; asg_arc_t *av, *aw; int32_t r = 1;
	ma_hit_t_alloc *z; asg_arc_t p, *t;
	uint32_t *dis, *idx; CALLOC(dis, n_vtx); MALLOC(idx, n_vtx);
	for (v = 0; v < n_vtx; ++v) {
		if(g->seq[v>>1].del || (!mark[v])) continue;
        nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
        if (nv == 0) continue; // no hits    
		for (i = 0; i < nv; ++i) {
			if((!(av[i].del)) && (is_contain_r((*ri), (av[i].v>>1)))) break;
		}
		if(i >= nv) continue; 
		z = &(ov[v>>1]);
		for (i = 0; i < z->length; i++) {
        	qn = Get_qn(z->buffer[i]); tn = Get_tn(z->buffer[i]);
			if(z->buffer[i].del) continue;
			r = ma_hit2arc(&(z->buffer[i]), g->seq[qn].len, g->seq[tn].len, max_hang, max_hang_rate, min_ovlp, &p);
			if((r < 0) || ((p.ul>>32) != v)) continue;
			if(g->seq[p.v>>1].del) continue;
			if(mark[p.v^1]) {
				dis[p.v] = asg_arc_len(p) + fuzz; idx[p.v] = i;
			}
		}

		nv = asg_arc_n(g, v); av = asg_arc_a(g, v); avi = g->idx[v]>>32;
		while(nv) {
			for (i = nc = cc = 0; i < nv; ++i) {
				if(av[i].del) continue; w = av[i].v;
				if(!(is_contain_r((*ri), (w>>1)))) continue;///new arcs must be bridged by contained reads
				assert(!(g->seq[w>>1].del));
				nw = asg_arc_n(g, w); aw = asg_arc_a(g, w); awi = g->idx[w]>>32;
				for (k = 0; k < nw; k++) {
					if(aw[k].del) continue;
					if((dis[aw[k].v] == ((uint32_t)-1)) || (dis[aw[k].v] == 0)) continue;
					assert(!(g->seq[aw[k].v>>1].del));
					if((asg_arc_len(av[i]) + asg_arc_len(aw[k])) <= dis[aw[k].v]) {
						dis[aw[k].v] = ((uint32_t)-1); assert(!(z->buffer[idx[aw[k].v]].del));
						qn = Get_qn(z->buffer[idx[aw[k].v]]); tn = Get_tn(z->buffer[idx[aw[k].v]]);
						r = ma_hit2arc(&(z->buffer[idx[aw[k].v]]), g->seq[qn].len, g->seq[tn].len, max_hang, max_hang_rate, min_ovlp, &p);
						assert(r>=0); assert((p.ul>>32)==v); assert(p.v==aw[k].v);
						cnt++; p.ou = 0; t = asg_arc_pushp(g); *t = p; 

						// fprintf(stderr, "[M::%s::]\t%.*s(id::%lu::%c)(is_c::%u)\t%.*s(id::%u::%c)(is_c::%u)\n", __func__, 
						// (int)Get_NAME_LENGTH(R_INF, (g->arc[g->n_arc-1].ul>>33)), 
						// Get_NAME(R_INF, (g->arc[g->n_arc-1].ul>>33)), 
						// g->arc[g->n_arc-1].ul>>33, "+-"[(g->arc[g->n_arc-1].ul>>32)&1], 
						// (is_contain_r((*ri), (g->arc[g->n_arc-1].ul>>33))),
						// (int)Get_NAME_LENGTH(R_INF, (g->arc[g->n_arc-1].v>>1)),
						// Get_NAME(R_INF, (g->arc[g->n_arc-1].v>>1)), 
						// g->arc[g->n_arc-1].v>>1, "+-"[(g->arc[g->n_arc-1].v)&1],
						// (is_contain_r((*ri), (g->arc[g->n_arc-1].v>>1)))
						// );
						// fprintf(stderr, "[M::%s::]\tmiddle::%.*s(id::%u::%c)(is_c::%u)\n", __func__, 
						// (int)Get_NAME_LENGTH(R_INF, (w>>1)), Get_NAME(R_INF, (w>>1)), 
						// w>>1, "+-"[w&1], (is_contain_r((*ri), (w>>1))));



						av = g->arc + avi; aw = g->arc + awi;///renew av and aw since asg_arc_pushp
						if((is_contain_r((*ri), (g->arc[g->n_arc-1].v>>1)))) {
							cc++;
						} else {
							if(g->n_arc!=(nc+1)) {		
								p = g->arc[g->n_arc-1]; 						
								g->arc[g->n_arc-1] = g->arc[nc];
								g->arc[nc] = p;
							}
							nc++;
						}
					}
				}
			}

			if(cc) {///new arcs must be bridged by contained reads
				nv = cc; av = g->arc + g->n_arc - cc; avi = g->n_arc - cc;
			} else {
				nv = 0; av = NULL; avi = ((uint32_t)-1);
			}
		}

		z = &(ov[v>>1]);
		for (i = 0; i < z->length; i++) {
        	qn = Get_qn(z->buffer[i]); tn = Get_tn(z->buffer[i]);
			if(z->buffer[i].del) continue;
			r = ma_hit2arc(&(z->buffer[i]), g->seq[qn].len, g->seq[tn].len, max_hang, max_hang_rate, min_ovlp, &p);
			if((r < 0) || ((p.ul>>32) != v)) continue;
			dis[p.v] = 0;
		}
	}

	free(dis); free(idx);
	if(cnt) {
		free(g->idx);
        g->idx = 0;
        g->is_srt = 0;
        asg_cleanup(g);
		asg_symm(g);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %r9, 0x30(%rsp)
movq %r8, 0xa0(%rsp)
movsd %xmm0, (%rsp)
movq %rcx, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
movq 0xf0(%rsp), %r14
movl 0x14(%rdi), %r15d
addl %r15d, %r15d
movl $0x4, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %r12
leaq (,%r15,4), %rdi
callq 0x2280
testl %r15d, %r15d
je 0x1dcd1f
movq %rax, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsd2ss (%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movl %r15d, %r15d
xorl %r9d, %r9d
movl $0x0, 0x3c(%rsp)
movq 0x30(%rsp), %r11
movq %r12, %rdi
movq %r14, 0x18(%rsp)
movq %r12, 0x8(%rsp)
movq 0x20(%rbx), %r12
movl %r9d, %eax
shrl %eax
cmpl $0x0, (%r12,%rax,8)
js 0x1dc7cd
cmpb $0x0, (%r14,%r9)
je 0x1dc7cd
movq 0x28(%rbx), %rcx
movq (%rcx,%r9,8), %rcx
testl %ecx, %ecx
je 0x1dc7cd
movq %r9, (%rsp)
movq 0x8(%rbx), %rdx
movq %rcx, %r14
shrq $0x20, %r14
leaq (%r14,%r14,2), %rsi
leaq (%rdx,%rsi,8), %rdi
movq %rdi, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movl %ecx, %ecx
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
movq %rcx, %rsi
negq %rsi
movb $0x1, %r8b
movl $0x1, %edi
cmpl $0x0, (%rdx)
js 0x1dc7a4
movl -0x4(%rdx), %r9d
shrl %r9d
cmpq %r9, (%r11)
jbe 0x1dc7a4
movq 0x8(%r11), %r10
cmpl $0x0, (%r10,%r9,4)
jns 0x1dc7de
cmpq %rcx, %rdi
setb %r8b
addq $0x18, %rdx
leaq (%rsi,%rdi), %r9
incq %r9
incq %rdi
cmpq $0x1, %r9
jne 0x1dc788
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
movq (%rsp), %r9
incq %r9
cmpq %r15, %r9
jne 0x1dc724
jmp 0x1dccd3
testb $0x1, %r8b
movq (%rsp), %r9
je 0x1dccaa
movq %r15, 0x90(%rsp)
leaq (%rax,%rax,2), %rax
movq %r13, 0x98(%rsp)
leaq (,%rax,8), %rax
addq %r13, %rax
movq %rax, 0x60(%rsp)
movl 0xc(%rax), %r13d
testq %r13, %r13
movq 0x8(%rsp), %rdi
je 0x1dc8d6
movq 0x60(%rsp), %rax
movq (%rax), %r15
xorl %ebp, %ebp
cmpq $0x0, 0x18(%r15)
js 0x1dc8c6
movl 0x4(%r15), %eax
movl 0xc(%r15), %ecx
movl (%r12,%rax,8), %esi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %esi
movl (%r12,%rcx,8), %edx
andl %eax, %edx
movq %r15, %rdi
movq 0x80(%rsp), %rcx
movss 0x14(%rsp), %xmm0
movq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
callq 0x19c0d3
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %r11
testl %eax, %eax
js 0x1dc8c6
movq 0x40(%rsp), %rax
movq %rax, %rcx
shrq $0x20, %rcx
cmpq %r9, %rcx
jne 0x1dc8c6
movl 0x48(%rsp), %ecx
movl %ecx, %edx
shrl %edx
cmpl $0x0, (%r12,%rdx,8)
js 0x1dc8c6
movq %rcx, %rdx
xorq $0x1, %rdx
movq 0x18(%rsp), %rsi
cmpb $0x0, (%rsi,%rdx)
je 0x1dc8c6
addl 0xa0(%rsp), %eax
movl %eax, (%rdi,%rcx,4)
movq 0x68(%rsp), %rax
movl %ebp, (%rax,%rcx,4)
incq %rbp
addq $0x28, %r15
cmpq %rbp, %r13
jne 0x1dc82c
movq 0x20(%rsp), %rdx
cmpl $0x1, %edx
movl %edx, %r8d
adcl $0x0, %r8d
movl %r14d, %eax
movq %rax, 0xa8(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x88(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x28(%rsp), %r10
movq %r8, 0x70(%rsp)
leaq (,%r13,2), %r14
addq %r13, %r14
cmpl $0x0, 0xc(%r10,%r14,8)
js 0x1dcbbe
leaq (%r10,%r14,8), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
shrl %ecx
cmpq %rcx, (%r11)
jbe 0x1dcbbe
movq 0x8(%r11), %rdx
cmpl $0x0, (%rdx,%rcx,4)
js 0x1dcbbe
movq 0x20(%rbx), %rdx
cmpl $0x0, (%rdx,%rcx,8)
js 0x1dcdc4
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0x1dcbbe
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, 0xb0(%rsp)
leaq (,%rcx,8), %r12
addq 0x8(%rbx), %r12
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
xorl %ebp, %ebp
movq %r14, 0x28(%rsp)
cmpl $0x0, 0xc(%r12,%rbp)
js 0x1dc9b1
movl 0x8(%r12,%rbp), %ecx
movl (%rdi,%rcx,4), %edx
leal 0x1(%rdx), %eax
cmpl $0x2, %eax
jae 0x1dc9bf
addq $0x18, %rbp
cmpq %rbp, %r15
jne 0x1dc999
jmp 0x1dcbbe
movq 0x20(%rbx), %rax
movl %ecx, %esi
shrl %esi
cmpl $0x0, (%rax,%rsi,8)
js 0x1dcd55
movl (%r12,%rbp), %esi
addl (%r10,%r14,8), %esi
cmpl %edx, %esi
ja 0x1dc9b1
movl $0xffffffff, (%rdi,%rcx,4) # imm = 0xFFFFFFFF
movq 0x60(%rsp), %rcx
movq (%rcx), %rcx
movl 0x8(%r12,%rbp), %edx
movq 0x68(%rsp), %rsi
movl (%rsi,%rdx,4), %edx
leaq (%rdx,%rdx,4), %rdx
cmpq $0x0, 0x18(%rcx,%rdx,8)
js 0x1dcd7d
leaq (%rcx,%rdx,8), %rdi
movl 0x4(%rdi), %ecx
movl 0xc(%rdi), %edx
movl (%rax,%rcx,8), %esi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %esi
movl (%rax,%rdx,8), %edx
movl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
andl %ecx, %edx
movq 0x80(%rsp), %rcx
movss 0x14(%rsp), %xmm0
movq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
callq 0x19c0d3
testl %eax, %eax
js 0x1dcd9c
movl 0x44(%rsp), %eax
movq (%rsp), %r9
cmpq %r9, %rax
movq 0x30(%rsp), %r11
jne 0x1dcda5
movl 0x48(%rsp), %eax
cmpl 0x8(%r12,%rbp), %eax
movq 0x8(%rsp), %rdi
jne 0x1dcd74
andw $0xc000, 0x50(%rsp)     # imm = 0xC000
movl 0x4(%rbx), %ecx
andl %r14d, %ecx
movl (%rbx), %eax
cmpl %eax, %ecx
jne 0x1dcabc
leal (%rax,%rax), %ecx
testl %eax, %eax
movl $0x10, %eax
cmovel %eax, %ecx
movl %ecx, (%rbx)
movq 0x8(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %r11
movq %rax, 0x8(%rbx)
incl 0x3c(%rsp)
movq 0x8(%rbx), %rax
movl 0x4(%rbx), %ecx
movq %rcx, %rdx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andq %r8, %rdx
leal 0x1(%rcx), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl $0x80000000, %ecx       # imm = 0x80000000
orl %esi, %ecx
movl %ecx, 0x4(%rbx)
leaq (%rdx,%rdx,2), %rcx
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%rcx,8)
movups 0x40(%rsp), %xmm0
movups %xmm0, (%rax,%rcx,8)
movq 0x8(%rbx), %rax
movq 0xa8(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r10
movq 0xb0(%rsp), %rcx
leaq (%rax,%rcx,8), %r12
movl 0x4(%rbx), %edx
andq %r8, %rdx
leaq (%rdx,%rdx,2), %rsi
movl -0x10(%rax,%rsi,8), %ecx
shrl %ecx
cmpq %rcx, (%r11)
movq 0x28(%rsp), %r14
jbe 0x1dcb51
movq 0x8(%r11), %r8
cmpl $0x0, (%r8,%rcx,4)
js 0x1dcb51
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
jmp 0x1dcbb4
movq 0x88(%rsp), %r8
leal 0x1(%r8), %ecx
cmpl %ecx, %edx
je 0x1dcbaa
leaq (%rax,%rsi,8), %rdx
movq -0x8(%rdx), %rsi
movq %rsi, 0x50(%rsp)
movups -0x18(%rdx), %xmm0
movaps %xmm0, 0x40(%rsp)
movl %r8d, %esi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
movups (%rax,%rsi), %xmm0
movups %xmm0, -0x18(%rdx)
movq 0x10(%rax,%rsi), %rax
movq %rax, -0x8(%rdx)
movq 0x8(%rbx), %rax
movq 0x50(%rsp), %rdx
movq %rdx, 0x10(%rax,%rsi)
movaps 0x40(%rsp), %xmm0
movups %xmm0, (%rax,%rsi)
movl %ecx, %eax
movq %rax, 0x88(%rsp)
movq 0x70(%rsp), %r8
jmp 0x1dc9b1
incq %r13
cmpq %r8, %r13
jne 0x1dc912
movq 0x20(%rsp), %rdx
testl %edx, %edx
je 0x1dcc01
movl 0x4(%rbx), %r14d
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq (%r14,%r14,2), %rax
shlq $0x3, %rax
addq 0x8(%rbx), %rax
movl %edx, %ecx
negq %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x28(%rsp)
subl %edx, %r14d
jmp 0x1dcc12
xorl %edx, %edx
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq $0x0, 0x28(%rsp)
testl %edx, %edx
jne 0x1dc8db
movq 0x60(%rsp), %rax
movl 0xc(%rax), %r14d
testq %r14, %r14
je 0x1dccb9
movq (%rax), %r15
movq 0x98(%rsp), %r13
cmpq $0x0, 0x18(%r15)
js 0x1dcc9f
movl 0x4(%r15), %eax
movl 0xc(%r15), %ecx
movq 0x20(%rbx), %rdx
movl (%rdx,%rax,8), %esi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %esi
movl (%rdx,%rcx,8), %edx
andl %eax, %edx
movq %r15, %rdi
movq 0x80(%rsp), %rcx
movss 0x14(%rsp), %xmm0
movq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
callq 0x19c0d3
movq (%rsp), %r9
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %r11
testl %eax, %eax
js 0x1dcc9f
movl 0x44(%rsp), %eax
cmpq %r9, %rax
jne 0x1dcc9f
movl 0x48(%rsp), %eax
movl $0x0, (%rdi,%rax,4)
addq $0x28, %r15
decq %r14
jne 0x1dcc37
jmp 0x1dccc1
movq 0x18(%rsp), %r14
movq 0x8(%rsp), %rdi
jmp 0x1dc7cd
movq 0x98(%rsp), %r13
movq 0x18(%rsp), %r14
movq 0x90(%rsp), %r15
jmp 0x1dc7cd
callq 0x2220
movq 0x68(%rsp), %rdi
callq 0x2220
cmpl $0x0, 0x3c(%rsp)
je 0x1dcd43
movq 0x28(%rbx), %rdi
callq 0x2220
movq $0x0, 0x28(%rbx)
andb $0x7f, 0x7(%rbx)
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa047e
movq %r12, %rdi
movq %rax, %rbx
callq 0x2220
movq %rbx, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b9a9(%rip), %rdi     # 0x238705
leaq 0x56c28(%rip), %rsi     # 0x23398b
leaq 0x5b928(%rip), %rcx     # 0x238692
movl $0x5512, %edx           # imm = 0x5512
callq 0x2110
leaq 0x5b9d6(%rip), %rdi     # 0x238751
jmp 0x1dcdac
leaq 0x5b99b(%rip), %rdi     # 0x23871f
leaq 0x56c00(%rip), %rsi     # 0x23398b
leaq 0x5b900(%rip), %rcx     # 0x238692
movl $0x5514, %edx           # imm = 0x5514
callq 0x2110
leaq 0x5b99b(%rip), %rdi     # 0x23873e
jmp 0x1dcdac
leaq 0x5b997(%rip), %rdi     # 0x238743
leaq 0x56bd8(%rip), %rsi     # 0x23398b
leaq 0x5b8d8(%rip), %rcx     # 0x238692
movl $0x5517, %edx           # imm = 0x5517
callq 0x2110
leaq 0x5b8b3(%rip), %rdi     # 0x23867e
leaq 0x56bb9(%rip), %rsi     # 0x23398b
leaq 0x5b8b9(%rip), %rcx     # 0x238692
movl $0x550d, %edx           # imm = 0x550D
callq 0x2110