// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x34(%rbp)
movq 0x8(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x6acf2
movl $0x0, -0x44(%rbp)
movq -0x40(%rbp), %rax
movq 0xf0(%rax), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6acd3
movq -0x50(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6ac66
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6ac66
cmpl $0x0, -0x2c(%rbp)
jne 0x6aab7
cmpl $0x1, -0x30(%rbp)
jne 0x6aab7
cmpl $0x0, -0x34(%rbp)
jne 0x6aab7
cmpl $0x2, -0x44(%rbp)
jne 0x6aab7
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
leaq 0x19ca7(%rip), %rsi     # 0x84726
callq 0x9530
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x62f30
movq -0x70(%rbp), %rdi
movl %eax, %esi
callq 0x9930
movq %rax, %rdi
leaq 0x1ab3c(%rip), %rsi     # 0x855ee
callq 0x9530
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x62f30
cmpl $0x0, %eax
je 0x6ac64
movq -0x68(%rbp), %rax
cmpl $0x0, 0x60(%rax)
jle 0x6ab6f
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
leaq 0x19c74(%rip), %rsi     # 0x84766
callq 0x9530
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x9930
movq %rax, %rdi
leaq 0x19c61(%rip), %rsi     # 0x8476d
callq 0x9530
movq %rax, %rdi
movl -0x30(%rbp), %esi
callq 0x9930
movq %rax, %rdi
leaq 0x19a98(%rip), %rsi     # 0x845be
callq 0x9530
movq %rax, %rdi
movq -0x18(%rbp), %rsi
addq $0x90, %rsi
callq 0x9530
movq %rax, %rdi
leaq 0x19c2c(%rip), %rsi     # 0x84774
callq 0x9530
movq %rax, %rdi
movq -0x50(%rbp), %rsi
addq $0x90, %rsi
callq 0x9530
movq %rax, %rdi
leaq 0x1a751(%rip), %rsi     # 0x852bb
callq 0x9530
cmpq $0x0, -0x28(%rbp)
je 0x6ab88
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x6ab9b
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0xf0(%rax)
movq -0x50(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x6abfc
movq -0x58(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq 0x58(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x6abc3
movq -0x68(%rbp), %rax
cmpl $0x1, 0x60(%rax)
jle 0x6ac58
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
movq -0x50(%rbp), %rsi
addq $0x90, %rsi
callq 0x9530
movq %rax, %rdi
leaq 0x1aa4f(%rip), %rsi     # 0x85677
callq 0x9530
movq -0x68(%rbp), %rdi
movq %rax, -0x78(%rbp)
movq -0x50(%rbp), %rsi
callq 0x6ad10
movq -0x78(%rbp), %rdi
movl %eax, %esi
callq 0x9930
movq %rax, %rdi
leaq 0x19b33(%rip), %rsi     # 0x84786
callq 0x9530
movl $0x1, -0x4(%rbp)
jmp 0x6acf9
jmp 0x6acb7
movq -0x50(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x6aca1
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
leaq 0x198c7(%rip), %rsi     # 0x84547
callq 0x9530
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x9930
movq %rax, %rdi
leaq 0x19af7(%rip), %rsi     # 0x84791
callq 0x9530
jmp 0x6acb5
movq -0x68(%rbp), %rdi
addq $0x68, %rdi
leaq 0x19aff(%rip), %rsi     # 0x847af
callq 0x9530
jmp 0x6acb7
jmp 0x6acb9
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x6aa2f
jmp 0x6acd5
movq -0x40(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x6aa0e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)