// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x14(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jne 0x13f170
movl $0x0, -0x4(%rbp)
jmp 0x13f413
movq $-0x1, -0x40(%rbp)
movq $-0x1, -0x48(%rbp)
movq $-0x1, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
cmpl $0x2, %eax
jg 0x13f1fc
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
cmpl $0x2, %eax
jg 0x13f1fc
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
cltq
movq $0x0, -0x50(%rbp,%rax,8)
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x14(%rbp), %edx
shrl %edx
callq 0xd4770
cltq
movq $0x1, -0x50(%rbp,%rax,8)
cmpq $-0x1, -0x48(%rbp)
je 0x13f20a
cmpq $-0x1, -0x40(%rbp)
jne 0x13f216
movl $0x0, -0x4(%rbp)
jmp 0x13f413
movq -0x78(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x1, %eax
jne 0x13f239
movl $0x0, -0x4(%rbp)
jmp 0x13f413
movq -0x78(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x84(%rbp)
cmpl $0x2, -0x84(%rbp)
je 0x13f2aa
movq 0x284d47(%rip), %rax    # 0x3c3fe0
movq (%rax), %rdi
leaq 0x243342(%rip), %rsi    # 0x3825e5
movb $0x0, %al
callq 0x22a0
movq $-0x1, -0x60(%rbp)
movq $-0x1, -0x68(%rbp)
movq $-0x1, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x34(%rbp), %edx
shrl %edx
callq 0xd4770
cmpl $0x2, %eax
jg 0x13f336
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x34(%rbp), %edx
shrl %edx
callq 0xd4770
cmpl $0x2, %eax
jg 0x13f336
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x8(%rax), %esi
movl -0x34(%rbp), %edx
shrl %edx
callq 0xd4770
cltq
movq $0x0, -0x70(%rbp,%rax,8)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rax
movl 0x20(%rax), %esi
movl -0x34(%rbp), %edx
shrl %edx
callq 0xd4770
cltq
movq $0x1, -0x70(%rbp,%rax,8)
cmpq $-0x1, -0x68(%rbp)
je 0x13f344
cmpq $-0x1, -0x60(%rbp)
jne 0x13f350
movl $0x0, -0x4(%rbp)
jmp 0x13f413
movl $0x0, -0x38(%rbp)
movq -0x78(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x78(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x10(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xdbff0
cmpq $0x1, %rax
je 0x13f3a9
movq -0x80(%rbp), %rax
movl 0x8(%rax), %edi
movq -0x80(%rbp), %rax
movl 0x20(%rax), %esi
movq -0x10(%rbp), %rdx
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x30(%rbp), %r9
callq 0xdbff0
cmpq $0x1, %rax
jne 0x13f3b0
movl $0x1, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x13f40d
movq -0x78(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x78(%rbp), %rax
imulq $0x18, -0x40(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xd6530
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nop