// File: /workspace/github_cpp_makefile_star2_O3/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
movq $0x0, 0x70(%rsp)
testl %edx, %edx
je 0xa71b4
movq %rsi, %r10
movl %r9d, 0x5c(%rsp)
movl %ecx, %r11d
shrl %r11d
movl %r8d, 0x84(%rsp)
movl %r8d, %r9d
shrl %r9d
movl %ecx, 0x60(%rsp)
xorl $0x1, %ecx
movl %ecx, 0x64(%rsp)
movl %edx, %r8d
xorl %ebp, %ebp
movl $0x1, %r12d
movl $0x0, 0x44(%rsp)
xorl %ebx, %ebx
xorl %r15d, %r15d
movq %rsi, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
movl %r11d, 0xc(%rsp)
movl %r9d, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movl (%r10,%rbp,4), %r13d
movl %r13d, %r14d
shrl %r14d
cmpl %r11d, %r14d
sete %al
cmpl %r9d, %r14d
sete %cl
orb %al, %cl
jne 0xa6d7c
movq 0x28(%rdi), %rax
movq (%rax,%r13,8), %rdx
cmpl $0x1, %edx
jne 0xa6d7c
movl %ebx, 0x1c(%rsp)
movq 0x8(%rdi), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
movq %rdx, 0x38(%rsp)
movl 0x8(%rdx), %edx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %rbx
testl %ebx, %ebx
jle 0xa6d8d
movq %rbx, %rdx
shrq $0x20, %rdx
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r14d, %esi
cmovel %r12d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa6b26
testl %ecx, %ecx
je 0xa6d8f
cmpl $0x2, %ebx
jne 0xa6d78
xorl $0x1, %r13d
movq 0x28(%rdi), %rax
movq (%rax,%r13,8), %rdx
cmpl $0x1, %edx
jne 0xa6d78
movq 0x8(%rdi), %rcx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r13
movl 0x8(%r13), %edx
xorq $0x1, %rdx
movq (%rax,%rdx,8), %rbx
testl %ebx, %ebx
jle 0xa6dd9
movq %rbx, %rdx
shrq $0x20, %rdx
movl %ebx, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0x8, %rdx
xorl %ecx, %ecx
movl (%rdx), %esi
shrl %esi
cmpl %r14d, %esi
cmovel %r12d, %ecx
addq $0x18, %rdx
decq %rax
jne 0xa6ba0
testl %ecx, %ecx
je 0xa6ddb
cmpl $0x2, %ebx
jne 0xa6d78
movq 0x38(%rsp), %rax
movl 0x8(%rax), %edx
movl 0x8(%r13), %eax
movq %rax, 0x68(%rsp)
xorl %edx, %eax
cmpl $0x2, %eax
movl 0x1c(%rsp), %ebx
jb 0xa6d7c
movq %rdx, 0x88(%rsp)
xorq $0x1, %rdx
movq 0x8(%rdi), %rax
movq 0x28(%rdi), %rcx
movl 0x4(%rcx,%rdx,8), %edx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
movb $0x1, %sil
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r8
movl 0x8(%rdx,%r8,8), %r9d
movl %r9d, %r8d
shrl %r8d
xorl $0x1, %r9d
cmpl %r14d, %r8d
cmovnel %r9d, %r15d
movl $0x1, %r8d
testb $0x1, %sil
movl $0x0, %esi
jne 0xa6c0b
movq 0x68(%rsp), %rdx
xorq $0x1, %rdx
movl 0x4(%rcx,%rdx,8), %edx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdx
movb $0x1, %sil
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r8
movl 0x8(%rdx,%r8,8), %r9d
movl %r9d, %r8d
shrl %r8d
xorl $0x1, %r9d
cmpl %r14d, %r8d
cmovnel %r9d, %ebx
movl $0x1, %r8d
testb $0x1, %sil
movl $0x0, %esi
jne 0xa6c51
movl %r15d, %edx
movq (%rcx,%rdx,8), %rdx
cmpl $0x1, %edx
jne 0xa6dcd
movl %ebx, %esi
movq (%rcx,%rsi,8), %rcx
cmpl $0x1, %ecx
movl 0x8(%rsp), %r9d
movq 0x10(%rsp), %r8
jne 0xa6d7c
movl %ebx, %esi
xorl %r15d, %esi
cmpl $0x2, %esi
jb 0xa6d7c
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
cmpb $0x0, 0x12(%rax,%rdx,8)
je 0xa6d7c
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
cmpb $0x0, 0x12(%rax,%rcx,8)
je 0xa6d7c
movl %ebx, %r14d
movq 0x88(%rsp), %rsi
cmpl 0x64(%rsp), %esi
sete %al
movl 0x84(%rsp), %ebx
cmpl %ebx, %esi
sete %cl
orb %al, %cl
jne 0xa6d73
movl %r14d, %edx
xorl $0x1, %edx
cmpl 0x60(%rsp), %r14d
sete %al
cmpl %ebx, %edx
sete %cl
orb %al, %cl
jne 0xa6d73
movl %edx, 0x1c(%rsp)
leaq 0x2c(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0xa4f1c
movq 0x68(%rsp), %rcx
cmpl 0x64(%rsp), %ecx
sete %dl
cmpl %ebx, %ecx
sete %cl
orb %dl, %cl
jne 0xa6d5a
movl %r15d, %edx
xorl $0x1, %edx
cmpl 0x60(%rsp), %r15d
sete %sil
cmpl %ebx, %edx
sete %cl
orb %sil, %cl
je 0xa6e19
movq 0x30(%rsp), %r10
movq 0x20(%rsp), %rdi
movl 0xc(%rsp), %r11d
movl 0x8(%rsp), %r9d
movq 0x10(%rsp), %r8
movl %r14d, %ebx
jmp 0xa6d7c
movl 0x1c(%rsp), %ebx
incq %rbp
cmpq %r8, %rbp
jne 0xa6aaf
jmp 0xa71bc
xorl %ebx, %ebx
movq 0x1ee24a(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x192370(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x10(%rsp), %r8
movl 0x8(%rsp), %r9d
movl 0xc(%rsp), %r11d
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %r10
jmp 0xa6b42
movl 0x8(%rsp), %r9d
movq 0x10(%rsp), %r8
jmp 0xa6d7c
xorl %ebx, %ebx
movq 0x1ee1fe(%rip), %rax    # 0x294fe0
movq (%rax), %rcx
movl $0xa, %esi
movl $0x1, %edx
leaq 0x192324(%rip), %rdi    # 0x23911a
callq 0x2410
movq 0x10(%rsp), %r8
movl 0x8(%rsp), %r9d
movl 0xc(%rsp), %r11d
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %r10
jmp 0xa6bbc
movq 0x20(%rsp), %rdi
movl %eax, %ebx
movq 0x68(%rsp), %rsi
movl %edx, 0x80(%rsp)
leaq 0x28(%rsp), %rcx
leaq 0x48(%rsp), %r8
xorl %r9d, %r9d
callq 0xa4f1c
movl %ebx, %ecx
testl %ebx, %ebx
je 0xa6e99
testl %eax, %eax
je 0xa6e99
movl 0x2c(%rsp), %eax
shrl %eax
movl 0xc(%rsp), %r11d
cmpl %r11d, %eax
setne %cl
movl 0x8(%rsp), %r9d
cmpl %r9d, %eax
setne %dl
testb %dl, %cl
movl %r14d, %ebx
jne 0xa6eca
movl 0x28(%rsp), %ecx
shrl %ecx
cmpl %r11d, %ecx
setne %dl
cmpl %r9d, %ecx
setne %cl
testb %cl, %dl
movq 0x30(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
jne 0xa7025
jmp 0xa7053
testl %ecx, %ecx
movl 0xc(%rsp), %r11d
movl 0x8(%rsp), %r9d
je 0xa6ede
movl 0x2c(%rsp), %edx
shrl %edx
cmpl %r11d, %edx
setne %cl
cmpl %r9d, %edx
setne %dl
movb $0x1, %bl
testb %dl, %cl
jne 0xa6f8e
movq 0x50(%rsp), %rax
jmp 0xa6f01
movq 0x30(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
jmp 0xa7025
movl %eax, 0x7c(%rsp)
testl %eax, %eax
je 0xa6f1f
movl 0x28(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl %r9d, %eax
setne %al
testb %al, %cl
jne 0xa6f1f
movq 0x48(%rsp), %rax
cmpq 0x1ef518(%rip), %rax    # 0x296420
movq 0x30(%rsp), %r10
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %r8
movl %r14d, %ebx
jmp 0xa706a
movq 0x88(%rsp), %rax
movl %eax, 0x90(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x94(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x90(%rsp), %rsi
movl $0x2, %edx
movl 0x5c(%rsp), %ecx
movq 0xd0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x2c(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0xa5e58
movl 0x18(%rsp), %r9d
movl 0x1c(%rsp), %r11d
addq $0x10, %rsp
movq 0x1ef4a4(%rip), %rcx    # 0x296420
addq $0xa, %rcx
movq %rcx, 0x50(%rsp)
testl %eax, %eax
setne %bl
movl 0x7c(%rsp), %eax
movb $0x1, %dl
testl %eax, %eax
movq 0x30(%rsp), %r10
movq 0x10(%rsp), %r8
jne 0xa700a
movq 0x68(%rsp), %rax
movl %eax, 0x70(%rsp)
movl 0x80(%rsp), %eax
movl %eax, 0x74(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %edx
movl 0x5c(%rsp), %ecx
movq 0xd0(%rsp), %r8
xorl %r9d, %r9d
leaq 0x28(%rsp), %rax
pushq %rax
pushq $-0x1
callq 0xa5e58
movq 0x20(%rsp), %r8
movl 0x18(%rsp), %r9d
movl 0x1c(%rsp), %r11d
movq 0x40(%rsp), %r10
addq $0x10, %rsp
movq 0x1ef424(%rip), %rcx    # 0x296420
addq $0xa, %rcx
movq %rcx, 0x48(%rsp)
testl %eax, %eax
setne %dl
movl %ebx, %ecx
andb %dl, %cl
cmpb $0x1, %cl
movq 0x20(%rsp), %rdi
jne 0xa714f
movl 0x2c(%rsp), %eax
shrl %eax
movl %r14d, %ebx
cmpl %r11d, %eax
setne %cl
cmpl %r9d, %eax
setne %al
testb %al, %cl
jne 0xa6d7c
movl 0x28(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl %r9d, %eax
setne %al
testb %al, %cl
jne 0xa6d7c
movq 0x1ef3c6(%rip), %rax    # 0x296420
cmpq %rax, 0x50(%rsp)
jle 0xa6d7c
cmpq %rax, 0x48(%rsp)
movq 0x38(%rsp), %rcx
jle 0xa6d7c
cmpb $0x0, 0x12(%rcx)
je 0xa7086
cmpb $0x0, 0x12(%r13)
jne 0xa6d7c
orb $-0x80, 0xf(%rcx)
movl 0x8(%rcx), %eax
xorq $0x1, %rax
movq %rcx, %rsi
movq 0x28(%rdi), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0xa70e6
movl 0x4(%rsi), %eax
movq 0x8(%rdi), %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), %r8d
xorl %eax, %r8d
cmpl $0x1, %r8d
jne 0xa70dd
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xa70ca
orb $-0x80, 0xf(%r13)
movl 0x8(%r13), %eax
xorq $0x1, %rax
movq 0x28(%rdi), %rcx
movq (%rcx,%rax,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0xa7146
movl 0x4(%r13), %eax
movq 0x8(%rdi), %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), %r8d
xorl %eax, %r8d
cmpl $0x1, %r8d
jne 0xa713d
orb $-0x80, 0x3(%rdx,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xa712a
incl 0x44(%rsp)
jmp 0xa6dd2
testb %bl, %bl
je 0xa7181
movl 0x2c(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl %r9d, %eax
setne %al
testb %al, %cl
movl %r14d, %ebx
jne 0xa6d7c
movq 0x50(%rsp), %rax
cmpq 0x1ef2a4(%rip), %rax    # 0x296420
jmp 0xa706a
testb %dl, %dl
je 0xa6d73
movl 0x28(%rsp), %eax
shrl %eax
cmpl %r11d, %eax
setne %cl
cmpl %r9d, %eax
setne %al
testb %al, %cl
jne 0xa6d73
movq 0x48(%rsp), %rax
cmpq 0x1ef271(%rip), %rax    # 0x296420
jmp 0xa6f17
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq