// File: /workspace/github_cpp_makefile_star2_O2/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 $0x68, %rsp
movq %rcx, %r13
movl %esi, %ebp
movq 0x8(%rdi), %r15
movq 0x28(%rdi), %rax
movl %esi, %ecx
movl 0x4(%rax,%rcx,8), %eax
imulq $0x18, %rax, %r12
movl 0x8(%r15,%r12), %esi
xorl %ebx, %ebx
cmpl 0x20(%r15,%r12), %esi
je 0xaa85f
movq %rdi, %r14
movq %rdx, 0x58(%rsp)
movq %r8, 0x60(%rsp)
shrl %ebp
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
orq $-0x1, 0x30(%rsp)
movl %ebp, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jg 0xaa85f
addq %r12, %r15
movl 0x20(%r15), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jg 0xaa85f
movl 0x8(%r15), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cltq
andq $0x0, 0x20(%rsp,%rax,8)
movl 0x20(%r15), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cltq
movq $0x1, 0x20(%rsp,%rax,8)
movq 0x30(%rsp), %rax
cmpq $-0x1, 0x28(%rsp)
sete %cl
cmpq $-0x1, %rax
sete %dl
orb %cl, %dl
jne 0xaa85f
imulq $0x18, %rax, %rax
cmpl $0x0, 0xc(%r15,%rax)
js 0xaa85f
movq %rax, 0x50(%rsp)
addq %r15, %rax
movq %rax, 0x48(%rsp)
movl 0x8(%rax), %ebp
movq %rbp, %rax
xorq $0x1, %rax
movq 0x28(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %r12
addq 0x8(%r14), %r12
cmpl $0x2, %eax
jne 0xaa870
orq $-0x1, 0x10(%rsp)
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, (%rsp)
movl 0x8(%r12), %esi
shrl %ebp
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jg 0xaa85f
movl 0x20(%r12), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cmpl $0x2, %eax
jg 0xaa85f
movl 0x8(%r12), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cltq
andq $0x0, (%rsp,%rax,8)
movq %r12, 0x40(%rsp)
movl 0x20(%r12), %esi
movq %r14, %rdi
movl %ebp, %edx
callq 0x6c8a1
cltq
movq $0x1, (%rsp,%rax,8)
cmpq $-0x1, 0x8(%rsp)
je 0xaa85f
cmpq $-0x1, 0x10(%rsp)
je 0xaa85f
movl 0x8(%r15), %edi
movl 0x20(%r15), %esi
movq %r14, %rdx
movq %r13, %rcx
movq 0x58(%rsp), %rbp
movq %rbp, %r8
movq 0x60(%rsp), %r12
movq %r12, %r9
callq 0x70fd8
cmpq $0x1, %rax
je 0xaa836
movq 0x40(%rsp), %rax
movl 0x8(%rax), %edi
movl 0x20(%rax), %esi
movq %r14, %rdx
movq %r13, %rcx
movq %rbp, %r8
movq %r12, %r9
callq 0x70fd8
cmpq $0x1, %rax
jne 0xaa85f
movq 0x50(%rsp), %rax
orb $-0x80, 0xf(%r15,%rax)
movq 0x48(%rsp), %rax
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
pushq $0x1
popq %rbx
movq %r14, %rdi
movl %ebx, %ecx
callq 0x6db50
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a8769(%rip), %rax    # 0x252fe0
movq (%rax), %rcx
leaq 0x1390ec(%rip), %rdi    # 0x1e396d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
callq 0x2410
jmp 0xaa766