// File: /workspace/github_cpp_makefile_star2_O2/realuptime[P]PolyDetector/PolyDetector.cpp
// Function: PolyLine::iCompareLineOrder(PolyLine const&, PolyLine&)
int PolyLine::iCompareLineOrder(const PolyLine &l1, PolyLine &l2)
{
    int result = iComparePointOrder(l1.a, l2.a);

    if (result == 0)
    {
        // in case lines share first point
        // we must order the lines by its slope

        auto dx1 = l1.b.x - l1.a.x;
        auto dy1 = l1.b.y - l1.a.y;
        auto dx2 = l2.b.x - l2.a.x;
        auto dy2 = l2.b.y - l2.a.y;

        // by definition of first and last point we are sure that dy > 0

        if (dx1>0 && dx2<0)
            // line 1 in 1st quadrant, line 2 in 2nd quadrant
            // this means line 2 cames first
            return 1;

        if (dx1<0 && dx2>0)
            // line 1 in 2nd quadrant, line 2 in 1st quadrant
            // this means line 1 cames first
            return -1;

        if (dx1 == 0) {
            // first line is vertical
            if (dx2>0)
                // second line in 1st quadrant
                // first line is previous
                return -1;

            if (dx2<0)
                // second line in 2nd quadrant
                // second line is previous
                return 1;
            // this should no happen
            return 0;
        }

        if (dx2 == 0) {
            // second line is vertical
            if (dx1>0)
                // first line in 1st quadrant
                // second line is previous
                return 1;

            if (dx1<0)
                // first line in 2nd quadrant
                // first line is previous
                return -1;

            // this should not happen
            return 0;
        }


        // calculate the slopes
        double m1 = dy1/dx1;
        double m2 = dy2/dx2;
        // line 1 and line 2 in 2nd quadrant
        if (m1 > m2)
            return -1;
        if (m1 < m2)
            return 1;
        
        // in this case we have the same slope in both lines,
        // which means that both lines are coincident.
        return 0;
    }

    return result;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x26e5
testl %eax, %eax
jne 0x26dd
movups (%r14), %xmm5
movups 0x4(%r14), %xmm2
movups 0x8(%r14), %xmm6
movups 0xc(%r14), %xmm4
movss (%rbx), %xmm7
movss 0x4(%rbx), %xmm3
movss 0x8(%rbx), %xmm0
movss 0xc(%rbx), %xmm1
movlhps %xmm6, %xmm0            # xmm0 = xmm0[0],xmm6[0]
shufps $0xe2, %xmm6, %xmm0     # xmm0 = xmm0[2,0],xmm6[2,3]
movlhps %xmm5, %xmm7            # xmm7 = xmm7[0],xmm5[0]
shufps $0xe2, %xmm5, %xmm7     # xmm7 = xmm7[2,0],xmm5[2,3]
subps %xmm7, %xmm0
movaps %xmm0, %xmm5
shufps $0x55, %xmm0, %xmm5     # xmm5 = xmm5[1,1],xmm0[1,1]
xorps %xmm6, %xmm6
ucomiss %xmm6, %xmm0
pushq $0x1
popq %rcx
jbe 0x2671
ucomiss %xmm5, %xmm6
jbe 0x2671
movl %ecx, %eax
jmp 0x26dd
ucomiss %xmm0, %xmm6
pushq $-0x1
popq %rax
jbe 0x267e
ucomiss %xmm6, %xmm5
ja 0x26dd
ucomiss %xmm6, %xmm0
jne 0x2697
jp 0x2697
ucomiss %xmm6, %xmm5
ja 0x26dd
xorps %xmm0, %xmm0
xorl %eax, %eax
ucomiss %xmm5, %xmm0
seta %al
jmp 0x26dd
ucomiss %xmm6, %xmm5
jne 0x26b4
jp 0x26b4
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
movl %ecx, %eax
ja 0x26dd
xorl %eax, %eax
ucomiss %xmm0, %xmm1
seta %al
negl %eax
jmp 0x26dd
movlhps %xmm4, %xmm1            # xmm1 = xmm1[0],xmm4[0]
shufps $0xe2, %xmm4, %xmm1     # xmm1 = xmm1[2,0],xmm4[2,3]
movlhps %xmm2, %xmm3            # xmm3 = xmm3[0],xmm2[0]
shufps $0xe2, %xmm2, %xmm3     # xmm3 = xmm3[2,0],xmm2[2,3]
subps %xmm3, %xmm1
divps %xmm0, %xmm1
movaps %xmm1, %xmm0
shufps $0x55, %xmm1, %xmm0     # xmm0 = xmm0[1,1],xmm1[1,1]
xorl %ecx, %ecx
ucomiss %xmm1, %xmm0
seta %cl
ucomiss %xmm0, %xmm1
cmovbel %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq