// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_triangular_directly(asg_t*, unsigned int, long long, ma_hit_t_alloc*, R_to_U*)
int test_triangular_directly(asg_t *g, uint32_t v, 
long long min_edge_length, ma_hit_t_alloc* reverse_sources, R_to_U* ruIndex)
{
    
    uint32_t w;
    int todel;
    long long NodeLen_first[3];
    long long NodeLen_second[3];
    
    asg_arc_t *av = asg_arc_a(g, v);
    if(av[0].v == av[1].v)
    {
        return 0;
    }
    /**********************test first node************************/
    NodeLen_first[0] = NodeLen_first[1] = NodeLen_first[2] = -1;
    if(asg_is_single_edge(g, av[0].v, v>>1) <= 2 && asg_is_single_edge(g, av[1].v, v>>1) <= 2)
    {
        NodeLen_first[asg_is_single_edge(g, av[0].v, v>>1)] = 0;
        NodeLen_first[asg_is_single_edge(g, av[1].v, v>>1)] = 1;
    }
    ///one node has one out-edge, another node has two out-edges
    if(NodeLen_first[1] == -1 || NodeLen_first[2] == -1)
    {
        return 0;
    }
    /**********************test first node************************/
    ///if the potiential edge has already been removed 
    if(av[NodeLen_first[2]].del == 1)
    {
        return 0;
    }

    /**********************test second node************************/
    w = av[NodeLen_first[2]].v^1;
    asg_arc_t *aw = asg_arc_a(g, w);
    uint32_t nw = asg_arc_n(g, w);
    if(nw != 2)
    {
        fprintf(stderr, "error\n");
    }
    NodeLen_second[0] = NodeLen_second[1] = NodeLen_second[2] = -1;
    if(asg_is_single_edge(g, aw[0].v, w>>1) <= 2 && asg_is_single_edge(g, aw[1].v, w>>1) <= 2)
    {
        NodeLen_second[asg_is_single_edge(g, aw[0].v, w>>1)] = 0;
        NodeLen_second[asg_is_single_edge(g, aw[1].v, w>>1)] = 1;
    }
    ///one node has one out-edge, another node has two out-edges
    if(NodeLen_second[1] == -1 || NodeLen_second[2] == -1)
    {
        return 0;
    }



    todel = 0;
    // if(check_if_diploid(av[0].v, av[1].v, g, reverse_sources, min_edge_length) && 
    // check_if_diploid(aw[0].v, aw[1].v, g, reverse_sources, min_edge_length))
    if(check_if_diploid(av[0].v, av[1].v, g, reverse_sources, min_edge_length, ruIndex) == 1||
    check_if_diploid(aw[0].v, aw[1].v, g, reverse_sources, min_edge_length, ruIndex) == 1)
    {
        todel = 1;
    }
    
    
    
    if(todel)
    {
        ///fprintf(stderr, "v: %u\n", v>>1);
        av[NodeLen_first[2]].del = 1;
        ///remove the reverse direction
        asg_arc_del(g, av[NodeLen_first[2]].v^1, av[NodeLen_first[2]].ul>>32^1, 1);
    }

    return todel;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %r11
movq %rdx, 0x18(%rsp)
movq 0x8(%rdi), %r13
movq 0x28(%rdi), %rax
movl %esi, %ecx
movl 0x4(%rax,%rcx,8), %ecx
leaq (%rcx,%rcx,2), %r14
movl 0x8(%r13,%r14,8), %ecx
cmpl 0x20(%r13,%r14,8), %ecx
je 0xe8bf6
movq %r8, %r10
movl %esi, %ebp
movq %rdi, %rbx
shrl %ebp
xorq $0x1, %rcx
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
movq $-0x1, 0x50(%rsp)
movq (%rax,%rcx,8), %r15
testl %r15d, %r15d
jle 0xe8c09
movq %r15, %rcx
shrq $0x20, %rcx
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rcx,%rcx,2), %rcx
leaq 0x8(,%rcx,8), %rdx
addq %r13, %rdx
xorl %ecx, %ecx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xe87bc
testl %ecx, %ecx
je 0xe8c0c
cmpl $0x2, %r15d
jg 0xe8bf6
leaq (%r13,%r14,8), %r13
movl 0x20(%r13), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r14
testl %r14d, %r14d
jle 0xe8c41
movq 0x8(%rbx), %rcx
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 $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xe8824
testl %ecx, %ecx
je 0xe8c44
cmpl $0x2, %r14d
jg 0xe8bf6
movl 0x8(%r13), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r14
xorl %edx, %edx
testl %r14d, %r14d
jle 0xe8c7b
movq 0x8(%rbx), %rax
movq %r14, %rdi
shrq $0x20, %rdi
movl %r14d, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0x8, %rdi
movl $0x1, %r8d
movl (%rdi), %r9d
shrl %r9d
cmpl %ebp, %r9d
cmovel %r8d, %edx
addq $0x18, %rdi
decq %rsi
jne 0xe8889
testl %edx, %edx
je 0xe8c7e
movslq %r14d, %rdx
movq $0x0, 0x40(%rsp,%rdx,8)
movl 0x20(%r13), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %r14
xorl %ecx, %ecx
testl %r14d, %r14d
jle 0xe8cbd
movq %r14, %rsi
shrq $0x20, %rsi
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rax
addq $0x8, %rax
movl $0x1, %esi
movl (%rax), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rax
decq %rdx
jne 0xe88eb
testl %ecx, %ecx
je 0xe8cc0
movslq %r14d, %rax
movq $0x1, 0x40(%rsp,%rax,8)
movq 0x50(%rsp), %rax
cmpq $-0x1, 0x48(%rsp)
sete %cl
cmpq $-0x1, %rax
sete %dl
xorl %ebp, %ebp
orb %cl, %dl
jne 0xe8bf8
leaq (%rax,%rax,2), %r15
cmpl $0x0, 0xc(%r13,%r15,8)
js 0xe8bf8
leaq (,%r15,8), %rax
addq %r13, %rax
movq %rax, 0x10(%rsp)
movl 0x8(%rax), %ebp
movq %rbp, %rdx
xorq $0x1, %rdx
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %r12
cmpl $0x2, %edx
jne 0xe8cf7
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movq $-0x1, 0x30(%rsp)
movl 0x8(%r12), %edx
shrl %ebp
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %r14
testl %r14d, %r14d
jle 0xe8d38
movq %r14, %rdx
shrq $0x20, %rdx
movl %r14d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
addq $0x8, %rdx
xorl %eax, %eax
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %eax
addq $0x18, %rdx
decq %rcx
jne 0xe89cc
testl %eax, %eax
je 0xe8d3b
cmpl $0x2, %r14d
jg 0xe8bf6
movl 0x20(%r12), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r14
testl %r14d, %r14d
jle 0xe8d84
movq 0x8(%rbx), %rcx
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 $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rdx
decq %rax
jne 0xe8a30
testl %ecx, %ecx
je 0xe8d87
cmpl $0x2, %r14d
jg 0xe8bf6
movl 0x8(%r12), %eax
movq 0x28(%rbx), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %r14
xorl %edx, %edx
testl %r14d, %r14d
jle 0xe8dd0
movq 0x8(%rbx), %rax
movq %r14, %rdi
shrq $0x20, %rdi
movl %r14d, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0x8, %rdi
movl $0x1, %r8d
movl (%rdi), %r9d
shrl %r9d
cmpl %ebp, %r9d
cmovel %r8d, %edx
addq $0x18, %rdi
decq %rsi
jne 0xe8a96
testl %edx, %edx
je 0xe8dd3
movslq %r14d, %rdx
movq $0x0, 0x20(%rsp,%rdx,8)
movl 0x20(%r12), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %r14
xorl %ecx, %ecx
testl %r14d, %r14d
jle 0xe8e24
movq %r14, %rsi
shrq $0x20, %rsi
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rax
addq $0x8, %rax
movl $0x1, %esi
movl (%rax), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %ecx
addq $0x18, %rax
decq %rdx
jne 0xe8af9
testl %ecx, %ecx
je 0xe8e27
movslq %r14d, %rax
movq $0x1, 0x20(%rsp,%rax,8)
xorl %ebp, %ebp
cmpq $-0x1, 0x28(%rsp)
je 0xe8bf8
cmpq $-0x1, 0x30(%rsp)
je 0xe8bf8
movq %r12, 0x8(%rsp)
movl 0x8(%r13), %edi
movl 0x20(%r13), %esi
movq %rbx, %rdx
movq %r11, %rcx
movq 0x18(%rsp), %r8
movq %r10, %r9
movq %r10, %r14
movq %r15, %r12
movq %r11, %r15
callq 0xaad4d
cmpq $0x1, %rax
je 0xe8b8c
movq %r15, %rcx
movq %r14, %r9
movq 0x8(%rsp), %rax
movl 0x8(%rax), %edi
movl 0x20(%rax), %esi
movq %rbx, %rdx
movq 0x18(%rsp), %r8
callq 0xaad4d
cmpq $0x1, %rax
jne 0xe8bf8
orb $-0x80, 0xf(%r13,%r12,8)
movq 0x10(%rsp), %rax
movl 0x8(%rax), %eax
xorq $0x1, %rax
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %ebp
andq %rdx, %rcx
je 0xe8bf8
movq 0x10(%rsp), %rax
movl 0x4(%rax), %eax
movq 0x8(%rbx), %rsi
shrq $0x20, %rdx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl -0x4(%rdx,%rsi), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0xe8beb
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xe8bdb
jmp 0xe8bf8
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
movq 0x1ac3cd(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1504fd(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, 0x10(%rsp)
movq %r11, %r12
callq 0x2410
movq %r12, %r11
movq 0x10(%rsp), %r10
jmp 0xe87d6
xorl %r14d, %r14d
movq 0x1ac395(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1504c5(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %r15
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq %r15, %r10
jmp 0xe883e
xorl %r14d, %r14d
movq 0x1ac35b(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x15048b(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %r15
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq %r15, %r10
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
jmp 0xe88a7
xorl %r14d, %r14d
movq 0x1ac319(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x150449(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r10, %r15
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq %r15, %r10
jmp 0xe8905
movq 0x1ac2e2(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x148d15(%rip), %rdi    # 0x231a1d
movl $0x6, %esi
movl $0x1, %edx
movq %r10, %r14
movq %r15, (%rsp)
movq %r11, %r15
callq 0x2410
movq %r15, %r11
movq (%rsp), %r15
movq %r14, %r10
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
jmp 0xe897e
xorl %r14d, %r14d
movq 0x1ac29e(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1503ce(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r15, (%rsp)
movq %r10, %r15
movq %r12, 0x8(%rsp)
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq 0x8(%rsp), %r12
movq %r15, %r10
movq (%rsp), %r15
jmp 0xe89e6
xorl %r14d, %r14d
movq 0x1ac252(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x150382(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r15, (%rsp)
movq %r10, %r15
movq %r12, 0x8(%rsp)
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq 0x8(%rsp), %r12
movq %r15, %r10
movq (%rsp), %r15
jmp 0xe8a4a
xorl %r14d, %r14d
movq 0x1ac206(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x150336(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r15, (%rsp)
movq %r10, %r15
movq %r12, 0x8(%rsp)
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq 0x8(%rsp), %r12
movq %r15, %r10
movq (%rsp), %r15
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
jmp 0xe8ab4
xorl %r14d, %r14d
movq 0x1ac1b2(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
leaq 0x1502e2(%rip), %rdi    # 0x23911a
movl $0xa, %esi
movl $0x1, %edx
movq %r15, (%rsp)
movq %r10, %r15
movq %r12, %rbp
movq %r13, %r12
movq %r11, %r13
callq 0x2410
movq %r13, %r11
movq %r12, %r13
movq %rbp, %r12
movq %r15, %r10
movq (%rsp), %r15
jmp 0xe8b13