// File: /workspace/github_cpp_makefile_star2_O3/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
je 0x2dae1
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)
movq 0xf0(%rbp), %r14
testq %r14, %r14
je 0x2dacd
cmpl $0x0, 0x4(%rsp)
sete %r13b
andb 0x3(%rsp), %r13b
movl $0x2, %r12d
movq 0x60(%r14), %rsi
testq %rsi, %rsi
je 0x2da78
movq 0x60(%r15), %rdi
testq %rdi, %rdi
je 0x2daa9
testl %r12d, %r12d
sete %al
andb %r13b, %al
cmpb $0x1, %al
jne 0x2da6d
movl $0x3f, %edx
movq %rbx, %rdi
leaq 0x10d05(%rip), %rsi     # 0x3e73a
callq 0x74e0
movq 0x60(%r15), %rdi
movq 0x60(%r14), %rsi
callq 0x28e92
movq %rbx, %rdi
movl %eax, %esi
callq 0x7720
movl $0x2, %edx
movq %rax, %rdi
leaq 0x11b8c(%rip), %rsi     # 0x3f5ec
callq 0x74e0
movq 0x60(%r15), %rdi
movq 0x60(%r14), %rsi
callq 0x28e92
testl %eax, %eax
je 0x2dabd
jmp 0x2dae8
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x10ad4(%rip), %rsi     # 0x3e55b
callq 0x74e0
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x7720
movl $0x1d, %edx
movq %rax, %rdi
leaq 0x10cfe(%rip), %rsi     # 0x3e7a5
jmp 0x2dab8
movl $0x1f, %edx
movq %rbx, %rdi
leaq 0x10d0b(%rip), %rsi     # 0x3e7c3
callq 0x74e0
movq 0x48(%r14), %r14
decl %r12d
testq %r14, %r14
jne 0x2da03
incl 0x4(%rsp)
movq 0xf8(%rbp), %rbp
testq %rbp, %rbp
jne 0x2d9df
xorl %ebp, %ebp
jmp 0x2dc71
movq 0x10(%rsp), %rdx
cmpl $0x0, 0x60(%rdx)
jle 0x2dbb7
leaq 0x10c7c(%rip), %rsi     # 0x3e77a
movl $0x6, %edx
movq %rbx, %rdi
callq 0x74e0
movq %rbx, %rdi
movl 0x8(%rsp), %esi
callq 0x7720
movq %rax, %r12
leaq 0x10c60(%rip), %rsi     # 0x3e781
movl $0x6, %edx
movq %rax, %rdi
callq 0x74e0
movq %r12, %rdi
movl 0xc(%rsp), %esi
callq 0x7720
movq %rax, %rbp
leaq 0x10a8e(%rip), %rsi     # 0x3e5d2
movl $0x1, %edx
movq %rax, %rdi
callq 0x74e0
movl $0x90, %r12d
leaq (%r15,%r12), %r13
movq %r13, %rdi
callq 0x71d0
movq %rbp, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x74e0
leaq 0x10c10(%rip), %rsi     # 0x3e788
movl $0x11, %edx
movq %rbp, %rdi
callq 0x74e0
addq %r14, %r12
movq %r12, %rdi
callq 0x71d0
movq %rbp, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x74e0
leaq 0x11727(%rip), %rsi     # 0x3f2cc
movl $0x1, %edx
movq %rbp, %rdi
callq 0x74e0
movq 0x10(%rsp), %rdx
movq 0x20(%rsp), %rsi
addq $0xf0, %rsi
movq 0x18(%rsp), %rcx
leaq 0x48(%rcx), %rax
testq %rcx, %rcx
movq 0x48(%r15), %rcx
cmoveq %rsi, %rax
movq %rcx, (%rax)
movq 0x58(%r14), %rax
movq %rax, 0x48(%r15)
movq %r15, 0x58(%r14)
movq 0x58(%r15), %rax
testq %rax, %rax
je 0x2dc06
movq %rax, %rcx
movq 0x48(%rax), %rax
movq %r15, 0x48(%rcx)
movq %rcx, %r15
testq %rax, %rax
jne 0x2dbef
movq %rcx, 0x58(%r14)
movl $0x1, %ebp
cmpl $0x2, 0x60(%rdx)
jl 0x2dc71
leaq 0x90(%r14), %r15
movq %r15, %rdi
callq 0x71d0
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x74e0
leaq 0x11a40(%rip), %rsi     # 0x3f675
movl $0x5, %edx
movq %rbx, %rdi
callq 0x74e0
movq 0x58(%r14), %rax
xorl %esi, %esi
testq %rax, %rax
je 0x2dc55
incl %esi
movq 0x48(%rax), %rax
jmp 0x2dc48
movq %rbx, %rdi
callq 0x7720
leaq 0x10b36(%rip), %rsi     # 0x3e79a
movl $0xa, %edx
movq %rax, %rdi
callq 0x74e0
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq