// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movl %r9d, 0x44(%rsp)
leaq 0x60(%rsp), %rax
andq $0x0, (%rax)
movl %ecx, %r10d
shrl %r10d
movl %r8d, %r13d
shrl %r13d
movl %ecx, 0x48(%rsp)
xorl $0x1, %ecx
movl %ecx, 0x4c(%rsp)
movl %edx, %edx
xorl %r15d, %r15d
xorl %r9d, %r9d
xorl %ebp, %ebp
movl $0x0, 0x54(%rsp)
movl %r8d, 0x50(%rsp)
movq %rsi, 0x28(%rsp)
movl %r10d, (%rsp)
movq %rdx, 0x20(%rsp)
movl %r13d, 0x14(%rsp)
movq %rdi, 0x8(%rsp)
cmpq %rdx, %r15
je 0x6e564
movl (%rsi,%r15,4), %r14d
movl %r14d, %ebx
shrl %ebx
cmpl %r10d, %ebx
sete %al
cmpl %r13d, %ebx
sete %cl
orb %al, %cl
jne 0x6e0f0
movq 0x28(%rdi), %rax
movq (%rax,%r14,8), %rax
cmpl $0x1, %eax
jne 0x6e0f0
movl %ebp, %r12d
movl %r9d, %r13d
shrq $0x20, %rax
imulq $0x18, %rax, %rax
addq 0x8(%rdi), %rax
movq %rax, 0x58(%rsp)
movl 0x8(%rax), %esi
movl %ebx, %edx
movq %rdi, %rbp
callq 0x6c8a1
cmpl $0x2, %eax
jne 0x6e0bc
xorl $0x1, %r14d
movq 0x28(%rbp), %rax
movq (%rax,%r14,8), %rax
cmpl $0x1, %eax
movq %rbp, %rdi
jne 0x6e0d7
shrq $0x20, %rax
imulq $0x18, %rax, %r14
addq 0x8(%rdi), %r14
movl 0x8(%r14), %esi
movl %ebx, %edx
callq 0x6c8a1
cmpl $0x2, %eax
movl %r12d, %ebp
jne 0x6e0f8
movq 0x58(%rsp), %rax
movl 0x8(%rax), %edx
movl 0x8(%r14), %r12d
movl %r12d, %eax
xorl %edx, %eax
cmpl $0x2, %eax
movl %r13d, %r9d
jae 0x6e115
movq 0x28(%rsp), %rsi
movl (%rsp), %r10d
movq 0x20(%rsp), %rdx
jmp 0x6e109
movq 0x28(%rsp), %rsi
movl (%rsp), %r10d
movq 0x20(%rsp), %rdx
movl %r13d, %r9d
movl 0x14(%rsp), %r13d
movq %rbp, %rdi
jmp 0x6e0ed
movq 0x28(%rsp), %rsi
movl (%rsp), %r10d
movq 0x20(%rsp), %rdx
movl %r13d, %r9d
movl 0x14(%rsp), %r13d
movl %r12d, %ebp
incq %r15
jmp 0x6e000
movq 0x28(%rsp), %rsi
movl (%rsp), %r10d
movq 0x20(%rsp), %rdx
movl %r13d, %r9d
movl 0x14(%rsp), %r13d
movq 0x8(%rsp), %rdi
jmp 0x6e0f0
movq %r14, %r11
movq %rdx, %r14
xorq $0x1, %rdx
movq 0x8(%rsp), %rdi
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
movl 0x4(%rcx,%rdx,8), %edx
imulq $0x18, %rdx, %rdx
addq %rax, %rdx
pushq $0x8
popq %rsi
movl 0x14(%rsp), %r13d
cmpq $0x38, %rsi
je 0x6e160
movl (%rdx,%rsi), %r10d
movl %r10d, %r8d
shrl %r8d
xorl $0x1, %r10d
cmpl %ebx, %r8d
cmovnel %r10d, %r9d
addq $0x18, %rsi
jmp 0x6e13f
movq %r12, %rdx
xorq $0x1, %rdx
movl 0x4(%rcx,%rdx,8), %edx
imulq $0x18, %rdx, %rdx
addq %rax, %rdx
pushq $0x8
popq %rsi
cmpq $0x38, %rsi
je 0x6e196
movl (%rdx,%rsi), %r10d
movl %r10d, %r8d
shrl %r8d
xorl $0x1, %r10d
cmpl %ebx, %r8d
cmovnel %r10d, %ebp
addq $0x18, %rsi
jmp 0x6e175
movl %r9d, %edx
movq (%rcx,%rdx,8), %rdx
cmpl $0x1, %edx
jne 0x6e27c
movl %ebp, %esi
movq (%rcx,%rsi,8), %rcx
cmpl $0x1, %ecx
movl 0x50(%rsp), %r8d
jne 0x6e27c
movl %ebp, %esi
xorl %r9d, %esi
cmpl $0x2, %esi
jb 0x6e27c
shrq $0x20, %rdx
imulq $0x18, %rdx, %rdx
cmpb $0x0, 0x12(%rax,%rdx)
je 0x6e27c
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
cmpb $0x0, 0x12(%rax,%rcx)
je 0x6e27c
movq %r14, %rsi
cmpl 0x4c(%rsp), %esi
sete %al
cmpl %r8d, %esi
sete %cl
orb %al, %cl
jne 0x6e27c
movl %ebp, %ebx
xorl $0x1, %ebx
cmpl 0x48(%rsp), %ebp
sete %al
cmpl %r8d, %ebx
sete %cl
orb %al, %cl
jne 0x6e27c
movq %r11, 0x70(%rsp)
movl %r9d, 0x4(%rsp)
movl %ebx, %edx
leaq 0x1c(%rsp), %rcx
leaq 0x38(%rsp), %r8
xorl %r9d, %r9d
callq 0x6ce93
movl 0x50(%rsp), %r8d
cmpl 0x4c(%rsp), %r12d
sete %dl
movq %r12, 0x78(%rsp)
cmpl %r8d, %r12d
sete %cl
orb %dl, %cl
je 0x6e259
movl 0x4(%rsp), %r9d
jmp 0x6e277
movl 0x4(%rsp), %r9d
movl %r9d, %r12d
xorl $0x1, %r12d
cmpl 0x48(%rsp), %r9d
sete %dl
cmpl %r8d, %r12d
sete %cl
orb %dl, %cl
je 0x6e28f
movq 0x8(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl (%rsp), %r10d
movq 0x20(%rsp), %rdx
jmp 0x6e0f0
movq 0x8(%rsp), %rdi
movl %eax, 0x6c(%rsp)
movq 0x78(%rsp), %rsi
movl %r12d, %edx
leaq 0x18(%rsp), %rcx
leaq 0x30(%rsp), %r8
xorl %r9d, %r9d
callq 0x6ce93
movl 0x6c(%rsp), %ecx
movl %eax, %edx
testl %ecx, %ecx
je 0x6e300
testl %edx, %edx
je 0x6e300
movl 0x1c(%rsp), %eax
shrl %eax
movl (%rsp), %esi
cmpl %esi, %eax
setne %cl
cmpl %r13d, %eax
setne %dl
testb %dl, %cl
jne 0x6e333
movl 0x18(%rsp), %ecx
shrl %ecx
cmpl %esi, %ecx
setne %dl
cmpl %r13d, %ecx
setne %cl
testb %cl, %dl
movl 0x4(%rsp), %r9d
movq 0x8(%rsp), %rdi
jne 0x6e44d
jmp 0x6e47c
testl %ecx, %ecx
je 0x6e342
movl 0x1c(%rsp), %eax
shrl %eax
cmpl (%rsp), %eax
setne %cl
cmpl %r13d, %eax
setne %al
movb $0x1, %bl
testb %al, %cl
movl 0x4(%rsp), %r9d
jne 0x6e3da
movq 0x38(%rsp), %rax
cmpq 0x1e60ef(%rip), %rax    # 0x254420
jmp 0x6e36d
movl 0x4(%rsp), %r9d
movq 0x8(%rsp), %rdi
jmp 0x6e44d
testl %edx, %edx
je 0x6e37d
movl 0x18(%rsp), %eax
shrl %eax
cmpl (%rsp), %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0x6e37d
movq 0x30(%rsp), %rax
cmpq 0x1e60b8(%rip), %rax    # 0x254420
movl 0x4(%rsp), %r9d
movq 0x8(%rsp), %rdi
jle 0x6e27c
jmp 0x6e499
movl %r14d, 0x80(%rsp)
movl %ebx, 0x84(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
movl %edx, %ebx
pushq $0x2
popq %rdx
movl 0x44(%rsp), %ecx
movq 0xc0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x1c(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0x6d6ff
movl %ebx, %edx
addq $0x10, %rsp
movq 0x1e6059(%rip), %rcx    # 0x254420
addq $0xa, %rcx
movq %rcx, 0x38(%rsp)
testl %eax, %eax
setne %bl
movl 0x4(%rsp), %r9d
movb $0x1, %al
testl %edx, %edx
jne 0x6e435
movq 0x78(%rsp), %rax
movl %eax, 0x60(%rsp)
movl %r12d, 0x64(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
pushq $0x2
popq %rdx
movl 0x44(%rsp), %ecx
movq 0xc0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x18(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0x6d6ff
movl 0x14(%rsp), %r9d
addq $0x10, %rsp
movq 0x1e5ff9(%rip), %rcx    # 0x254420
addq $0xa, %rcx
movq %rcx, 0x30(%rsp)
testl %eax, %eax
setne %al
movl %ebx, %ecx
andb %al, %cl
cmpb $0x1, %cl
movq 0x8(%rsp), %rdi
jne 0x6e506
movl 0x1c(%rsp), %eax
shrl %eax
movl (%rsp), %edx
cmpl %edx, %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0x6e27c
movl 0x18(%rsp), %eax
shrl %eax
cmpl %edx, %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0x6e27c
movq 0x1e5f9d(%rip), %rax    # 0x254420
cmpq %rax, 0x38(%rsp)
jle 0x6e27c
cmpq %rax, 0x30(%rsp)
jle 0x6e27c
movq 0x58(%rsp), %rax
cmpb $0x0, 0x12(%rax)
je 0x6e4b3
movq 0x70(%rsp), %rax
cmpb $0x0, 0x12(%rax)
jne 0x6e27c
movq 0x58(%rsp), %rax
orb $-0x80, 0xf(%rax)
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
pushq $0x1
popq %rbx
movl %ebx, %ecx
callq 0x6db50
movq 0x70(%rsp), %rax
orb $-0x80, 0xf(%rax)
movl 0x4(%rax), %edx
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq 0x8(%rsp), %rdi
movl %ebx, %ecx
callq 0x6db50
movq 0x8(%rsp), %rdi
movl 0x4(%rsp), %r9d
incl 0x54(%rsp)
jmp 0x6e27c
testb %bl, %bl
je 0x6e52b
movl 0x1c(%rsp), %eax
shrl %eax
cmpl (%rsp), %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0x6e27c
movq 0x38(%rsp), %rax
jmp 0x6e552
testb %al, %al
je 0x6e27c
movl 0x18(%rsp), %eax
shrl %eax
cmpl (%rsp), %eax
setne %cl
cmpl %r13d, %eax
setne %al
testb %al, %cl
jne 0x6e27c
movq 0x30(%rsp), %rax
cmpq 0x1e5ec7(%rip), %rax    # 0x254420
jle 0x6e27c
jmp 0x6e499
movl 0x54(%rsp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq