// File: /workspace/github_cpp_makefile_star2_O1/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, %r11
movq 0x8(%rdi), %r15
movq 0x28(%rdi), %rax
movl %esi, %ecx
movl 0x4(%rax,%rcx,8), %ecx
leaq (%rcx,%rcx,2), %r12
movl 0x8(%r15,%r12,8), %ecx
xorl %ebx, %ebx
cmpl 0x20(%r15,%r12,8), %ecx
je 0xe7529
movq %r8, %r9
movq %rdx, %r10
movl %esi, %ebp
movq %rdi, %r14
shrl %ebp
xorq $0x1, %rcx
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x40(%rsp)
movq $-0x1, 0x50(%rsp)
movq (%rax,%rcx,8), %rax
testl %eax, %eax
jle 0xe7054
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%r15,%rdx,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl $0x1, %edi
movl (%rsi), %r8d
shrl %r8d
cmpl %ebp, %r8d
cmovel %edi, %edx
addq $0x18, %rsi
decq %rcx
jne 0xe7031
testl %edx, %edx
sete %cl
cmpl $0x3, %eax
setl %r13b
jmp 0xe7059
movb $0x1, %r13b
movb $0x1, %cl
testb %cl, %cl
jne 0xe7315
leaq (%r15,%r12,8), %r15
testb %r13b, %r13b
je 0xe71c3
movl 0x20(%r15), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
jle 0xe70cb
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl $0x1, %edi
movl (%rsi), %r8d
shrl %r8d
cmpl %ebp, %r8d
cmovel %edi, %edx
addq $0x18, %rsi
decq %rcx
jne 0xe70a8
testl %edx, %edx
sete %cl
cmpl $0x3, %eax
setl %r12b
jmp 0xe70d0
movb $0x1, %r12b
movb $0x1, %cl
testb %cl, %cl
jne 0xe73b0
testb %r12b, %r12b
je 0xe71c3
movl 0x8(%r15), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %r12d, %r12d
testl %eax, %eax
jle 0xe713f
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %r12d
addq $0x18, %rdx
decq %rcx
jne 0xe711c
testl %r12d, %r12d
sete %cl
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %r12
jmp 0xe7141
movb $0x1, %cl
testb %cl, %cl
jne 0xe7586
movq $0x0, 0x40(%rsp,%r12,8)
movl 0x20(%r15), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %r12d, %r12d
testl %eax, %eax
jle 0xe71b0
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %ebp, %edi
cmovel %esi, %r12d
addq $0x18, %rdx
decq %rcx
jne 0xe718d
testl %r12d, %r12d
sete %cl
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %r12
jmp 0xe71b2
movb $0x1, %cl
testb %cl, %cl
jne 0xe75aa
movq $0x1, 0x40(%rsp,%r12,8)
movq 0x50(%rsp), %rax
cmpq $-0x1, 0x48(%rsp)
sete %cl
cmpq $-0x1, %rax
sete %dl
orb %cl, %dl
jne 0xe7529
leaq (%rax,%rax,2), %rax
cmpl $0x0, 0xc(%r15,%rax,8)
js 0xe7529
movq %rax, 0x58(%rsp)
leaq (%r15,%rax,8), %rax
movq %rax, 0x60(%rsp)
movl 0x8(%rax), %r13d
movq %r13, %rax
xorq $0x1, %rax
movq 0x28(%r14), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
shlq $0x3, %r12
addq 0x8(%r14), %r12
cmpl $0x2, %eax
jne 0xe753a
pcmpeqd %xmm0, %xmm0
movdqa %xmm0, 0x20(%rsp)
movq $-0x1, 0x30(%rsp)
movl 0x8(%r12), %eax
shrl %r13d
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
jle 0xe72a1
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl $0x1, %edi
movl (%rsi), %r8d
shrl %r8d
cmpl %r13d, %r8d
cmovel %edi, %edx
addq $0x18, %rsi
decq %rcx
jne 0xe727e
testl %edx, %edx
sete %cl
cmpl $0x3, %eax
setl %bpl
jmp 0xe72a6
movb $0x1, %bpl
movb $0x1, %cl
testb %cl, %cl
jne 0xe755e
testb %bpl, %bpl
je 0xe7457
movl 0x20(%r12), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
jle 0xe733d
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movl $0x1, %edi
movl (%rsi), %r8d
shrl %r8d
cmpl %r13d, %r8d
cmovel %edi, %edx
addq $0x18, %rsi
decq %rcx
jne 0xe72f2
testl %edx, %edx
sete %cl
cmpl $0x3, %eax
setl %bpl
jmp 0xe7342
movq %r9, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %r11, 0x8(%rsp)
callq 0x1151c
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0xe7061
movb $0x1, %bpl
movb $0x1, %cl
testb %cl, %cl
jne 0xe75ca
testb %bpl, %bpl
je 0xe7457
movl 0x8(%r12), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %ebp, %ebp
testl %eax, %eax
jle 0xe73d4
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r13d, %edi
cmovel %esi, %ebp
addq $0x18, %rdx
decq %rcx
jne 0xe738e
testl %ebp, %ebp
sete %cl
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %rbp
jmp 0xe73d6
movq %r9, 0x10(%rsp)
movq %r10, %r13
movq %r11, 0x8(%rsp)
callq 0x11538
movq 0x8(%rsp), %r11
movq %r13, %r10
movq 0x10(%rsp), %r9
jmp 0xe70d8
movb $0x1, %cl
testb %cl, %cl
jne 0xe75f2
movq $0x0, 0x20(%rsp,%rbp,8)
movl 0x20(%r12), %eax
movq 0x28(%r14), %rcx
xorq $0x1, %rax
movq (%rcx,%rax,8), %rax
xorl %ebp, %ebp
testl %eax, %eax
jle 0xe7444
movq 0x8(%r14), %rdx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rsi,8), %rdx
addq $0x8, %rdx
movl $0x1, %esi
movl (%rdx), %edi
shrl %edi
cmpl %r13d, %edi
cmovel %esi, %ebp
addq $0x18, %rdx
decq %rcx
jne 0xe7422
testl %ebp, %ebp
sete %cl
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, %rbp
jmp 0xe7446
movb $0x1, %cl
testb %cl, %cl
jne 0xe761a
movq $0x1, 0x20(%rsp,%rbp,8)
cmpq $-0x1, 0x28(%rsp)
je 0xe7529
cmpq $-0x1, 0x30(%rsp)
je 0xe7529
movl 0x8(%r15), %edi
movl 0x20(%r15), %esi
movq %r14, %rdx
movq %r11, %rcx
movq %r10, %r8
movq %r9, %rbx
movq %r10, %r13
movq %r11, %rbp
callq 0xa9c9f
cmpq $0x1, %rax
je 0xe74b5
movl 0x8(%r12), %edi
movl 0x20(%r12), %esi
movq %r14, %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %rbx, %r9
callq 0xa9c9f
cmpq $0x1, %rax
jne 0xe74be
movl $0x1, %ebx
xorl %eax, %eax
jmp 0xe74c2
xorl %ebx, %ebx
movb $0x1, %al
testb %al, %al
jne 0xe7529
movq 0x58(%rsp), %rax
orb $-0x80, 0xf(%r15,%rax,8)
movq 0x60(%rsp), %rsi
movl 0x8(%rsi), %eax
xorq $0x1, %rax
movq 0x28(%r14), %rcx
movq (%rcx,%rax,8), %rdx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xe7529
movl 0x4(%rsi), %eax
movq 0x8(%r14), %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 0xe7520
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xe7510
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, 0x10(%rsp)
movq %r10, %rbp
movq %r11, 0x8(%rsp)
callq 0x1158c
movq 0x8(%rsp), %r11
movq %rbp, %r10
movq 0x10(%rsp), %r9
jmp 0xe722d
movq %r9, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %r11, 0x8(%rsp)
callq 0x115a8
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0xe72ae
movq %r9, 0x10(%rsp)
movq %r10, %r13
movq %r11, 0x8(%rsp)
callq 0x11554
movq 0x8(%rsp), %r11
movq %r13, %r10
movq 0x10(%rsp), %r9
jmp 0xe7149
movq %r9, %r13
movq %r10, %rbp
movq %r11, 0x8(%rsp)
callq 0x11570
movq 0x8(%rsp), %r11
movq %rbp, %r10
movq %r13, %r9
jmp 0xe71ba
movq %r9, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %r11, 0x8(%rsp)
callq 0x115c4
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0xe734a
movq %r9, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %r11, 0x8(%rsp)
callq 0x115e0
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r10
movq 0x10(%rsp), %r9
jmp 0xe73de
movq %r9, 0x10(%rsp)
movq %r10, %r13
movq %r11, 0x8(%rsp)
callq 0x115fc
movq 0x8(%rsp), %r11
movq %r13, %r10
movq 0x10(%rsp), %r9
jmp 0xe744e