// File: /workspace/github_cpp_makefile_star2_O3/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 $0x78, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, %r13
movq %rcx, %rbp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x27c1a
movsd (%rbx), %xmm0
movl $0x11, %ebx
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
ja 0x34e21
movsd 0x60(%rsp), %xmm1
ucomisd %xmm1, %xmm2
ja 0x34e21
movsd 0x68(%rsp), %xmm2
ucomisd 0x10(%r14), %xmm2
ja 0x34e21
movsd 0x70(%rsp), %xmm3
ucomisd 0x18(%r14), %xmm3
ja 0x34e21
xorl %ebx, %ebx
ucomisd 0x10(%rbp), %xmm0
jae 0x34e21
ucomisd 0x18(%rbp), %xmm1
jae 0x34e21
movsd (%rbp), %xmm0
ucomisd %xmm2, %xmm0
jae 0x34e21
movsd 0x8(%rbp), %xmm0
ucomisd %xmm3, %xmm0
jae 0x34e21
movq (%r15), %rdx
cmpq %r15, %rdx
je 0x34c61
xorl %ebp, %ebp
xorl %esi, %esi
movq 0x10(%rdx), %rdi
movl 0x80(%rdi), %eax
testl %eax, %eax
je 0x34944
movq 0x68(%rdi), %rcx
addl 0x8(%rcx), %esi
movl $0x10, %ebx
jmp 0x34946
xorl %ebx, %ebx
cmpl $0x0, 0x8(%rsp)
je 0x3495b
testl %eax, %eax
je 0x3495b
cmpl 0x8(%rsp), %esi
jl 0x34c53
movl %esi, 0x34(%rsp)
movq %rdx, 0x50(%rsp)
movq %rdi, 0x28(%rsp)
movq 0x78(%rdi), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x27772
testl %eax, %eax
jg 0x34d86
movq %rbp, 0x38(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
cmpl $0x2, 0x8(%r12)
movq 0x28(%rsp), %rdi
jl 0x34c45
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %ebp, %ebp
movl $0xffffffff, 0x18(%rsp) # imm = 0xFFFFFFFF
movq %r8, 0x40(%rsp)
movl %r9d, 0x20(%rsp)
incq 0x288(%r14)
movq 0x78(%rdi), %rdi
movq 0x10(%r12), %rsi
movq %rcx, 0x10(%rsp)
addq %rcx, %rsi
leaq 0xc(%rsp), %rdx
callq 0x27772
movl %eax, %esi
movl $0x2, %eax
testl %esi, %esi
jg 0x34e1f
sete %al
movl 0xc(%rsp), %ecx
testl %ecx, %ecx
setns %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x34a26
testq %rbp, %rbp
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %r8
je 0x34a47
movq 0x40(%r12), %rax
leaq (%rax,%r8), %rdx
addq $-0x8, %rdx
addq %r8, %rax
jmp 0x34a59
testl %esi, %esi
movq 0x28(%rsp), %rdi
movq 0x40(%rsp), %r8
js 0x34bbe
movq 0x10(%rsp), %rcx
movl 0x20(%rsp), %r9d
jmp 0x34c25
movslq 0x8(%r12), %rdx
movq 0x40(%r12), %rax
leaq (%rax,%rdx,8), %rdx
addq $-0x10, %rdx
movl 0x20(%rsp), %r9d
movl %ecx, %ecx
movq 0x78(%rdi), %rsi
movsd (%rdx), %xmm0
movsd 0x75b0(%rip), %xmm6     # 0x3c020
addsd %xmm6, %xmm0
movapd %xmm0, %xmm1
movsd 0x97e8(%rip), %xmm7     # 0x3e268
addsd %xmm7, %xmm1
movapd %xmm6, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movsd (%rax), %xmm3
movq 0x40(%rsi), %rax
movsd (%rax,%rcx,8), %xmm0
movapd %xmm0, %xmm4
addsd %xmm6, %xmm4
movapd %xmm4, %xmm5
addsd %xmm7, %xmm5
movapd %xmm6, %xmm1
cmpltsd %xmm4, %xmm1
andpd %xmm1, %xmm5
andnpd %xmm4, %xmm1
orpd %xmm5, %xmm1
xorpd %xmm4, %xmm4
ucomisd %xmm1, %xmm4
movapd %xmm1, %xmm4
addsd 0x9781(%rip), %xmm4     # 0x3e260
movapd %xmm0, %xmm5
addsd 0x971d(%rip), %xmm5     # 0x3e208
jbe 0x34b1c
ucomisd %xmm0, %xmm1
movq 0x10(%rsp), %rcx
ja 0x34b27
ucomisd %xmm2, %xmm5
movl $0x3, %eax
jb 0x34e1f
ucomisd %xmm4, %xmm2
jb 0x34e1f
ucomisd %xmm3, %xmm5
jae 0x34b42
jmp 0x34e1f
ucomisd %xmm1, %xmm0
movq 0x10(%rsp), %rcx
jae 0x34af8
ucomisd %xmm2, %xmm5
movl $0x3, %eax
jae 0x34b3c
ucomisd %xmm4, %xmm2
jb 0x34e1f
ucomisd %xmm3, %xmm5
jae 0x34b4c
ucomisd %xmm4, %xmm3
jb 0x34e1f
xorpd %xmm4, %xmm4
ucomisd %xmm2, %xmm4
movapd %xmm2, %xmm4
addsd 0x9700(%rip), %xmm4     # 0x3e260
movapd %xmm3, %xmm5
addsd 0x969c(%rip), %xmm5     # 0x3e208
jbe 0x34b8f
ucomisd %xmm3, %xmm2
jbe 0x34b95
ucomisd %xmm4, %xmm1
jae 0x34b84
ucomisd %xmm1, %xmm5
jb 0x34e1f
ucomisd %xmm0, %xmm5
jb 0x34bb3
jmp 0x34c25
ucomisd %xmm2, %xmm3
jb 0x34b74
ucomisd %xmm4, %xmm1
jb 0x34e1f
ucomisd %xmm1, %xmm5
jb 0x34e1f
ucomisd %xmm0, %xmm5
jb 0x34e1f
ucomisd %xmm4, %xmm0
jae 0x34c25
jmp 0x34e1f
movl 0x1c(%rsp), %eax
testl %eax, %eax
setns %cl
addl %esi, %eax
setne %dl
testb %dl, %cl
movl 0x20(%rsp), %r9d
jne 0x34be0
movl %ebp, 0x18(%rsp)
movq 0x10(%rsp), %rcx
jmp 0x34c1f
movl %eax, %ecx
negl %ecx
movq 0x78(%rdi), %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 0x18(%rsp), %edx
addl %edx, %edx
movl %r9d, %ecx
subl %edx, %ecx
cmpl 0x8(%r12), %ecx
setle %cl
movl %ebp, 0x18(%rsp)
cmpb %cl, %al
movq 0x10(%rsp), %rcx
jne 0x34d8e
notl %esi
movl %esi, 0x1c(%rsp)
incq %rbp
movslq 0x8(%r12), %rax
decq %rax
addl $0x2, %r9d
addq $0x8, %r8
addq $0x10, %rcx
cmpq %rax, %rbp
jl 0x349b7
movq 0x38(%rsp), %rbp
movq 0x50(%rsp), %rdx
movl 0x34(%rsp), %esi
incl %ebp
movq (%rdx), %rdx
cmpq %r15, %rdx
jne 0x34928
movq (%r15), %rdx
movl $0x0, %ebp
cmpq %r15, %rdx
je 0x34d24
xorl %ebp, %ebp
movq %r15, 0x48(%rsp)
movq 0x10(%rdx), %rsi
movl 0x80(%rsi), %eax
testl %eax, %eax
je 0x34c95
movq 0x68(%rsi), %rcx
addl 0x8(%rcx), %ebp
movl $0x12, %ebx
jmp 0x34c9a
movl $0x2, %ebx
cmpl $0x0, 0x8(%rsp)
je 0x34cab
testl %eax, %eax
je 0x34cab
cmpl 0x8(%rsp), %ebp
jl 0x34d18
movq %rdx, 0x20(%rsp)
movq %rbp, 0x10(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq 0x78(%rsi), %rax
cmpl $0x0, 0x8(%rax)
jle 0x34d09
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %rsi, %r15
incq 0x288(%r14)
movq 0x10(%rax), %rsi
addq %r13, %rsi
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
callq 0x27772
testl %eax, %eax
jg 0x34e21
incq %rbp
movq %r15, %rsi
movq 0x78(%r15), %rax
movslq 0x8(%rax), %rcx
addq $0x10, %r13
cmpq %rcx, %rbp
jl 0x34ccc
movq 0x10(%rsp), %rbp
movq 0x20(%rsp), %rdx
movq 0x48(%rsp), %r15
movq (%rdx), %rdx
cmpq %r15, %rdx
jne 0x34c79
movq (%r15), %r13
cmpq %r15, %r13
je 0x34d7f
movq 0x10(%r13), %rax
movl 0x80(%rax), %ecx
testl %ecx, %ecx
je 0x34d48
movq 0x68(%rax), %rdx
addl 0x8(%rdx), %ebp
movl $0x13, %ebx
jmp 0x34d4d
movl $0x3, %ebx
cmpl $0x0, 0x8(%rsp)
je 0x34d5e
testl %ecx, %ecx
je 0x34d5e
cmpl 0x8(%rsp), %ebp
jl 0x34d79
movq 0x78(%rax), %rsi
incq 0x290(%r14)
movq %r12, %rdi
callq 0x287a6
testb %al, %al
jne 0x34e21
movq (%r13), %r13
jmp 0x34d27
xorl %ebx, %ebx
jmp 0x34e21
orl $0x2, %ebx
jmp 0x34e21
cmpl $0x3, 0x60(%r14)
jl 0x34e1a
movl %esi, %ebp
addq $0x68, %r14
leaq 0xad29(%rip), %rsi      # 0x3facf
movl $0x46, %edx
movq %r14, %rdi
callq 0x74e0
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x7720
movq %rax, %r14
leaq 0xad4c(%rip), %rsi      # 0x3fb16
movl $0xf, %edx
movq %rax, %rdi
callq 0x74e0
movq %r14, %rdi
movl 0x1c(%rsp), %esi
callq 0x7720
movq %rax, %r14
leaq 0xa493(%rip), %rsi      # 0x3f280
movl $0x5, %edx
movq %rax, %rdi
callq 0x74e0
movl %ebp, %esi
notl %esi
movq %r14, %rdi
callq 0x7720
leaq 0xa4bf(%rip), %rsi      # 0x3f2cc
movl $0x1, %edx
movq %rax, %rdi
callq 0x74e0
movl $0x2, %eax
orl %eax, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq