// File: /workspace/github_cpp_makefile_star2_O1/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: SvgDoc::RemoveIfIncluded(NSVGpath*, NSVGshape*, NSVGpath*, int, int)
int SvgDoc::RemoveIfIncluded(NSVGpath *Inpath, NSVGshape *Inshape, NSVGpath *OldPath, int nShapeIn, int nPathIn)
{
    int nShape = 0;
	for (NSVGshape *shape = SvgData->shapes; shape != NULL; shape = shape->next, nShape++)
	{
        int nPath = 0;
        //  For each path of the shape, check if the path passed as parameter (Inpath) is included in this one
		for (NSVGpath *path = shape->paths; path != NULL; path = path->next, nPath++)
		{
            if ( path->ClosePolygon != NULL && Inpath->ClosePolygon != NULL )
            {
                if ( nShapeIn == 0 && nPathIn == 1 && nShape== 0 && nPath == 2 )
                {
                    OutDebug << "Inpath->ClosePolygon->Poly_in_Poly(path->ClosePolygon) returns " << Inpath->ClosePolygon->Poly_in_Poly(path->ClosePolygon) << " \n";
                }
                if ( Inpath->ClosePolygon->Poly_in_Poly(path->ClosePolygon) )
                {
                    if ( debug_level > 0 )
                    {
                        OutDebug << "Shape_" << nShapeIn << "/Path_" << nPathIn << "(" << Inpath->id << ") is included in " << path->id << "\n";
                    }
                    //  First, remove from primary list
                    if ( OldPath )
                    {
                        OldPath->next = Inpath->next;       //  Not first in list, change next element of previous one
                    }
                    else
                    {
                        Inshape->paths = Inpath->next;      //  First in list for this shape, change head of list
                    }
                    // Now move from primary list to child list, insert head of list
                    Inpath->next = path->child;
                    path->child = Inpath;
                    //  If Inpath has children, move them to child list
                    NSVGpath *pCur = Inpath->child;
                    while (  pCur != NULL )
                    {
                        NSVGpath *pNext = pCur->next;
                        pCur->next = path->child;
                        path->child = pCur;
                        pCur = pNext;
                    }
                    if ( debug_level > 1 )
                    {
                        OutDebug << path->id << " has " << NbChildren(path) << " children\n";
                    }
                    return 1;
                }
            }
            else if (  path->ClosePolygon == NULL )
            {
                OutDebug << " Shape " << nShapeIn << " Shape->ClosePolygon is NULL\n";
            }
            else
            {
                OutDebug << " InShape->ClosePolygon is NULL\n";
            }
        }
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdi), %rax
movq 0x10(%rax), %rbp
testq %rbp, %rbp
setne %r14b
je 0x2e97e
movq %rsi, %r15
movq %rcx, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movl %r9d, 0xc(%rsp)
movl %r9d, %eax
xorl $0x1, %eax
movl %r8d, 0x8(%rsp)
orl %r8d, %eax
sete 0x3(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0x68(%rdi), %rbx
movl $0x0, 0x4(%rsp)
movb %r14b, 0x2(%rsp)
movq 0xf0(%rbp), %r14
testq %r14, %r14
je 0x2e7bf
cmpl $0x0, 0x4(%rsp)
sete %r12b
andb 0x3(%rsp), %r12b
movl $0x2, %r13d
movq 0x60(%r14), %rax
testq %rax, %rax
je 0x2e77b
cmpq $0x0, 0x60(%r15)
je 0x2e765
testl %r13d, %r13d
sete %al
andb %r12b, %al
cmpb $0x1, %al
jne 0x2e752
movl $0x3f, %edx
movq %rbx, %rdi
leaq 0x10f7c(%rip), %rsi     # 0x3f69e
callq 0x74d0
movq 0x60(%r15), %rdi
movq 0x60(%r14), %rsi
callq 0x29704
movq %rbx, %rdi
movl %eax, %esi
callq 0x7710
movl $0x2, %edx
movq %rax, %rdi
leaq 0x11e03(%rip), %rsi     # 0x40550
callq 0x74d0
movq 0x60(%r15), %rdi
movq 0x60(%r14), %rsi
callq 0x29704
testl %eax, %eax
je 0x2e7af
jmp 0x2e7dc
testq %rax, %rax
je 0x2e77b
movl $0x1f, %edx
movq %rbx, %rdi
leaq 0x10fae(%rip), %rsi     # 0x3f727
jmp 0x2e7aa
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x10d35(%rip), %rsi     # 0x3f4bf
callq 0x74d0
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x7710
movl $0x1d, %edx
movq %rax, %rdi
leaq 0x10f5f(%rip), %rsi     # 0x3f709
callq 0x74d0
movq 0x48(%r14), %r14
decl %r13d
testq %r14, %r14
jne 0x2e6f6
incl 0x4(%rsp)
movq 0xf8(%rbp), %rbp
testq %rbp, %rbp
setne %r14b
jne 0x2e6cd
jmp 0x2e97e
movq 0x10(%rsp), %r12
cmpl $0x0, 0x60(%r12)
jle 0x2e8ad
leaq 0x10eea(%rip), %rsi     # 0x3f6de
movl $0x6, %edx
movq %rbx, %rdi
callq 0x74d0
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x7710
movq %rax, %r12
leaq 0x10ece(%rip), %rsi     # 0x3f6e5
movl $0x6, %edx
movq %rax, %rdi
callq 0x74d0
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x7710
movq %rax, %rbp
leaq 0x10cfc(%rip), %rsi     # 0x3f536
movl $0x1, %edx
movq %rax, %rdi
callq 0x74d0
movl $0x90, %r12d
leaq (%r15,%r12), %r13
movq %r13, %rdi
callq 0x71d0
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x74d0
leaq 0x10e7e(%rip), %rsi     # 0x3f6ec
movl $0x11, %edx
movq %rbp, %rdi
callq 0x74d0
addq %r14, %r12
movq %r12, %rdi
callq 0x71d0
movq %rbp, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %r12
movq %rax, %rdx
callq 0x74d0
leaq 0x11990(%rip), %rsi     # 0x40230
movl $0x1, %edx
movq %rbp, %rdi
callq 0x74d0
movq 0x20(%rsp), %rdx
addq $0xf0, %rdx
movq 0x18(%rsp), %rcx
leaq 0x48(%rcx), %rax
testq %rcx, %rcx
movq 0x48(%r15), %rcx
cmoveq %rdx, %rax
movq %rcx, (%rax)
movq 0x58(%r14), %rax
movq %rax, 0x48(%r15)
movq %r15, 0x58(%r14)
movq 0x58(%r15), %rax
testq %rax, %rax
je 0x2e900
movq 0x58(%r14), %rcx
movq %rax, %rdx
movq 0x48(%rax), %rax
movq %rcx, 0x48(%rdx)
movq %rdx, %rcx
testq %rax, %rax
jne 0x2e8e9
movq %rdx, 0x58(%r14)
cmpl $0x2, 0x60(%r12)
jl 0x2e956
leaq 0x90(%r14), %r15
movq %r15, %rdi
callq 0x71d0
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x74d0
leaq 0x11cad(%rip), %rsi     # 0x405d9
movl $0x5, %edx
movq %rbx, %rdi
callq 0x74d0
movq 0x58(%r14), %rax
xorl %esi, %esi
testq %rax, %rax
je 0x2e95d
movb 0x2(%rsp), %r14b
incl %esi
movq 0x48(%rax), %rax
testq %rax, %rax
jne 0x2e949
jmp 0x2e962
movb 0x2(%rsp), %r14b
jmp 0x2e97e
movb 0x2(%rsp), %r14b
movq %rbx, %rdi
callq 0x7710
leaq 0x10d8d(%rip), %rsi     # 0x3f6fe
movl $0xa, %edx
movq %rax, %rdi
callq 0x74d0
movzbl %r14b, %eax
andl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq