// File: /workspace/github_cpp_makefile_star2_O2/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 $0x38, %rsp
movl %r8d, %r13d
movq %rcx, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
movq %rsi, %r14
movq 0x8(%rdi), %rbx
addq $0x10, %rbx
movl %r9d, 0x10(%rsp)
movl %r9d, %eax
xorl $0x1, %eax
orl %r8d, %eax
sete 0xe(%rsp)
movq %rdi, 0x18(%rsp)
leaq 0x68(%rdi), %r15
xorl %eax, %eax
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x288dc
movq %rbx, 0x20(%rsp)
leaq 0xf0(%rbx), %r12
movl %eax, 0x14(%rsp)
testl %eax, %eax
sete %bl
andb 0xe(%rsp), %bl
pushq $0x2
popq %rbp
movb %bl, 0xf(%rsp)
movq (%r12), %r12
testq %r12, %r12
je 0x28792
movq 0x60(%r12), %rsi
testq %rsi, %rsi
je 0x28752
movq 0x60(%r14), %rdi
testq %rdi, %rdi
je 0x28778
testl %ebp, %ebp
sete %al
andb %bl, %al
cmpb $0x1, %al
jne 0x28747
movq %r15, %rdi
leaq 0xdffb(%rip), %rsi      # 0x366fa
callq 0x8420
movq %r15, %rbx
movl %r13d, %r15d
movq %rax, %r13
movq 0x60(%r14), %rdi
movq 0x60(%r12), %rsi
callq 0x23fc2
movq %r13, %rdi
movl %r15d, %r13d
movq %rbx, %r15
movb 0xf(%rsp), %bl
movl %eax, %esi
callq 0x8740
movq %rax, %rdi
leaq 0xee73(%rip), %rsi      # 0x375ac
callq 0x8420
movq 0x60(%r14), %rdi
movq 0x60(%r12), %rsi
callq 0x23fc2
testl %eax, %eax
je 0x28787
jmp 0x287a9
movq %r15, %rdi
leaq 0xddbf(%rip), %rsi      # 0x3651b
callq 0x8420
movq %rax, %rdi
movl %r13d, %esi
callq 0x8740
movq %rax, %rdi
leaq 0xdfef(%rip), %rsi      # 0x36765
jmp 0x28782
movq %r15, %rdi
leaq 0xe001(%rip), %rsi      # 0x36783
callq 0x8420
addq $0x48, %r12
decl %ebp
jmp 0x286c6
movq 0x20(%rsp), %rbx
addq $0xf8, %rbx
movl 0x14(%rsp), %eax
incl %eax
jmp 0x2869a
movq 0x18(%rsp), %rax
cmpl $0x0, 0x60(%rax)
jle 0x2883a
leaq 0xdf7b(%rip), %rsi      # 0x3673a
movq %r15, %rdi
callq 0x8420
movq %rax, %rdi
movl %r13d, %esi
callq 0x8740
leaq 0xdf68(%rip), %rsi      # 0x36741
movq %rax, %rdi
callq 0x8420
movq %rax, %rdi
movl 0x10(%rsp), %esi
callq 0x8740
leaq 0xdd9e(%rip), %rsi      # 0x36592
movq %rax, %rdi
callq 0x8420
movl $0x90, %r13d
leaq (%r14,%r13), %rsi
movq %rax, %rdi
callq 0x8420
leaq 0xdf33(%rip), %rsi      # 0x36748
movq %rax, %rdi
callq 0x8420
addq %r12, %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0x8420
leaq 0xea5a(%rip), %rsi      # 0x3728c
movq %rax, %rdi
callq 0x8420
movq 0x30(%rsp), %rdx
addq $0xf0, %rdx
movq 0x28(%rsp), %rcx
leaq 0x48(%rcx), %rax
testq %rcx, %rcx
movq 0x48(%r14), %rcx
cmoveq %rdx, %rax
movq %rcx, (%rax)
movq 0x58(%r12), %rax
movq %rax, 0x48(%r14)
movq %r14, 0x58(%r12)
movq 0x58(%r14), %rax
movq 0x20(%rsp), %rbx
testq %rax, %rax
je 0x2888e
movq 0x48(%rax), %rcx
movq %r14, 0x48(%rax)
movq %rax, 0x58(%r12)
movq %rax, %r14
movq %rcx, %rax
jmp 0x28874
movq 0x18(%rsp), %rax
cmpl $0x2, 0x60(%rax)
jl 0x288dc
leaq 0x90(%r12), %rsi
movq %r15, %rdi
callq 0x8420
leaq 0xed85(%rip), %rsi      # 0x37635
movq %rax, %rdi
callq 0x8420
movq %rax, %r14
movq %r12, %rsi
callq 0x288f4
movq %r14, %rdi
movl %eax, %esi
callq 0x8740
leaq 0xde86(%rip), %rsi      # 0x3675a
movq %rax, %rdi
callq 0x8420
xorl %eax, %eax
testq %rbx, %rbx
setne %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop