// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_false_node(asg_t*, ma_hit_t_alloc*, int)
int asg_arc_del_false_node(asg_t *g, ma_hit_t_alloc* sources, int max_ext)
{
    double startTime = Get_T();
    kvec_t(uint64_t) b;
    memset(&b, 0, sizeof(b));
    ma_sub_t max_left, max_right;

	uint32_t v, n_vtx = g->n_seq * 2;
    long long n_cut = 0;
    
    for (v = 0; v < n_vtx; ++v) 
    {
        if(g->seq_vis[v] == 0)
        {
            if(asg_arc_n(g, v)!=1 || asg_arc_n(g, v^1)!=1)
            {
                continue;
            }


            if(asg_is_single_edge(g, asg_arc_a(g, v)[0].v, v>>1) < 2)
            {
                continue;
            }

            if(asg_is_single_edge(g, asg_arc_a(g, v^1)[0].v, (v^1)>>1) < 2)
            {
                continue;
            }

            if(asg_arc_a(g, v)[0].el == 1)
            {
                continue;
            }

            if(if_potential_false_node(&(sources[v>>1]), g->seq[v>>1].len, &max_left, &max_right, 1)==0)
            {
                continue;
            }

            asg_arc_t *av = asg_arc_a(g, v);
            kv_push(uint64_t, b, (uint64_t)((uint64_t)av[0].ol << 32 | (av - g->arc)));
        }
	}

    radix_sort_arch64(b.a, b.a + b.n);

    uint64_t k;
    ///here all edges are inexact matches 
    for (k = 0; k < b.n; k++)
    {
        
        asg_arc_t *a = &g->arc[(uint32_t)b.a[k]];
		///v is self id, w is the id of another end
		uint32_t i, iv, iw, v = (a->ul)>>32, w = a->v^1;
		uint32_t nv = asg_arc_n(g, v), nw = asg_arc_n(g, w), kv, kw;
		asg_arc_t *av, *aw;
        av = asg_arc_a(g, v);
		aw = asg_arc_a(g, w);


        ///calculate the longest edge for v and w
		for (i = 0, kv = 0; i < nv; ++i) {
			if (av[i].del) continue;
			++kv;
		}

		for (i = 0, kw = 0; i < nw; ++i) {
			if (aw[i].del) continue;
			++kw;
		}

		if (kv < 1 || kw < 2) continue;

        ///to see which one is the current edge (from v and w)
		for (iv = 0; iv < nv; ++iv)
			if (av[iv].v == (w^1)) break;
		for (iw = 0; iw < nw; ++iw)
			if (aw[iw].v == (v^1)) break;
        ///if one edge has been deleted, it should be deleted in both direction
        if (av[iv].del && aw[iw].del) continue;

        

        uint32_t el_edges = 0;
        ///there should be at least two available edges in aw
        for (i = 0; i < nw; i++)
        {
            if (aw[i].del) continue;

            if(i != iw && aw[i].el == 1)
            {
                el_edges++;
            }
        }

        if(el_edges > 0 && av[iv].el == 0)
        {
            asg_seq_del(g, v>>1);
            ++n_cut;
        }
    }
    
    free(b.a);
	if (n_cut) 
    {
		asg_cleanup(g);
		asg_symm(g);
	}

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %lld single nodes\n", __func__, n_cut);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }
	return n_cut;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
addl %eax, %eax
je 0xb0f35
movq %r14, 0x20(%rsp)
movl %eax, %edi
xorl %r12d, %r12d
movl $0x1, %r15d
movq $0x0, 0x10(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, (%rsp)
movq 0x30(%rbx), %rax
cmpb $0x0, (%rax,%r12)
jne 0xb0bbb
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rdx
cmpl $0x1, %edx
jne 0xb0bbb
movl %r12d, %r14d
xorq $0x1, %r14
cmpl $0x1, (%rax,%r14,8)
jne 0xb0bbb
movq 0x8(%rbx), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,8), %edx
movl %r12d, %r13d
shrl %r13d
xorq $0x1, %rdx
movq (%rax,%rdx,8), %rbp
testl %ebp, %ebp
jle 0xb0b3b
movq %rbp, %rdx
shrq $0x20, %rdx
movl %ebp, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r13d, %esi
cmovel %r15d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xb0a16
testl %ecx, %ecx
je 0xb0b3d
cmpl $0x2, %ebp
jl 0xb0bbb
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rax
movl 0x4(%rax,%r14,8), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rcx,%rdx,8), %edx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %r14
testl %r14d, %r14d
jle 0xb0bc9
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r13d, %esi
cmovel %r15d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xb0a7e
testl %ecx, %ecx
je 0xb0bcc
cmpl $0x2, %r14d
jl 0xb0bbb
movq 0x8(%rbx), %r14
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %rbp
cmpb $0x1, 0x12(%r14,%rbp,8)
je 0xb0bbb
movq %rdi, 0x8(%rsp)
movl %r13d, %eax
leaq (%rax,%rax,2), %rcx
movq 0x20(%rsp), %rdx
leaq (%rdx,%rcx,8), %rdi
movq 0x20(%rbx), %rcx
movl (%rcx,%rax,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq 0x4c(%rsp), %rdx
leaq 0x40(%rsp), %rcx
movl $0x1, %r8d
callq 0xb0797
testl %eax, %eax
je 0xb0b6c
movq 0x10(%rsp), %r13
cmpq 0x18(%rsp), %r13
jne 0xb0b73
leaq (,%r13,2), %rcx
testq %r13, %r13
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x18(%rsp)
leaq (,%rcx,8), %rsi
movq (%rsp), %rdi
callq 0x2370
movq 0x8(%rbx), %rsi
jmp 0xb0b7a
xorl %ebp, %ebp
movq 0x1e449c(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
movq %rdi, 0x8(%rsp)
leaq 0x1885bd(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x8(%rsp), %rdi
jmp 0xb0a32
movq 0x8(%rsp), %rdi
jmp 0xb0bbb
movq %r14, %rsi
movq (%rsp), %rax
movq 0x8(%rsp), %rdi
leaq (%r14,%rbp,8), %rcx
movl 0xc(%rcx), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
shlq $0x20, %rdx
subq %rsi, %rcx
sarq $0x3, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rcx
orq %rdx, %rcx
movq %rax, (%rsp)
movq %rcx, (%rax,%r13,8)
incq %r13
movq %r13, 0x10(%rsp)
incq %r12
cmpq %rdi, %r12
jne 0xb09a2
jmp 0xb0bf7
xorl %r14d, %r14d
movq 0x1e440d(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
movq %rdi, %rbp
leaq 0x188530(%rip), %rdi    # 0x23911a
callq 0x2410
movq %rbp, %rdi
jmp 0xb0a9a
movq (%rsp), %r15
movq 0x10(%rsp), %r14
leaq (%r15,%r14,8), %rsi
movq %r15, %rdi
callq 0x9dc69
testq %r14, %r14
je 0xb0f41
movq $0x0, 0x28(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq %r15, (%rsp)
movq 0x8(%rbx), %rdi
movq 0x28(%rbx), %r8
movq %r13, 0x8(%rsp)
movl (%r15,%r13,8), %ecx
leaq (%rcx,%rcx,2), %r9
movq (%rdi,%r9,8), %r12
movq %r12, %rdx
shrq $0x20, %rdx
movq (%r8,%rdx,8), %r13
movq %r13, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %r13, %rbp
andq %rax, %rbp
je 0xb0ca1
movl %r13d, %ecx
movq %rsi, %r15
leaq (%rdi,%rsi,8), %r10
addq $0xc, %r10
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r11
xorl %esi, %esi
xorl %r14d, %r14d
movl (%r10,%rsi), %ecx
notl %ecx
shrl $0x1f, %ecx
addl %ecx, %r14d
addq $0x18, %rsi
cmpq %rsi, %r11
jne 0xb0c7c
testl %r14d, %r14d
sete %r10b
movq %r15, %rsi
movq (%rsp), %r15
jmp 0xb0ca4
movb $0x1, %r10b
movl 0x8(%rdi,%r9,8), %r14d
movq %r14, %rcx
xorq $0x1, %rcx
movq (%r8,%rcx,8), %r9
testl %r9d, %r9d
je 0xb0d1b
movq %r12, 0x30(%rsp)
movq %rsi, 0x38(%rsp)
leaq (%rdi,%rsi,8), %rcx
movq %rcx, 0x20(%rsp)
movq %r9, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rcx, 0x18(%rsp)
leaq (%rdi,%rcx,8), %r12
movl %r9d, %r8d
leaq (,%r8,8), %rcx
leaq (%rcx,%rcx,2), %rsi
xorl %r11d, %r11d
xorl %ecx, %ecx
movl 0xc(%r12,%r11), %r15d
notl %r15d
shrl $0x1f, %r15d
addl %r15d, %ecx
addq $0x18, %r11
cmpq %r11, %rsi
jne 0xb0cf4
cmpl $0x2, %ecx
setb %cl
orb %cl, %r10b
je 0xb0d36
movq (%rsp), %r15
movq 0x10(%rsp), %r12
movq 0x8(%rsp), %r13
incq %r13
cmpq %r12, %r13
jne 0xb0c2a
jmp 0xb0f05
testq %rbp, %rbp
je 0xb0d6d
movq 0x38(%rsp), %rcx
leaq (%rdi,%rcx,8), %rcx
addq $0x8, %rcx
xorl %esi, %esi
movq 0x18(%rsp), %r11
cmpl %r14d, (%rcx)
je 0xb0d63
incq %rsi
addq $0x18, %rcx
cmpq %rsi, %rbp
jne 0xb0d4f
movq %r13, %rsi
movl %esi, %r10d
movq 0x8(%rsp), %r13
jmp 0xb0d7a
xorl %r10d, %r10d
movq 0x8(%rsp), %r13
movq 0x18(%rsp), %r11
testl %r9d, %r9d
je 0xb0da7
leaq (%rdi,%r11,8), %rsi
addq $0x8, %rsi
xorl %r14d, %r14d
movl (%rsi), %ecx
xorl %edx, %ecx
cmpl $0x1, %ecx
je 0xb0da2
incq %r14
addq $0x18, %rsi
cmpq %r14, %r8
jne 0xb0d8a
movq %r9, %r14
movl %r14d, %r14d
jmp 0xb0daa
xorl %r14d, %r14d
leaq (%r10,%r10,2), %rcx
movq 0x20(%rsp), %r10
cmpl $0x0, 0xc(%r10,%rcx,8)
js 0xb0dc5
testl %r9d, %r9d
jne 0xb0de1
jmp 0xb0ef7
leaq (%r14,%r14,2), %rsi
cmpl $0x0, 0xc(%r12,%rsi,8)
js 0xb0ef7
movl %r9d, %esi
testq %rsi, %rsi
je 0xb0ef7
leaq (%r10,%rcx,8), %r9
leaq (%rdi,%r11,8), %rdi
addq $0x12, %rdi
xorl %r10d, %r10d
xorl %r11d, %r11d
cmpq %r10, %r14
je 0xb0e09
cmpl $0x0, -0x6(%rdi)
js 0xb0e09
xorl %ecx, %ecx
cmpb $0x1, (%rdi)
sete %cl
addl %ecx, %r11d
incq %r10
addq $0x18, %rdi
cmpq %r10, %r8
jne 0xb0df3
testl %r11d, %r11d
movq (%rsp), %r15
movq 0x10(%rsp), %r12
je 0xb0d25
cmpb $0x0, 0x12(%r9)
jne 0xb0d25
movq 0x20(%rbx), %rcx
movq 0x30(%rsp), %rsi
shrq $0x21, %rsi
orl $0x80000000, (%rcx,%rsi,8) # imm = 0x80000000
andl $-0x2, %edx
movb $0x1, %sil
xorl %edi, %edi
orq %rdx, %rdi
movq 0x28(%rbx), %rcx
movq (%rcx,%rdi,8), %rcx
movq %rcx, %r8
andq %rax, %r8
je 0xb0ed9
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r9
shlq $0x3, %r9
addq 0x8(%rbx), %r9
xorl %r10d, %r10d
leaq (%r10,%r10,2), %rcx
orb $-0x80, 0xf(%r9,%rcx,8)
movl 0x8(%r9,%rcx,8), %ecx
xorq $0x1, %rcx
movq 0x28(%rbx), %r11
movq (%r11,%rcx,8), %rcx
movq %rcx, %r11
andq %rax, %r11
je 0xb0ed1
movq 0x8(%rbx), %r14
shrq $0x20, %rcx
shlq $0x3, %r11
leaq (%r11,%r11,2), %r11
leaq (%rcx,%rcx,2), %rcx
leaq (%r14,%rcx,8), %rcx
addq $0xc, %rcx
xorl %r14d, %r14d
movl -0x4(%rcx,%r14), %ebp
xorl %edi, %ebp
cmpl $0x1, %ebp
jne 0xb0ec8
orb $-0x80, 0x3(%rcx,%r14)
addq $0x18, %r14
cmpq %r14, %r11
jne 0xb0eb6
incq %r10
cmpq %r8, %r10
jne 0xb0e74
movl $0x1, %edi
testb $0x1, %sil
movl $0x0, %esi
jne 0xb0e4e
incq 0x28(%rsp)
jmp 0xb0d25
movq (%rsp), %r15
movq 0x10(%rsp), %r12
jmp 0xb0d25
movq %r15, %rdi
callq 0x2220
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0xb0f49
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
jmp 0xb0f4c
xorl %r15d, %r15d
xorl %edi, %edi
xorl %esi, %esi
callq 0x9dc69
movq %r15, %rdi
callq 0x2220
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq