// File: /workspace/github_cpp_makefile_star2_O3/thierry7100[P]CutOptim/src/SvgDoc.cpp
// Function: ComputeFreeRotAngle(Polygon*, int, Polygon*, int, int, double&)
bool ComputeFreeRotAngle(Polygon *FloatPoly, int iVertexFloat, Polygon *FixedPoly, int iVertexFixed, int iRot, double &angle)
{
double sf1, sf2;
double sm1, sm2;

    //  First compute angles of edges ogf Fixed polygon
    if ( iVertexFixed == 0)
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sf1 = FixedPoly->getSlope(FixedPoly->nVertices-2) + M_PI;
        if ( sf1 > M_PI ) sf1 -= 2*M_PI;
        sf2 = FixedPoly->getSlope(0);
    }
    else
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sf1 = FixedPoly->getSlope(iVertexFixed-1) + M_PI;
        if ( sf1 > M_PI ) sf1 -= 2*M_PI;
        sf2 = FixedPoly->getSlope(iVertexFixed);
    }
    //  Then angles for the floating polygon
    if ( iVertexFloat == 0)
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sm1 = FloatPoly->getSlope(FloatPoly->nVertices-2) + M_PI;
        if ( sm1 > M_PI ) sm1 -= 2*M_PI;
        sm2 = FloatPoly->getSlope(0);
    }
    else
    {
        //  Arrival segment, angle is pi + slope, and if angle is greater than pi, substract 2*pi to keep value between -pi and +pi
        sm1 = FloatPoly->getSlope(iVertexFloat-1) + M_PI;
        if ( sm1 > M_PI ) sm1 -= 2*M_PI;
        sm2 = FloatPoly->getSlope(iVertexFloat);
    }
    switch ( iRot )
    {
    case 0:
    //  if iRot is 0, align sm1 on sf1
        angle = sf1 - sm1;
        break;
    case 1:
    //  if iRot is 1, align sm2 on sf1
        angle = sf1 - sm2;
        break;
    case 2:
    //  if iRot is 2, align sm1 on sf2
        angle = sf2 - sm1;
        break;
    case 3:
    //  if iRot is 3, align sm2 on sf2
        angle = sf2 - sm2;
        break;
    default:
        printf("Invalid choice !!\n");
        FloatPoly = 0;
        FloatPoly->nVertices = 0;           //  Segment violation
    }
    sm1 += angle;
    sm2 += angle;
    //  check if sm1 is OK, given angles sm1, smé, sf1 and sf2
    int res1 = CheckOKAngles(sf1, sf2, sm1);
    if ( res1 == 0 ) return false;
    //  Idem with sm2
    int res2 = CheckOKAngles(sf1, sf2, sm2);
    if (res2 == 0 ) return false;
    //  Also check sf1 upon sm1 and sm2
    int res3 = CheckOKAngles(sm1, sm2, sf1);
    if ( res3 == 0 ) return false;
    //  and finally sf2 upon sm1 and sm2
    int res4 = CheckOKAngles(sm1, sm2, sf2);
    if (res4 == 0 ) return false;
    //  All is OK, return true
    return true;
}

// Assembly:
pushq %rbx
subq $0x40, %rsp
movq %r9, %rbx
testl %ecx, %ecx
je 0x30f37
movq 0x40(%rdx), %rdx
movslq %ecx, %rcx
leaq (%rdx,%rcx,8), %rax
leaq (%rdx,%rcx,8), %rcx
addq $-0x8, %rcx
jmp 0x30f47
movslq 0x8(%rdx), %rcx
movq 0x40(%rdx), %rax
leaq (%rax,%rcx,8), %rcx
addq $-0x10, %rcx
movsd 0xb0d1(%rip), %xmm4     # 0x3c020
movsd (%rcx), %xmm0
addsd %xmm4, %xmm0
movsd 0xd309(%rip), %xmm1     # 0x3e268
addsd %xmm0, %xmm1
movapd %xmm4, %xmm3
cmpltsd %xmm0, %xmm3
andpd %xmm3, %xmm1
andnpd %xmm0, %xmm3
orpd %xmm1, %xmm3
testl %esi, %esi
je 0x30f91
movq 0x40(%rdi), %rdx
movslq %esi, %rsi
leaq (%rdx,%rsi,8), %rcx
leaq (%rdx,%rsi,8), %rdx
addq $-0x8, %rdx
jmp 0x30fa1
movslq 0x8(%rdi), %rdx
movq 0x40(%rdi), %rcx
leaq (%rcx,%rdx,8), %rdx
addq $-0x10, %rdx
movsd (%rax), %xmm2
movsd (%rdx), %xmm0
addsd %xmm4, %xmm0
movsd 0xd2b3(%rip), %xmm1     # 0x3e268
addsd %xmm0, %xmm1
cmpltsd %xmm0, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
movsd (%rcx), %xmm5
cmpl $0x3, %r8d
ja 0x310c8
movl %r8d, %eax
leaq 0xd3d6(%rip), %rcx      # 0x3e3b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movapd %xmm3, %xmm0
jmp 0x30ff5
movapd %xmm2, %xmm0
subsd %xmm4, %xmm0
jmp 0x31009
movapd %xmm2, %xmm0
jmp 0x31005
movapd %xmm3, %xmm0
subsd %xmm5, %xmm0
movsd %xmm0, (%rbx)
addsd %xmm0, %xmm4
addsd %xmm0, %xmm5
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm0
movsd 0xd23b(%rip), %xmm1     # 0x3e260
addsd %xmm3, %xmm1
movsd 0xd1d7(%rip), %xmm0     # 0x3e208
addsd %xmm2, %xmm0
jbe 0x31057
ucomisd %xmm2, %xmm3
jbe 0x3105d
ucomisd %xmm1, %xmm4
jae 0x31049
ucomisd %xmm4, %xmm0
jb 0x310c1
ucomisd %xmm1, %xmm5
jae 0x31089
ucomisd %xmm5, %xmm0
jb 0x310c1
jmp 0x31089
ucomisd %xmm3, %xmm2
jb 0x3103d
xorl %eax, %eax
ucomisd %xmm1, %xmm4
jb 0x3114e
ucomisd %xmm4, %xmm0
jb 0x3114e
xorl %eax, %eax
ucomisd %xmm1, %xmm5
jb 0x3114e
ucomisd %xmm5, %xmm0
jb 0x3114e
xorpd %xmm0, %xmm0
ucomisd %xmm4, %xmm0
movsd 0xd1c7(%rip), %xmm0     # 0x3e260
addsd %xmm4, %xmm0
movsd 0xd163(%rip), %xmm1     # 0x3e208
addsd %xmm5, %xmm1
jbe 0x31118
ucomisd %xmm5, %xmm4
jbe 0x3111e
ucomisd %xmm0, %xmm3
jae 0x3113c
ucomisd %xmm3, %xmm1
jae 0x3113c
xorl %eax, %eax
jmp 0x3114e
leaq 0xef02(%rip), %rdi      # 0x3ffd1
movapd %xmm2, 0x30(%rsp)
movapd %xmm3, 0x20(%rsp)
movapd %xmm4, 0x10(%rsp)
movsd %xmm5, 0x8(%rsp)
callq 0x7640
movsd 0x8(%rsp), %xmm5
movapd 0x10(%rsp), %xmm4
movapd 0x20(%rsp), %xmm3
movapd 0x30(%rsp), %xmm2
movl $0x0, 0x8
movsd (%rbx), %xmm0
jmp 0x3100d
ucomisd %xmm4, %xmm5
jb 0x310b1
xorl %eax, %eax
ucomisd %xmm0, %xmm3
jb 0x3114e
ucomisd %xmm3, %xmm1
jb 0x3114e
cmplepd %xmm2, %xmm0
cmplepd %xmm1, %xmm2
andpd %xmm0, %xmm2
jmp 0x3114a
cmplepd %xmm2, %xmm0
cmplepd %xmm1, %xmm2
orpd %xmm0, %xmm2
movd %xmm2, %eax
andb $0x1, %al
addq $0x40, %rsp
popq %rbx
retq