// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::BuildIntersectList(long long, long long)
void Clipper::BuildIntersectList(const cInt botY, const cInt topY)
{
  if ( !m_ActiveEdges ) return;

  //prepare for sorting ...
  TEdge* e = m_ActiveEdges;
  m_SortedEdges = e;
  while( e )
  {
    e->PrevInSEL = e->PrevInAEL;
    e->NextInSEL = e->NextInAEL;
    e->Curr.X = TopX( *e, topY );
    e = e->NextInAEL;
  }

  //bubblesort ...
  bool isModified;
  do
  {
    isModified = false;
    e = m_SortedEdges;
    while( e->NextInSEL )
    {
      TEdge *eNext = e->NextInSEL;
      IntPoint Pt;
      if(e->Curr.X > eNext->Curr.X)
      {
        if (!IntersectPoint(*e, *eNext, Pt, m_UseFullRange) && e->Curr.X > eNext->Curr.X +1)
          throw clipperException("Intersection error");
        if (Pt.Y > botY)
        {
            Pt.Y = botY;
            if (std::fabs(e->Dx) > std::fabs(eNext->Dx))
              Pt.X = TopX(*eNext, botY); else
              Pt.X = TopX(*e, botY);
        }

        IntersectNode * newNode = new IntersectNode;
        newNode->Edge1 = e;
        newNode->Edge2 = eNext;
        newNode->Pt = Pt;
        m_IntersectList.push_back(newNode);

        SwapPositionsInSEL(e, eNext);
        isModified = true;
      }
      else
        e = eNext;
    }
    if( e->PrevInSEL ) e->PrevInSEL->NextInSEL = 0;
    else break;
  }
  while ( isModified );
  m_SortedEdges = 0; //important
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0xa0(%rdi), %r12
testq %r12, %r12
je 0xc1ae
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %r12, 0xa8(%rdi)
testq %r12, %r12
je 0xc097
movupd 0x78(%r12), %xmm0
movupd %xmm0, 0x88(%r12)
movq %r12, %rdi
movq %r15, %rsi
callq 0xf607
movq %rax, 0x10(%r12)
movq 0x78(%r12), %r12
jmp 0xc06a
leaq 0x50(%rbx), %r15
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rbp
movq 0xa8(%rbx), %r13
xorl %eax, %eax
movq 0x88(%r13), %r12
testq %r12, %r12
je 0xc18a
movapd %xmm0, (%rsp)
movq 0x10(%r13), %rcx
cmpq 0x10(%r12), %rcx
jle 0xc131
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %ecx
movq %r13, %rdi
movq %r12, %rsi
movq %rsp, %rdx
callq 0x806d
testb %al, %al
jne 0xc0fd
movq 0x10(%r12), %rax
incq %rax
cmpq %rax, 0x10(%r13)
jg 0xc1bd
cmpq %r14, 0x8(%rsp)
jle 0xc148
movq %r14, 0x8(%rsp)
movsd 0x40(%r13), %xmm0
movapd 0x6dc9(%rip), %xmm2     # 0x12ee0
andpd %xmm2, %xmm0
movsd 0x40(%r12), %xmm1
andpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xc139
movq %r12, %rdi
jmp 0xc13c
movq %r12, %r13
jmp 0xc0ad
movq %r13, %rdi
movq %r14, %rsi
callq 0xf607
movq %rax, (%rsp)
pushq $0x20
popq %rdi
callq 0x3230
movq %rax, 0x10(%rsp)
movq %r13, (%rax)
movq %r12, 0x8(%rax)
movapd (%rsp), %xmm0
movupd %xmm0, 0x10(%rax)
movq %r15, %rdi
movq %rbp, %rsi
callq 0xf796
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0xbd88
movb $0x1, %al
xorpd %xmm0, %xmm0
jmp 0xc0ad
movq 0x90(%r13), %rcx
testq %rcx, %rcx
je 0xc1a6
andq $0x0, 0x88(%rcx)
testb $0x1, %al
jne 0xc0a4
andq $0x0, 0xa8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x28
popq %rdi
callq 0x3100
movq %rax, %rbx
leaq 0x7671(%rip), %rsi      # 0x13840
movq %rax, %rdi
callq 0xf67a
leaq 0xeb8a(%rip), %rsi      # 0x1ad68
leaq 0x34cf(%rip), %rdx      # 0xf6b4
movq %rbx, %rdi
callq 0x3390
movq %rax, %r14
movq %rbx, %rdi
callq 0x3180
movq %r14, %rdi
callq 0x33a0