// File: /workspace/github_cpp_makefile_star2_O3/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: SvgDoc::PlaceFirst(Polygon*, int, double)
Polygon *SvgDoc::PlaceFirst(Polygon *p, int FirstPos, double StepAngle)
{
Rectangle BBox;
Polygon *Rot = NULL;
Polygon *cur;

    if ( debug_level > 0 )
    {
        OutDebug << "Entering PlaceFirst...\n";
    }
    //  If possible place polygon at page center
    for (double angle = 0; angle < 2*M_PI - 0.001; angle += StepAngle)
    {
        if ( angle > 0 )
        {
            if (Rot != NULL) delete Rot;
            Rot = p->Rotate(angle);
            cur = Rot;
        }
        else
        {
            cur = p;
        }
        BBox = cur->GetBoundingBox();
        double xSize = BBox.B.x - BBox.A.x;
        double ySize = BBox.B.y - BBox.A.y;
        if ( xSize < SheetSizeX && ySize < SheetSizeY )
        {
            //  Possible, compute new position. new Bounding box point A will be in
            Point newA = ComputeRefPoint(FirstPos, xSize, ySize);
            Point Translation = newA - BBox.A;
            Translation.align_grid();
            Point newPt0 = *(cur->GetVertex(0)) + Translation;
            newPt0.align_grid();
            Polygon *Translated = cur->Translate(&newPt0, 0);        //  Move point 0 to this point
            if ( Rot != NULL ) delete Rot;
            if ( debug_level > 0 )
            {
                OutDebug << "First polygon placed with rotation " <<  round(angle*180/M_PI) << "° and translation " << newPt0 << "\n";
            }
            return Translated;
        }
    }
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movsd %xmm0, (%rsp)
movl %edx, 0x20(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
cmpl $0x0, 0x60(%rdi)
jle 0x32004
leaq 0x68(%rbx), %rdi
leaq 0xda85(%rip), %rsi      # 0x3fa7f
movl $0x17, %edx
callq 0x74e0
xorl %r14d, %r14d
leaq 0x30(%rsp), %rbp
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
ucomisd 0xc225(%rip), %xmm0     # 0x3e240
movsd %xmm0, 0x18(%rsp)
jbe 0x32047
testq %r15, %r15
je 0x32037
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
movsd 0x18(%rsp), %xmm0
movq %r13, %rdi
callq 0x28190
movq %rax, %r12
movq %rax, %r15
jmp 0x3204a
movq %r13, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0x27c1a
movapd 0x30(%rsp), %xmm3
movapd 0x40(%rsp), %xmm0
subpd %xmm3, %xmm0
movupd 0x10(%rbx), %xmm1
movapd %xmm0, %xmm2
cmpltpd %xmm1, %xmm2
movmskpd %xmm2, %eax
cmpl $0x3, %eax
je 0x3209e
movsd 0x18(%rsp), %xmm0
addsd (%rsp), %xmm0
movsd 0xc1e1(%rip), %xmm1     # 0x3e270
ucomisd %xmm0, %xmm1
ja 0x32013
jmp 0x321df
cvttsd2si %xmm0, %edx
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
cvttsd2si %xmm0, %ecx
movq %rbx, %rdi
movl 0x20(%rsp), %esi
movapd %xmm3, (%rsp)
callq 0x34e32
movq 0x10(%r12), %r14
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
subpd (%rsp), %xmm0
divpd 0xbfff(%rip), %xmm0     # 0x3e0d0
movapd %xmm0, 0x20(%rsp)
callq 0x71c0
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
callq 0x71c0
movapd (%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0xbfcf(%rip), %xmm2     # 0x3e0d0
mulpd %xmm2, %xmm1
movupd (%r14), %xmm0
addpd %xmm1, %xmm0
divpd %xmm2, %xmm0
movapd %xmm0, 0x20(%rsp)
callq 0x71c0
movapd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
callq 0x71c0
movapd (%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
mulpd 0xbf8e(%rip), %xmm1     # 0x3e0d0
leaq 0x30(%rsp), %rsi
movapd %xmm1, (%rsi)
movq %r12, %rdi
xorl %edx, %edx
callq 0x27fb4
movq %rax, %r14
testq %r15, %r15
je 0x32166
movq (%r15), %rax
movq %r15, %rdi
callq *0x8(%rax)
cmpl $0x0, 0x60(%rbx)
jle 0x321df
addq $0x68, %rbx
leaq 0xd920(%rip), %rsi      # 0x3fa97
movl $0x23, %edx
movq %rbx, %rdi
callq 0x74e0
movsd 0x18(%rsp), %xmm0
mulsd 0xc07e(%rip), %xmm0     # 0x3e210
divsd 0x9e86(%rip), %xmm0     # 0x3c020
callq 0x71c0
movq %rbx, %rdi
callq 0x7690
movq %rax, %rbx
leaq 0xd90a(%rip), %rsi      # 0x3fabb
movl $0x13, %edx
movq %rax, %rdi
callq 0x74e0
leaq 0x30(%rsp), %rsi
movq %rbx, %rdi
callq 0x3b894
leaq 0xd0fa(%rip), %rsi      # 0x3f2cc
movl $0x1, %edx
movq %rax, %rdi
callq 0x74e0
movq %r14, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop