// File: /workspace/github_cpp_makefile_star2_O2/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: SvgDoc::PlacementNotPossible(Polygon*, std::__cxx11::list<NSVGpath*, std::allocator<NSVGpath*>>, Rectangle*, Point const*, int)
int SvgDoc::PlacementNotPossible(Polygon *CurPoly, std::list<NSVGpath *> FixedPath, Rectangle *OverAll, const Point *RefPoint, int Cached)
{
int PlacedPolygon = 0;
int FixedBit = 0;
int FixedVertex = 0;
int CCW_B;

    //  If bounding box is outside the sheet, return false
    Rectangle BBox = CurPoly->GetBoundingBox();
    if ( BBox.A.x < 0 ) return FAIL_OUTSIDE_SHEET | FIXED_BIT;
    if ( BBox.A.y < 0 ) return FAIL_OUTSIDE_SHEET | FIXED_BIT;
    if ( BBox.B.x > SheetSizeX ) return FAIL_OUTSIDE_SHEET | FIXED_BIT;
    if ( BBox.B.y > SheetSizeY ) return FAIL_OUTSIDE_SHEET | FIXED_BIT;
    //  If BBox outside OverAll return true
    if ( BBox.A.x >= OverAll->B.x ) return 0;
    if ( BBox.A.y >= OverAll->B.y ) return 0;
    if ( BBox.B.x <= OverAll->A.x ) return 0;
    if ( BBox.B.y <= OverAll->A.y ) return 0;

    PlacedPolygon = 0;
    //  Now checks if some vertex of CurPoly lies into a polygon from the list
    FixedVertex = 0;
    for (std::list<NSVGpath *>::iterator it=FixedPath.begin(); it != FixedPath.end(); ++it, PlacedPolygon++)
    {
        NSVGpath *path = *it;
        if ( path->isFixed )
        {
            FixedBit = FIXED_BIT;
            FixedVertex += path->LargePolygon->nVertices;
        }
        else
            FixedBit = 0;
        if ( Cached != 0 && path->isFixed && Cached > FixedVertex) continue;     //  No need to reprocess fixed polygons which are already computed
        //  Check if start point of real path is inside polygon. This test is mandatory to avoid placing two polygons at the same place !
        if ( path->PlacedPolygon->isInPoly(RefPoint) > 0)
            return FAIL_VERTEX_IN_POLYGON | FixedBit;
        //  Then check for all vertices of polygon
        int idx_common_vertex_B = -1;
        int idx_common_vertex_CurPoly = -1;
        int SegmentIndex = -1;
        //  For each vertex of CurPoly, so stop at CurPoly->nVertices - 1 to avoid double check of vertex 0
        for ( int i = 0; i < CurPoly->nVertices - 1; i++ )
        {
            nbPointInPoly++;
            int ResInPoly = path->PlacedPolygon->isInPoly(CurPoly->GetVertex(i), &SegmentIndex);
            if ( ResInPoly > 0 )        //  Vertex in polygon, bad placement
                return FAIL_VERTEX_IN_POLYGON | FixedBit;
            //  If point is on an edge of PlacedPolygon, check angles to verify that this is possible
            if ( ResInPoly == 0 && SegmentIndex >= 0 )
            {
                //  If impossible, the edge will be inside the Placed Polygon.
                if ( !CheckAnglesOnEdge(CurPoly, i, path->PlacedPolygon, SegmentIndex) )
                    return FAIL_EDGE_INTERSECT | FixedBit;
            }
            //  If the 2 polygons share more than 2 vertices with the same order (clockwise or counter clockwise), placement is NOT possible
            if ( ResInPoly < 0  )
            {
                //  Compute difference between indices of common vertices of polygon B ( the biggest one )
                if ( idx_common_vertex_B >= 0 && idx_common_vertex_B + ResInPoly != 0)  //  Check there is already a common vertex and this is NOT the same
                {
                    int diffB = -ResInPoly - idx_common_vertex_B;
                    if (diffB < 0) diffB += path->PlacedPolygon->nVertices - 1;
                    // diffB gives the distance (in number of vertices) between the 2 vertices of the biggest polygon (not CutPoly)
                    //  If this distance is less than half of number of vertices, this is CCW
                    CCW_B = (2*diffB > path->PlacedPolygon->nVertices);
                    // If at least 2 common vertex, one should be CCW and other one CW
                    //  Compute if CurPoly vertex are CW or CCW
                    int CCW_CurPoly = 2*(i-idx_common_vertex_CurPoly) > CurPoly->nVertices;
                    //  SO exclusive OR of CCW_B and CCW_CurPoly should be true
                    if ((CCW_B ^ CCW_CurPoly) == 0 )
                    {
                        if ( debug_level > 2 )
                        {
                            OutDebug << "Placement impossible , polygon share at least 2 vertices with polygon " << PlacedPolygon << ", vertices are " <<  idx_common_vertex_B << " and " << -ResInPoly - 1 << "\n";
                        }
                        return FAIL_VERTEX_IN_POLYGON | FixedBit;
                    }
                }
                idx_common_vertex_B = -ResInPoly - 1;       //  Store common vertex for following loops
                idx_common_vertex_CurPoly = i;
            }
        }
    }
    //  Then checks if some vertex of placed polygons lies in CurPoly

    PlacedPolygon = 0;
    FixedVertex = 0;
    for (std::list<NSVGpath *>::iterator it=FixedPath.begin(); it != FixedPath.end(); ++it, PlacedPolygon++)
    {
        NSVGpath *path = *it;
        if ( path->isFixed )
        {
            FixedBit = FIXED_BIT;
            FixedVertex += path->LargePolygon->nVertices;
        }
        else
            FixedBit = 0;
        if ( Cached != 0 && path->isFixed && Cached > FixedVertex) continue;       //  No need to reprocess fixed polygons already computed
        int SegmentIndex = -1;
        for ( int i = 0; i < path->PlacedPolygon->nVertices; i++ )
        {
            nbPointInPoly++;
            int ResInPoly = CurPoly->isInPoly(path->PlacedPolygon->GetVertex(i), &SegmentIndex);
            if ( ResInPoly > 0 )        //  Vertex in polygon, bad placement
                return FAIL_VERTEX_IN_POLYGON | FixedBit;
        }
    }
    //  Last, also checks if polygon overlap with segment crossing, without point inclusion.
    //  Check if one segment of CurPoly intersect with one segment of one of the fixed polygons
    for (std::list<NSVGpath *>::iterator it=FixedPath.begin(); it != FixedPath.end(); ++it, PlacedPolygon++)
    {
        NSVGpath *path = *it;
        if ( path->isFixed )
        {
            FixedBit = FIXED_BIT;
            FixedVertex += path->LargePolygon->nVertices;
        }
        else
            FixedBit = 0;
        if ( Cached != 0 && path->isFixed && Cached > FixedVertex) continue;       //  No need to reprocess fixed polygons already computed
        Polygon *fPoly = path->PlacedPolygon;
        nbIntersectPoly++;
        if ( CurPoly->Intersect(fPoly) )
            return FAIL_EDGE_INTERSECT | FixedBit;
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x2329a
movsd (%r14), %xmm0
pushq $0x11
popq %r14
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
ja 0x2dc34
movsd 0x90(%rsp), %xmm1
ucomisd %xmm1, %xmm2
ja 0x2dc34
movsd 0x98(%rsp), %xmm2
ucomisd 0x10(%rbx), %xmm2
ja 0x2dc34
movsd 0xa0(%rsp), %xmm3
ucomisd 0x18(%rbx), %xmm3
ja 0x2dc34
xorl %r14d, %r14d
ucomisd 0x10(%rbp), %xmm0
jae 0x2dc34
ucomisd 0x18(%rbp), %xmm1
jae 0x2dc34
movsd (%rbp), %xmm0
ucomisd %xmm2, %xmm0
jae 0x2dc34
movsd 0x8(%rbp), %xmm0
ucomisd %xmm3, %xmm0
jae 0x2dc34
movq $0x0, 0x40(%rsp)
movq %r15, %rax
xorl %ebp, %ebp
movl 0x8(%rsp), %edx
movq (%rax), %rax
cmpq %r15, %rax
je 0x2db0a
movq %rax, 0x58(%rsp)
movq 0x10(%rax), %rdi
movl 0x80(%rdi), %eax
testl %eax, %eax
je 0x2d876
movq 0x68(%rdi), %rcx
movq 0x40(%rsp), %rsi
addl 0x8(%rcx), %esi
movq %rsi, 0x40(%rsp)
pushq $0x10
popq %r14
jmp 0x2d879
xorl %r14d, %r14d
testl %edx, %edx
je 0x2d88b
testl %eax, %eax
je 0x2d88b
cmpl %edx, 0x40(%rsp)
jl 0x2daf7
movq %rdi, 0x38(%rsp)
movq 0x78(%rdi), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x22e40
testl %eax, %eax
jg 0x2dbbd
movl %ebp, 0x34(%rsp)
orl $-0x1, 0xc(%rsp)
xorl %ebp, %ebp
xorl %ecx, %ecx
movq $0x0, 0x48(%rsp)
xorl %edi, %edi
pushq $-0x1
popq %rax
movl %eax, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq 0x38(%rsp), %rsi
movslq 0x8(%r12), %rax
decq %rax
cmpq %rax, %rdi
jge 0x2daef
movq %rdi, 0x28(%rsp)
incq 0x288(%rbx)
movq 0x78(%rsi), %rdi
movq 0x10(%r12), %rsi
movq %rcx, 0x18(%rsp)
addq %rcx, %rsi
leaq 0xc(%rsp), %rdx
callq 0x22e40
testl %eax, %eax
jg 0x2dc2e
movl %eax, %r8d
sete %al
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
setns %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x2d948
cmpq $0x0, 0x28(%rsp)
movq 0x38(%rsp), %rsi
je 0x2d965
movq 0x40(%r12), %rax
movq 0x48(%rsp), %rdi
leaq (%rax,%rdi), %rdx
addq $-0x8, %rdx
addq %rdi, %rax
jmp 0x2d977
testl %r8d, %r8d
movq 0x38(%rsp), %rsi
movq 0x28(%rsp), %rdi
js 0x2da76
movq 0x18(%rsp), %rcx
jmp 0x2dada
movslq 0x8(%r12), %rdx
movq 0x40(%r12), %rax
leaq (%rax,%rdx,8), %rdx
addq $-0x10, %rdx
movl %ecx, %ecx
movq 0x78(%rsi), %rsi
movsd (%rdx), %xmm0
movsd 0x6697(%rip), %xmm4     # 0x34020
addsd %xmm4, %xmm0
movapd %xmm0, %xmm1
movsd 0x888f(%rip), %xmm3     # 0x36228
addsd %xmm3, %xmm1
movapd %xmm4, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x40(%rsi), %rax
movsd (%rax,%rcx,8), %xmm1
movapd %xmm1, %xmm0
addsd %xmm4, %xmm0
movapd %xmm0, %xmm5
addsd %xmm3, %xmm5
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm5
andnpd %xmm0, %xmm4
orpd %xmm5, %xmm4
movapd %xmm4, 0x70(%rsp)
movapd %xmm4, %xmm0
movsd %xmm1, 0x50(%rsp)
movapd %xmm2, 0x60(%rsp)
callq 0x2aa3a
testb %al, %al
je 0x2db03
movapd 0x70(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
callq 0x2aa3a
testb %al, %al
je 0x2db03
movapd 0x60(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
callq 0x2aa3a
testb %al, %al
je 0x2db03
movapd 0x60(%rsp), %xmm0
movsd 0x20(%rsp), %xmm1
movsd 0x50(%rsp), %xmm2
callq 0x2aa3a
testb %al, %al
movq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdi
jne 0x2dada
jmp 0x2db03
movl 0x14(%rsp), %eax
testl %eax, %eax
setns %cl
addl %r8d, %eax
setne %dl
notl %r8d
testb %dl, %cl
jne 0x2da97
movl %edi, 0x10(%rsp)
movq 0x18(%rsp), %rcx
jmp 0x2dad5
movl %eax, %ecx
negl %ecx
movq 0x78(%rsi), %rdx
movl 0x8(%rdx), %edx
notl %eax
addl %edx, %eax
testl %ecx, %ecx
cmovnsl %ecx, %eax
addl %eax, %eax
cmpl %edx, %eax
setg %al
movl 0x10(%rsp), %edx
addl %edx, %edx
movl %ebp, %ecx
subl %edx, %ecx
cmpl 0x8(%r12), %ecx
setle %cl
movl %edi, 0x10(%rsp)
cmpb %cl, %al
movq 0x18(%rsp), %rcx
jne 0x2dbc3
movl %r8d, 0x14(%rsp)
incq %rdi
addq $0x8, 0x48(%rsp)
addq $0x10, %rcx
addl $0x2, %ebp
jmp 0x2d8ce
movl 0x8(%rsp), %edx
movl 0x34(%rsp), %ebp
incl %ebp
movq 0x58(%rsp), %rax
jmp 0x2d840
pushq $0x3
jmp 0x2dc30
xorl %r13d, %r13d
pushq $-0x1
popq %rbp
movq %r15, %rcx
movq (%rcx), %rcx
cmpq %r15, %rcx
je 0x2dc49
movq 0x10(%rcx), %r8
movl 0x80(%r8), %eax
testl %eax, %eax
je 0x2db40
movq %rcx, %rdi
movq 0x68(%r8), %rcx
addl 0x8(%rcx), %r13d
movq %rdi, %rcx
pushq $0x12
jmp 0x2db42
pushq $0x2
popq %r14
testl %edx, %edx
je 0x2db51
testl %eax, %eax
je 0x2db51
cmpl %edx, %r13d
jl 0x2db13
movq %rcx, 0x20(%rsp)
movq %r13, 0x18(%rsp)
orl $-0x1, 0xc(%rsp)
xorl %esi, %esi
movq 0x78(%r8), %rax
movslq 0x8(%rax), %rcx
incq %rbp
cmpq %rcx, %rbp
jge 0x2dba7
incq 0x288(%rbx)
leaq 0x10(%rsi), %rcx
movq %rcx, 0x28(%rsp)
addq 0x10(%rax), %rsi
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
movq %r8, %r13
callq 0x22e40
movq %r13, %r8
movq 0x28(%rsp), %rsi
testl %eax, %eax
jle 0x2db62
jmp 0x2dc34
movl 0x8(%rsp), %edx
movq 0x18(%rsp), %r13
pushq $-0x1
popq %rbp
movq 0x20(%rsp), %rcx
jmp 0x2db13
orl $0x2, %r14d
jmp 0x2dc34
cmpl $0x3, 0x60(%rbx)
jl 0x2dc2e
movl %r8d, %ebp
addq $0x68, %rbx
leaq 0x9eb8(%rip), %rsi      # 0x37a8f
movq %rbx, %rdi
callq 0x8420
movq %rax, %rdi
movl 0x34(%rsp), %esi
callq 0x8740
leaq 0x9ee4(%rip), %rsi      # 0x37ad6
movq %rax, %rdi
callq 0x8420
movq %rax, %rdi
movl 0x14(%rsp), %esi
callq 0x8740
leaq 0x9633(%rip), %rsi      # 0x37240
movq %rax, %rdi
callq 0x8420
movq %rax, %rdi
movl %ebp, %esi
callq 0x8740
leaq 0x9666(%rip), %rsi      # 0x3728c
movq %rax, %rdi
callq 0x8420
pushq $0x2
popq %rax
orl %eax, %r14d
movl %r14d, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rbp
movq (%rbp), %rbp
cmpq %r15, %rbp
je 0x2dc9e
movq 0x10(%rbp), %rax
movl 0x80(%rax), %ecx
testl %ecx, %ecx
je 0x2dc6f
movq 0x68(%rax), %rdx
addl 0x8(%rdx), %r13d
pushq $0x13
jmp 0x2dc71
pushq $0x3
popq %r14
cmpl $0x0, 0x8(%rsp)
je 0x2dc85
testl %ecx, %ecx
je 0x2dc85
cmpl 0x8(%rsp), %r13d
jl 0x2dc4c
movq 0x78(%rax), %rsi
incq 0x290(%rbx)
movq %r12, %rdi
callq 0x23c9c
testb %al, %al
je 0x2dc4c
jmp 0x2dc34
xorl %r14d, %r14d
jmp 0x2dc34
nop