// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movl %r9d, %r12d
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, 0x50(%rsp)
leaq 0xa8(%rsp), %rbp
movq %rbp, %rdi
callq 0x2822c
movsd (%rbp), %xmm0
movl $0x11, %ebp
xorpd %xmm2, %xmm2
ucomisd %xmm0, %xmm2
ja 0x35b36
movsd 0xb0(%rsp), %xmm1
ucomisd %xmm1, %xmm2
ja 0x35b36
movsd 0xb8(%rsp), %xmm2
movq 0x50(%rsp), %rax
ucomisd 0x10(%rax), %xmm2
ja 0x35b36
movsd 0xc0(%rsp), %xmm3
ucomisd 0x18(%rax), %xmm3
ja 0x35b36
xorl %ebp, %ebp
ucomisd 0x10(%r14), %xmm0
jae 0x35b36
ucomisd 0x18(%r14), %xmm1
jae 0x35b36
movsd (%r14), %xmm0
ucomisd %xmm2, %xmm0
jae 0x35b36
movsd 0x8(%r14), %xmm0
ucomisd %xmm3, %xmm0
jae 0x35b36
movq (%rbx), %rdx
cmpq %rbx, %rdx
sete %dil
movq %rbx, 0x38(%rsp)
movl %r12d, 0x20(%rsp)
je 0x359a1
movq %rdx, %rcx
addq $0x68, %rax
movq %rax, 0x80(%rsp)
xorl %eax, %eax
movl $0x0, 0x34(%rsp)
movq %rax, 0x68(%rsp)
movq %rcx, 0x88(%rsp)
movq 0x10(%rcx), %r14
movl 0x80(%r14), %eax
testl %eax, %eax
je 0x355e4
movq 0x68(%r14), %rcx
movl 0x34(%rsp), %edx
addl 0x8(%rcx), %edx
movl %edx, 0x34(%rsp)
movl $0x10, 0x18(%rsp)
jmp 0x355ec
movl $0x0, 0x18(%rsp)
testl %r12d, %r12d
je 0x35605
testl %eax, %eax
je 0x35605
movl $0x4, %eax
cmpl %r12d, 0x34(%rsp)
jl 0x35962
movb %dil, 0xf(%rsp)
movq 0x78(%r14), %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x27d3a
testl %eax, %eax
jle 0x3562d
movl 0x18(%rsp), %ebp
orl $0x2, %ebp
movl $0x1, %eax
jmp 0x3595d
movq %r14, 0x10(%rsp)
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
cmpl $0x2, 0x8(%r15)
jl 0x3595b
movl 0x18(%rsp), %eax
movl %eax, %ecx
orl $0x3, %ecx
movl %ecx, 0x24(%rsp)
orl $0x2, %eax
movl %eax, 0x18(%rsp)
movl $0xffffffff, 0x30(%rsp) # imm = 0xFFFFFFFF
xorl %r14d, %r14d
xorl %r12d, %r12d
movl $0x0, 0x48(%rsp)
xorl %ebx, %ebx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x58(%rsp)
movq 0x10(%rsp), %rsi
movq 0x50(%rsp), %rax
incq 0x288(%rax)
movq 0x78(%rsi), %rdi
movq 0x10(%r15), %rsi
addq %r14, %rsi
leaq 0x2c(%rsp), %rdx
callq 0x27d3a
testl %eax, %eax
jle 0x356b1
xorl %r8d, %r8d
movl 0x18(%rsp), %ebp
jmp 0x3591c
movl %eax, %edi
sete %al
movl 0x2c(%rsp), %ecx
testl %ecx, %ecx
setns %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x357f5
testq %rbx, %rbx
movq 0x10(%rsp), %rsi
movl %edi, 0x28(%rsp)
je 0x356e9
movq 0x40(%r15), %rax
leaq (%rax,%r12), %rdx
addq $-0x8, %rdx
addq %r12, %rax
jmp 0x356f9
movslq 0x8(%r15), %rdx
movq 0x40(%r15), %rax
leaq (%rax,%rdx,8), %rdx
addq $-0x10, %rdx
movl %ecx, %ecx
movq 0x78(%rsi), %rsi
movsd (%rdx), %xmm0
movsd 0x7915(%rip), %xmm4     # 0x3d020
addsd %xmm4, %xmm0
movapd %xmm0, %xmm1
movsd 0x9ab5(%rip), %xmm3     # 0x3f1d0
addsd %xmm3, %xmm1
movapd %xmm4, %xmm2
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%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, 0x60(%rsp)
movapd %xmm2, 0x90(%rsp)
callq 0x31bd5
testb %al, %al
je 0x35915
movapd 0x70(%rsp), %xmm0
movsd 0x60(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
callq 0x31bd5
testb %al, %al
je 0x35915
movapd 0x90(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movapd 0x70(%rsp), %xmm2
callq 0x31bd5
testb %al, %al
je 0x35915
movapd 0x90(%rsp), %xmm0
movsd 0x40(%rsp), %xmm1
movsd 0x60(%rsp), %xmm2
callq 0x31bd5
testb %al, %al
movl 0x28(%rsp), %edi
je 0x35915
movb $0x1, %r8b
testl %edi, %edi
movq 0x10(%rsp), %rsi
jns 0x35921
movl 0x30(%rsp), %eax
testl %eax, %eax
sets %cl
addl %edi, %eax
sete %dl
orb %cl, %dl
jne 0x3594c
movl %edi, 0x28(%rsp)
movl %eax, %ecx
negl %ecx
jns 0x35830
movq 0x78(%rsi), %rcx
notl %eax
addl 0x8(%rcx), %eax
movl %eax, %ecx
addl %ecx, %ecx
movq 0x78(%rsi), %rax
cmpl 0x8(%rax), %ecx
setg %dl
movq 0x58(%rsp), %rax
addl %eax, %eax
movl 0x48(%rsp), %ecx
subl %eax, %ecx
cmpl 0x8(%r15), %ecx
setle %cl
cmpb %cl, %dl
movq 0x50(%rsp), %rax
je 0x3590c
cmpl $0x3, 0x60(%rax)
movl 0x18(%rsp), %ebp
jl 0x3590c
movb %dl, 0x40(%rsp)
movl $0x46, %edx
movq 0x80(%rsp), %rbp
movq %rbp, %rdi
leaq 0xb1ad(%rip), %rsi      # 0x40a33
movb %cl, 0x70(%rsp)
callq 0x74d0
movq %rbp, %rdi
movq 0x68(%rsp), %rsi
callq 0x7710
movq %rax, %rbp
movl $0xf, %edx
movq %rax, %rdi
leaq 0xb1cc(%rip), %rsi      # 0x40a7a
callq 0x74d0
movq %rbp, %rdi
movl 0x30(%rsp), %esi
callq 0x7710
movq %rax, %rbp
movl $0x5, %edx
movq %rax, %rdi
leaq 0xa913(%rip), %rsi      # 0x401e4
callq 0x74d0
movl 0x28(%rsp), %esi
notl %esi
movq %rbp, %rdi
callq 0x7710
movl $0x1, %edx
movq %rax, %rdi
leaq 0xa93d(%rip), %rsi      # 0x40230
callq 0x74d0
movb 0x70(%rsp), %cl
movb 0x40(%rsp), %dl
movb $0x1, %r8b
movq 0x10(%rsp), %rsi
movl 0x18(%rsp), %ebp
xorb %cl, %dl
je 0x35948
xorl %r8d, %r8d
jmp 0x35921
xorl %r8d, %r8d
movl 0x24(%rsp), %ebp
movq 0x10(%rsp), %rsi
testb %r8b, %r8b
je 0x35987
incq %rbx
movslq 0x8(%r15), %rax
decq %rax
addl $0x2, 0x48(%rsp)
addq $0x8, %r12
addq $0x10, %r14
cmpq %rax, %rbx
jl 0x35680
jmp 0x3598e
movl 0x28(%rsp), %edi
notl %edi
movl %ebx, %eax
movq %rax, 0x58(%rsp)
movl %edi, 0x30(%rsp)
jmp 0x35921
xorl %eax, %eax
movb 0xf(%rsp), %dil
testb $0x3, %al
jne 0x359a1
movq 0x68(%rsp), %rax
incl %eax
movq 0x88(%rsp), %rcx
movq (%rcx), %rcx
cmpq %rbx, %rcx
sete %dil
jne 0x355af
jmp 0x359a1
movl $0x1, %eax
jmp 0x35990
xorl %eax, %eax
movq 0x38(%rsp), %rbx
movb 0xf(%rsp), %dil
movl 0x20(%rsp), %r12d
jmp 0x35962
testb $0x1, %dil
je 0x35b36
movq (%rbx), %rdi
cmpq %rbx, %rdi
sete %dl
je 0x35ab1
xorl %esi, %esi
movq 0x10(%rdi), %r14
movl 0x80(%r14), %eax
testl %eax, %eax
je 0x359da
movq 0x68(%r14), %rcx
addl 0x8(%rcx), %esi
movl $0x12, %r13d
jmp 0x359e0
movl $0x2, %r13d
testl %r12d, %r12d
je 0x359f7
testl %eax, %eax
je 0x359f7
movl $0xa, %ecx
cmpl %r12d, %esi
jl 0x35a97
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movq 0x78(%r14), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x8(%rax)
jle 0x35a97
movq %rdi, 0x48(%rsp)
movb %dl, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x50(%rsp), %rcx
incq 0x288(%rcx)
movq 0x10(%rax), %rsi
addq %rbx, %rsi
movq %r15, %rdi
leaq 0x2c(%rsp), %rdx
callq 0x27d3a
testl %eax, %eax
cmovgl %r13d, %ebp
jg 0x35a7a
incq %r12
movq 0x78(%r14), %rax
movslq 0x8(%rax), %rcx
addq $0x10, %rbx
cmpq %rcx, %r12
jl 0x35a22
movl 0x20(%rsp), %r12d
movq 0x38(%rsp), %rbx
movq 0x18(%rsp), %rsi
movb 0x10(%rsp), %dl
movq 0x48(%rsp), %rdi
xorl %ecx, %ecx
jmp 0x35a97
movl $0x1, %ecx
movl 0x20(%rsp), %r12d
movq 0x38(%rsp), %rbx
movq 0x18(%rsp), %rsi
movb 0x10(%rsp), %dl
movq 0x48(%rsp), %rdi
cmpl $0xa, %ecx
je 0x35aa0
testl %ecx, %ecx
jne 0x35ab3
movq (%rdi), %rdi
cmpq %rbx, %rdi
sete %dl
jne 0x359bc
jmp 0x35ab3
xorl %esi, %esi
testb $0x1, %dl
je 0x35b36
movq %rbx, %rax
movq (%rbx), %rbx
cmpq %rax, %rbx
je 0x35b34
movq 0x10(%rbx), %rax
movl 0x80(%rax), %ecx
testl %ecx, %ecx
je 0x35ae0
movq 0x68(%rax), %rdx
addl 0x8(%rdx), %esi
movl $0x13, %r14d
jmp 0x35ae6
movl $0x3, %r14d
testl %r12d, %r12d
je 0x35afe
testl %ecx, %ecx
je 0x35afe
movl $0x10, %ecx
cmpl %r12d, %esi
jge 0x35afe
movq %rsi, %r13
jmp 0x35b22
movq %rsi, %r13
movq 0x78(%rax), %rsi
movq 0x50(%rsp), %rax
incq 0x290(%rax)
movq %r15, %rdi
callq 0x28fca
movzbl %al, %ecx
testb %cl, %cl
cmovnel %r14d, %ebp
testb $0xf, %cl
jne 0x35b36
movq (%rbx), %rbx
cmpq 0x38(%rsp), %rbx
movq %r13, %rsi
jne 0x35ac3
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq