// File: /workspace/github_cpp_makefile_star2_O2/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 $0xa8, %rsp
movq %r9, %rbx
movq %r8, 0x90(%rsp)
movsd %xmm0, 0x70(%rsp)
movq %rcx, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x88(%rsp)
movq 0xe0(%rsp), %r15
movq %rdi, 0x10(%rsp)
movl 0x14(%rdi), %r13d
addl %r13d, %r13d
pushq $0x4
popq %rsi
movq %r13, %rdi
callq 0x2120
movq %rax, %r14
leaq (,%r13,4), %rdi
callq 0x2280
movq %r14, %rdi
movq %rbx, %r10
movq %rax, 0x48(%rsp)
cvtsd2ss 0x70(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x1c(%rsp)
movq %rbx, 0x58(%rsp)
movq %r14, 0x38(%rsp)
movq %r15, 0x78(%rsp)
movq %r13, 0x80(%rsp)
cmpq %r13, %rbp
je 0x19b745
movq 0x10(%rsp), %r9
movq 0x20(%r9), %r14
movl %ebp, %eax
shrl %eax
cmpl $0x0, (%r14,%rax,8)
js 0x19b73d
cmpb $0x0, (%r15,%rbp)
je 0x19b73d
movq 0x28(%r9), %rcx
movq (%rcx,%rbp,8), %rcx
testl %ecx, %ecx
je 0x19b73d
movq 0x8(%r9), %rdx
movq %rcx, %rbx
shrq $0x20, %rbx
imulq $0x18, %rbx, %rsi
leaq (%rdx,%rsi), %r12
movq %rcx, 0x8(%rsp)
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x19b73d
cmpl $0x0, (%rdx,%rsi)
js 0x19b31f
movl -0x4(%rdx,%rsi), %r11d
shrl %r11d
cmpq %r11, (%r10)
jbe 0x19b31f
movq 0x8(%r10), %r8
cmpl $0x0, (%r8,%r11,4)
jns 0x19b325
addq $0x18, %rsi
jmp 0x19b2f8
movq %rbp, 0x50(%rsp)
imulq $0x18, %rax, %rax
movq 0x88(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movq %rdx, 0x40(%rsp)
movl 0xc(%rcx,%rax), %r15d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r12, %r11
cmpq %rbp, %r15
je 0x19b40a
movq 0x40(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x18(%rax,%r13)
js 0x19b3fe
leaq (%rax,%r13), %rdi
movl 0x4(%rax,%r13), %ecx
movl 0xc(%rax,%r13), %eax
movl (%r14,%rcx,8), %esi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %esi
movl (%r14,%rax,8), %edx
andl %ecx, %edx
movq 0x68(%rsp), %rcx
movss 0x4(%rsp), %xmm0
movq 0x60(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x15d560
movq %r12, %r11
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
testl %eax, %eax
js 0x19b3fe
movq 0x20(%rsp), %rax
movq %rax, %rcx
shrq $0x20, %rcx
cmpq 0x50(%rsp), %rcx
jne 0x19b3fe
movl 0x28(%rsp), %ecx
movl %ecx, %edx
shrl %edx
cmpl $0x0, (%r14,%rdx,8)
js 0x19b3fe
movq %rcx, %rdx
xorq $0x1, %rdx
movq 0x78(%rsp), %rsi
cmpb $0x0, (%rsi,%rdx)
je 0x19b3fe
addl 0x90(%rsp), %eax
movl %eax, (%rdi,%rcx,4)
movq 0x48(%rsp), %rax
movl %ebp, (%rax,%rcx,4)
incq %rbp
addq $0x28, %r13
jmp 0x19b34c
movq 0x8(%rsp), %rdx
testl %edx, %edx
je 0x19b6a2
movl %ebx, %eax
movl %edx, %esi
xorl %ebp, %ebp
imulq $0x18, %rax, %rax
movq %rax, 0xa0(%rsp)
movq $0x0, 0x8(%rsp)
xorl %r12d, %r12d
movq %rsi, 0x98(%rsp)
cmpq %rsi, %rbp
je 0x19b665
imulq $0x18, %rbp, %r14
cmpl $0x0, 0xc(%r11,%r14)
js 0x19b65d
leaq (%r11,%r14), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
shrl %ecx
cmpq %rcx, (%r10)
jbe 0x19b65d
movq 0x8(%r10), %rdx
cmpl $0x0, (%rdx,%rcx,4)
js 0x19b65d
movq 0x20(%r9), %rdx
cmpl $0x0, (%rdx,%rcx,8)
js 0x19b814
movq 0x28(%r9), %rcx
movq (%rcx,%rax,8), %rax
movl %eax, %ecx
shrq $0x20, %rax
imulq $0x18, %rax, %rdx
movq 0x8(%r9), %r15
movq %rdx, 0x70(%rsp)
addq %rdx, %r15
imulq $0x18, %rcx, %r13
xorl %ebx, %ebx
cmpq %rbx, %r13
je 0x19b655
cmpl $0x0, 0xc(%r15,%rbx)
js 0x19b4cb
movl 0x8(%r15,%rbx), %ecx
movl (%rdi,%rcx,4), %edx
leal 0x1(%rdx), %eax
cmpl $0x2, %eax
jae 0x19b4d1
addq $0x18, %rbx
jmp 0x19b4aa
movq 0x20(%r9), %rax
movl %ecx, %esi
shrl %esi
cmpl $0x0, (%rax,%rsi,8)
js 0x19b7a5
movl (%r15,%rbx), %esi
addl (%r11,%r14), %esi
cmpl %edx, %esi
ja 0x19b4cb
orl $-0x1, (%rdi,%rcx,4)
movq 0x40(%rsp), %rcx
movq (%rcx), %rdi
movl 0x8(%r15,%rbx), %ecx
movq 0x48(%rsp), %rdx
movl (%rdx,%rcx,4), %ecx
imulq $0x28, %rcx, %rcx
cmpq $0x0, 0x18(%rdi,%rcx)
js 0x19b7d6
addq %rcx, %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
andl %ecx, %edx
movq 0x68(%rsp), %rcx
movss 0x4(%rsp), %xmm0
movq 0x60(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x15d560
testl %eax, %eax
js 0x19b7cd
movl 0x24(%rsp), %eax
cmpq 0x50(%rsp), %rax
jne 0x19b7c4
movl 0x28(%rsp), %eax
cmpl 0x8(%r15,%rbx), %eax
jne 0x19b7f5
incl 0x1c(%rsp)
andw $0xc000, 0x30(%rsp)     # imm = 0xC000
movq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0x197052
movq %r15, %r9
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax)
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rax)
movq 0x8(%r15), %rax
movq 0xa0(%rsp), %rcx
leaq (%rax,%rcx), %r11
movq 0x70(%rsp), %rcx
leaq (%rax,%rcx), %r15
movl 0x4(%r9), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
imulq $0x18, %rdx, %rcx
movl -0x10(%rax,%rcx), %esi
shrl %esi
movq 0x58(%rsp), %r10
cmpq %rsi, (%r10)
jbe 0x19b5f3
movq 0x8(%r10), %rdi
cmpl $0x0, (%rdi,%rsi,4)
js 0x19b5f3
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0x38(%rsp), %rdi
jmp 0x19b4cb
leal 0x1(%r12), %esi
cmpl %esi, %edx
movq 0x38(%rsp), %rdi
jne 0x19b609
movl %edx, %r12d
jmp 0x19b4cb
addq %rax, %rcx
movq -0x8(%rcx), %rdx
movq %rdx, 0x30(%rsp)
movups -0x18(%rcx), %xmm0
movaps %xmm0, 0x20(%rsp)
movl %r12d, %edx
imulq $0x18, %rdx, %rdx
movups (%rax,%rdx), %xmm0
movups %xmm0, -0x18(%rcx)
movq 0x10(%rax,%rdx), %rax
movq %rax, -0x8(%rcx)
movq 0x8(%r9), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x10(%rax,%rdx)
movaps 0x20(%rsp), %xmm0
movups %xmm0, (%rax,%rdx)
movl %esi, %r12d
jmp 0x19b4cb
movq 0x98(%rsp), %rsi
incq %rbp
jmp 0x19b43d
pushq $-0x1
popq %rax
movl %eax, %ebx
movl $0x0, %r11d
movq 0x8(%rsp), %rdx
testl %edx, %edx
je 0x19b40f
movl 0x4(%r9), %ebx
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
imulq $0x18, %rbx, %rax
addq 0x8(%r9), %rax
movl %edx, %ecx
negq %rcx
imulq $0x18, %rcx, %r11
addq %rax, %r11
subl %edx, %ebx
jmp 0x19b40f
movq 0x40(%rsp), %rax
movl 0xc(%rax), %eax
imulq $0x28, %rax, %rbx
xorl %r14d, %r14d
movq 0x78(%rsp), %r15
movq 0x80(%rsp), %r13
movq 0x50(%rsp), %rbp
cmpq %r14, %rbx
je 0x19b73d
movq 0x40(%rsp), %rax
movq (%rax), %rax
cmpq $0x0, 0x18(%rax,%r14)
js 0x19b737
leaq (%rax,%r14), %rdi
movl 0x4(%rax,%r14), %ecx
movl 0xc(%rax,%r14), %eax
movq 0x20(%r9), %rdx
movl (%rdx,%rcx,8), %esi
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %esi
movl (%rdx,%rax,8), %edx
andl %ecx, %edx
movq 0x68(%rsp), %rcx
movss 0x4(%rsp), %xmm0
movq 0x60(%rsp), %r8
leaq 0x20(%rsp), %r9
callq 0x15d560
movq 0x38(%rsp), %rdi
movq 0x58(%rsp), %r10
movq 0x10(%rsp), %r9
testl %eax, %eax
js 0x19b737
movl 0x24(%rsp), %eax
cmpq %rbp, %rax
jne 0x19b737
movl 0x28(%rsp), %eax
andl $0x0, (%rdi,%rax,4)
addq $0x28, %r14
jmp 0x19b6c3
incq %rbp
jmp 0x19b295
callq 0x2220
movq 0x48(%rsp), %rdi
callq 0x2220
cmpl $0x0, 0x1c(%rsp)
je 0x19b793
movq 0x10(%rsp), %rbx
movq 0x28(%rbx), %rdi
callq 0x2220
andq $0x0, 0x28(%rbx)
andb $0x7f, 0x7(%rbx)
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x69638
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5b0f1(%rip), %rdi     # 0x1f689d
leaq 0x56370(%rip), %rsi     # 0x1f1b23
leaq 0x5b070(%rip), %rcx     # 0x1f682a
movl $0x5512, %edx           # imm = 0x5512
callq 0x2110
leaq 0x5b110(%rip), %rdi     # 0x1f68db
jmp 0x19b7fc
leaq 0x5b102(%rip), %rdi     # 0x1f68d6
jmp 0x19b7fc
leaq 0x5b0da(%rip), %rdi     # 0x1f68b7
leaq 0x5633f(%rip), %rsi     # 0x1f1b23
leaq 0x5b03f(%rip), %rcx     # 0x1f682a
movl $0x5514, %edx           # imm = 0x5514
callq 0x2110
leaq 0x5b0ed(%rip), %rdi     # 0x1f68e9
leaq 0x56320(%rip), %rsi     # 0x1f1b23
leaq 0x5b020(%rip), %rcx     # 0x1f682a
movl $0x5517, %edx           # imm = 0x5517
callq 0x2110
leaq 0x5affb(%rip), %rdi     # 0x1f6816
leaq 0x56301(%rip), %rsi     # 0x1f1b23
leaq 0x5b001(%rip), %rcx     # 0x1f682a
movl $0x550d, %edx           # imm = 0x550D
callq 0x2110