// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_triangular_addition_exact(asg_t*, unsigned int*, unsigned int, unsigned int, unsigned int, int, buf_t*)
int test_triangular_addition_exact(asg_t *g, uint32_t* nodes, uint32_t length, 
uint32_t startNode, uint32_t endNode, int max_dist, buf_t* bub)
{
    
    uint32_t i, j, v, w;
    ///int flag0, flag1, node;
    int n_reduced = 0, todel;
    uint32_t Nodes1[2]={0};
    uint32_t Nodes2[2]={0};

    uint32_t Ns_first[2]={0};
    uint32_t Ns_second[2]={0};


    
    for (i = 0; i < length; ++i)
    {
        v = nodes[i];

        if((v>>1) == (startNode>>1) || (v>>1) == (endNode>>1))
        {
            continue;
        }

        uint32_t nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        if(nv != 1)
        {
            continue;
        }
        if(asg_is_single_edge(g, av[0].v, v>>1) != 2)
        {
            continue;
        }


        w = v^1;
        asg_arc_t *aw = asg_arc_a(g, w);
        uint32_t nw = asg_arc_n(g, w);
        if(nw != 1)
        {
            continue;
        }
        if(asg_is_single_edge(g, aw[0].v, w>>1) != 2)
        {
            continue;
        }

        if((av[0].v>>1) == (aw[0].v>>1))
        {
            continue;
        }



        Nodes1[0] = av[0].v^1;
        Nodes2[0] = aw[0].v^1;

        
        for(j = 0; j < 2; j++)
        {
            if((asg_arc_a(g, Nodes1[0])[j].v>>1)!= (v>>1))
            {
                Nodes1[1] = asg_arc_a(g, Nodes1[0])[j].v^1;
            }
        }

        for(j = 0; j < 2; j++)
        {
            if((asg_arc_a(g, Nodes2[0])[j].v>>1)!= (v>>1))
            {
                Nodes2[1] = asg_arc_a(g, Nodes2[0])[j].v^1;
            }
        }
        
        if(asg_arc_n(g, Nodes1[1]) != 1 || asg_arc_n(g, Nodes2[1]) != 1)
        {
            continue;
        }

        if((Nodes1[1]>>1) == (Nodes2[1]>>1))
        {
            continue;
        }



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

        uint32_t convex1, convex2, f1, f2;
        long long l1, l2;
        todel = 0;

        if((Nodes1[0]^1) == (startNode^1) || (Nodes1[0]^1) == endNode)
        {
            continue;
        }
        if((Nodes2[1]^1) == (startNode^1) || (Nodes2[1]^1) == endNode)
        {
            continue;
        }

        f1 = detect_bubble_end_with_bubbles(g, Nodes1[0]^1, Nodes2[1]^1, &convex1, &l1, NULL);


        if((Nodes2[0]^1) == (startNode^1) || (Nodes2[0]^1) == endNode)
        {
            continue;
        }
        if((Nodes1[1]^1) == (startNode^1) || (Nodes1[1]^1) == endNode)
        {
            continue;
        }

        f2 = detect_bubble_end_with_bubbles(g, Nodes2[0]^1, Nodes1[1]^1, &convex2, &l2, NULL);


        if(f1 && f2)
        {
            if(((convex1>>1) == (startNode>>1) || (convex1>>1) == (endNode>>1)) && 
                ((convex2>>1) == (startNode>>1) || (convex2>>1) == (endNode>>1)))
            {
                if(l1 <= min_thres || l2 <= min_thres)
                {
                    continue;
                }

                todel = 1;
            }
        }
        else if(f1)
        {
           if(((convex1>>1) == (startNode>>1) || (convex1>>1) == (endNode>>1)))
            {
                if(l1 <= min_thres)
                {
                    continue;
                }

                todel = 1;
            }
        }
        else if(f2)
        {
            if(((convex2>>1) == (startNode>>1) || (convex2>>1) == (endNode>>1)))
            {
                if(l2 <= min_thres)
                {
                    continue;
                }

                todel = 1;
            }
        }

        if(todel == 0)
        {
            if(!f1)
            {
                Ns_first[0] = Nodes1[0]^1; Ns_first[1] = Nodes2[1]^1;
                f1 = asg_bub_end_finder_with_del_advance(g, Ns_first, 2, max_dist, 
                bub, 0, (uint32_t)-1, &convex1);
                l1 = min_thres + 10;
            }

            if(!f2)
            {
                Ns_second[0] = Nodes2[0]^1; Ns_second[1] = Nodes1[1]^1;
                f2 = asg_bub_end_finder_with_del_advance(g, Ns_second, 2, max_dist, 
                bub, 0, (uint32_t)-1, &convex2);
                l2 = min_thres + 10;
            }

            if(f1 && f2)
            {
                if(((convex1>>1) == (startNode>>1) || (convex1>>1) == (endNode>>1)) && 
                ((convex2>>1) == (startNode>>1) || (convex2>>1) == (endNode>>1)))
                {
                    if(l1 <= min_thres || l2 <= min_thres)
                    {
                        continue;
                    } 

                    todel = 1;
                } 
            }
            else if(f1)
            {
                if(((convex1>>1) == (startNode>>1) || (convex1>>1) == (endNode>>1)))
                {
                    if(l1 <= min_thres)
                    {
                        continue;
                    }

                    todel = 1;
                }   
            }
            else if(f2)
            {
                if(((convex2>>1) == (startNode>>1) || (convex2>>1) == (endNode>>1)))
                {
                    if(l2 <= min_thres)
                    {
                        continue;
                    }

                    todel = 1;
                }   
            }
            
        }

        
        if(todel)
        {
            if(av[0].el == 0 || aw[0].el == 0)
            {
                av[0].del = 1;
                asg_arc_del(g, av[0].v^1, av[0].ul>>32^1, 1);

                aw[0].del = 1;
                asg_arc_del(g, aw[0].v^1, aw[0].ul>>32^1, 1);
                
                n_reduced++;
            }
        }
    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorl %eax, %eax
movq %rax, 0x88(%rsp)
movq $0x0, 0x68(%rsp)
movq %rax, 0x80(%rsp)
testl %edx, %edx
je 0xa61a3
movl %ecx, %r10d
movl %ecx, %r11d
shrl %r11d
movl %r8d, %r15d
shrl %r15d
movl %ecx, %eax
xorl $0x1, %eax
movl %eax, 0x64(%rsp)
movl %edx, %edx
xorl %ebp, %ebp
movl $0x1, %r13d
movq $0x0, 0x68(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x34(%rsp)
movl %r11d, 0x14(%rsp)
movl %r15d, 0xc(%rsp)
movq %rdx, 0x20(%rsp)
movl (%rsi,%rbp,4), %ebx
movl %ebx, %r14d
shrl %r14d
cmpl %r11d, %r14d
sete %al
cmpl %r15d, %r14d
sete %cl
orb %al, %cl
jne 0xa5b8c
movq 0x28(%rdi), %rax
movq (%rax,%rbx,8), %rcx
cmpl $0x1, %ecx
jne 0xa5b8c
movq 0x8(%rdi), %rdx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x78(%rsp)
movl 0x8(%rcx), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %r15d, %r15d
testl %eax, %eax
jle 0xa5af5
movq %rax, %r11
shrq $0x20, %r11
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%r11,%r11,2), %r11
leaq (%rdx,%r11,8), %rdx
addq $0x8, %rdx
movl (%rdx), %r11d
shrl %r11d
cmpl %r14d, %r11d
cmovel %r13d, %r15d
addq $0x18, %rdx
decq %rcx
jne 0xa5acb
testl %r15d, %r15d
sete %cl
cmpl $0x2, %eax
sete %r15b
movl 0x14(%rsp), %r11d
jmp 0xa5af7
movb $0x1, %cl
testb %cl, %cl
movq 0x20(%rsp), %rdx
jne 0xa5d56
testb %r15b, %r15b
je 0xa5b87
xorl $0x1, %ebx
movq 0x28(%rdi), %rax
movq (%rax,%rbx,8), %rcx
cmpl $0x1, %ecx
movl 0xc(%rsp), %r15d
jne 0xa5b8c
movq 0x8(%rdi), %rdx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x48(%rsp)
movl 0x8(%rcx), %ecx
xorq $0x1, %rcx
movq (%rax,%rcx,8), %rax
xorl %ebx, %ebx
testl %eax, %eax
jle 0xa5b9d
movq %rax, %r11
shrq $0x20, %r11
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq (%r11,%r11,2), %r11
leaq (%rdx,%r11,8), %rdx
addq $0x8, %rdx
movl (%rdx), %r11d
shrl %r11d
cmpl %r14d, %r11d
cmovel %r13d, %ebx
addq $0x18, %rdx
decq %rcx
jne 0xa5b5f
testl %ebx, %ebx
sete %cl
cmpl $0x2, %eax
sete %bl
movl 0x14(%rsp), %r11d
jmp 0xa5b9f
movl 0xc(%rsp), %r15d
incq %rbp
cmpq %rdx, %rbp
jne 0xa5a5b
jmp 0xa61a3
movb $0x1, %cl
testb %cl, %cl
movq 0x20(%rsp), %rdx
jne 0xa5dab
testb %bl, %bl
je 0xa5b8c
movq 0x78(%rsp), %rax
movl 0x8(%rax), %ebx
movq 0x48(%rsp), %rax
movl 0x8(%rax), %ecx
movl %ecx, %eax
xorl %ebx, %eax
cmpl $0x2, %eax
jb 0xa5b8c
movq %rcx, 0x40(%rsp)
movq %rbx, 0x70(%rsp)
movq %rbx, %rax
xorq $0x1, %rax
movq 0x28(%rdi), %rcx
movl 0x4(%rcx,%rax,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%rdi), %rax
movl $0x8, %ecx
movl 0x34(%rsp), %ebx
movl (%rax,%rcx), %edx
movl %edx, %r11d
shrl %r11d
xorl $0x1, %edx
cmpl %r14d, %r11d
cmovnel %edx, %ebx
addq $0x18, %rcx
cmpq $0x20, %rcx
je 0xa5bf7
movl %ebx, 0x34(%rsp)
movq 0x40(%rsp), %rbx
movq %rbx, %rax
xorq $0x1, %rax
movq 0x28(%rdi), %rcx
movl 0x4(%rcx,%rax,8), %eax
leaq (%rax,%rax,2), %rax
shlq $0x3, %rax
addq 0x8(%rdi), %rax
movl $0x8, %ecx
movl (%rax,%rcx), %edx
movl %edx, %r11d
shrl %r11d
xorl $0x1, %edx
cmpl %r14d, %r11d
cmovnel %edx, %r12d
addq $0x18, %rcx
cmpq $0x20, %rcx
je 0xa5c3c
movq 0x28(%rdi), %rcx
movl 0x34(%rsp), %eax
movq (%rcx,%rax,8), %rax
cmpl $0x1, %eax
jne 0xa5d9c
movl %r12d, %edx
movq (%rcx,%rdx,8), %rcx
cmpl $0x1, %ecx
movl 0x14(%rsp), %r11d
jne 0xa5da1
movl %r12d, %edx
xorl 0x34(%rsp), %edx
cmpl $0x2, %edx
jb 0xa5da1
movq 0x8(%rdi), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
cmpb $0x0, 0x12(%rdx,%rax,8)
je 0xa5da1
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rax
cmpb $0x0, 0x12(%rdx,%rax,8)
je 0xa5da1
movq 0x70(%rsp), %rcx
cmpl 0x64(%rsp), %ecx
sete %al
cmpl %r8d, %ecx
sete %cl
orb %al, %cl
movq 0x20(%rsp), %rdx
jne 0xa5b8c
movl %r12d, %r14d
xorl $0x1, %r14d
cmpl %r10d, %r12d
sete %al
cmpl %r8d, %r14d
sete %cl
orb %al, %cl
jne 0xa5b8c
movl %r12d, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movl %r14d, %edx
movl %r10d, 0x1c(%rsp)
movl %r9d, 0x18(%rsp)
movq %rdi, %r15
movq 0x70(%rsp), %rsi
leaq 0x3c(%rsp), %rcx
movq %rbx, %r12
movl %r8d, %ebx
leaq 0x58(%rsp), %r8
xorl %r9d, %r9d
callq 0xa3e8c
movl %ebx, %r8d
cmpl 0x64(%rsp), %r12d
sete %dl
cmpl %ebx, %r12d
sete %cl
orb %dl, %cl
je 0xa5df2
movl 0x18(%rsp), %r9d
movl 0x1c(%rsp), %r10d
jmp 0xa5e17
movl %r9d, 0x18(%rsp)
movl %r8d, 0x48(%rsp)
movl %r10d, 0x1c(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x40(%rsp)
callq 0x1002c
movq 0x20(%rsp), %rdx
movl 0x14(%rsp), %r11d
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x1c(%rsp), %r10d
movl 0x48(%rsp), %r8d
movl 0x18(%rsp), %r9d
jmp 0xa5b04
movl 0x14(%rsp), %r11d
movq 0x20(%rsp), %rdx
jmp 0xa5b8c
movl %r9d, 0x18(%rsp)
movl %r8d, %r15d
movl %r10d, 0x1c(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, 0x40(%rsp)
callq 0x10048
movq 0x20(%rsp), %rdx
movl 0x14(%rsp), %r11d
movq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl 0x1c(%rsp), %r10d
movl %r15d, %r8d
movl 0xc(%rsp), %r15d
movl 0x18(%rsp), %r9d
jmp 0xa5bac
movl 0x34(%rsp), %ecx
movl %ecx, %r12d
xorl $0x1, %r12d
movl 0x1c(%rsp), %r10d
cmpl %r10d, %ecx
sete %dl
cmpl %r8d, %r12d
sete %cl
orb %dl, %cl
je 0xa5e38
movl 0x18(%rsp), %r9d
movq 0x28(%rsp), %rsi
movq %r15, %rdi
movl 0x14(%rsp), %r11d
movl 0xc(%rsp), %r15d
movq 0x20(%rsp), %rdx
movl 0x10(%rsp), %r12d
jmp 0xa5b8c
movq %r15, %rdi
movq 0x40(%rsp), %rsi
movl %eax, 0x60(%rsp)
movl %r12d, %edx
leaq 0x38(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0xa3e8c
movl 0x60(%rsp), %ecx
testl %ecx, %ecx
movl %eax, 0x94(%rsp)
je 0xa5ed8
testl %eax, %eax
je 0xa5ed8
movl 0x3c(%rsp), %eax
shrl %eax
movl 0x14(%rsp), %r11d
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
movl 0x18(%rsp), %r9d
movl %ebx, %r8d
movl 0x1c(%rsp), %r10d
movq 0x28(%rsp), %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
jne 0xa5f50
movl 0x38(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
jne 0xa5f50
movq 0x1e5558(%rip), %rax    # 0x28b420
cmpq %rax, 0x58(%rsp)
jg 0xa60a7
jmp 0xa6199
testl %ecx, %ecx
movl 0x14(%rsp), %r11d
je 0xa5f17
movl 0x3c(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
movl 0x18(%rsp), %r9d
movl %ebx, %r8d
movl 0x1c(%rsp), %r10d
movq 0x28(%rsp), %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
jne 0xa5f50
jmp 0xa60d3
testl %eax, %eax
movl 0x18(%rsp), %r9d
movl %ebx, %r8d
movl 0x1c(%rsp), %r10d
movq 0x28(%rsp), %rsi
movq %r15, %rdi
movq 0x20(%rsp), %rdx
je 0xa5f50
movl 0x38(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
je 0xa6105
movb $0x1, %cl
movb $0x1, %al
cmpl $0x0, 0x60(%rsp)
jne 0xa5fd1
movq 0x70(%rsp), %rax
movl %eax, 0x88(%rsp)
movl %r14d, 0x8c(%rsp)
leaq 0x88(%rsp), %rsi
movl $0x2, %edx
movl %r9d, %ecx
movq 0xd0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x3c(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0xa4d09
movq 0x30(%rsp), %rdx
movl 0x24(%rsp), %r11d
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movl 0x2c(%rsp), %r10d
movl %ebx, %r8d
movl 0x28(%rsp), %r9d
addq $0x10, %rsp
movq 0x1e545f(%rip), %rcx    # 0x28b420
addq $0xa, %rcx
movq %rcx, 0x58(%rsp)
movb $0x1, %cl
testl %eax, %eax
setne %al
cmpl $0x0, 0x94(%rsp)
jne 0xa6055
movl %eax, %r14d
movq 0x40(%rsp), %rax
movl %eax, 0x80(%rsp)
movl %r12d, 0x84(%rsp)
leaq 0x80(%rsp), %rsi
movl $0x2, %edx
movl %r9d, %ecx
movq 0xd0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x38(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0xa4d09
movq 0x30(%rsp), %rdx
movl 0x24(%rsp), %r11d
movq %r15, %rdi
movq 0x38(%rsp), %rsi
movl 0x2c(%rsp), %r10d
movl %ebx, %r8d
movl 0x28(%rsp), %r9d
addq $0x10, %rsp
movq 0x1e53dc(%rip), %rcx    # 0x28b420
addq $0xa, %rcx
movq %rcx, 0x50(%rsp)
testl %eax, %eax
movl %r14d, %eax
setne %cl
movl %eax, %r14d
andb %cl, %al
cmpb $0x1, %al
jne 0xa60b3
movl 0x3c(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
movl 0xc(%rsp), %edx
cmpl %edx, %eax
setne %al
testb %al, %cl
jne 0xa60da
movl 0x38(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl %edx, %eax
setne %al
testb %al, %cl
jne 0xa5e24
movq 0x1e5389(%rip), %rax    # 0x28b420
cmpq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rdx
jle 0xa6199
cmpq %rax, 0x50(%rsp)
jg 0xa6117
jmp 0xa6199
testb %r14b, %r14b
je 0xa60e2
movl 0x3c(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
jne 0xa6199
movq 0x58(%rsp), %rax
jmp 0xa610a
movl %edx, %r15d
jmp 0xa5e29
testb %cl, %cl
je 0xa6199
movl 0x38(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl 0xc(%rsp), %eax
setne %al
testb %al, %cl
jne 0xa6199
movq 0x50(%rsp), %rax
cmpq 0x1e530f(%rip), %rax    # 0x28b420
jle 0xa6199
movq 0x78(%rsp), %rax
cmpb $0x0, 0x12(%rax)
je 0xa612d
movq 0x48(%rsp), %rax
cmpb $0x0, 0x12(%rax)
jne 0xa6199
movq 0x78(%rsp), %rax
orb $-0x80, 0xf(%rax)
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movl $0x1, %ecx
callq 0xa5255
movq 0x48(%rsp), %rax
orb $-0x80, 0xf(%rax)
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %r15, %rdi
movl $0x1, %ecx
callq 0xa5255
movq 0x20(%rsp), %rdx
movl 0x14(%rsp), %r11d
movq %r15, %rdi
movq 0x28(%rsp), %rsi
movl 0x1c(%rsp), %r10d
movl %ebx, %r8d
movl 0x18(%rsp), %r9d
movq 0x68(%rsp), %rax
incl %eax
movq %rax, 0x68(%rsp)
movl 0xc(%rsp), %r15d
jmp 0xa5e2e
movq 0x68(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq