// File: /workspace/github_cpp_makefile_star2_O3/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 $0x28, %rsp
movq 0xa0(%rdi), %rax
testq %rax, %rax
je 0xd7cc
movq %rsi, %r14
movq %rdi, %rbx
movq %rax, 0xa8(%rdi)
xorpd %xmm0, %xmm0
leaq 0x815c(%rip), %rdi      # 0x156f0
movq 0x80(%rax), %rcx
movq %rcx, 0x90(%rax)
movq 0x28(%rax), %rsi
movq 0x78(%rax), %rcx
movq %rcx, 0x88(%rax)
cmpq %rdx, %rsi
jne 0xd5bc
movq 0x20(%rax), %rsi
jmp 0xd5e7
movq %rdx, %rsi
subq 0x8(%rax), %rsi
xorps %xmm1, %xmm1
cvtsi2sd %rsi, %xmm1
mulsd 0x40(%rax), %xmm1
xorl %esi, %esi
ucomisd %xmm1, %xmm0
seta %sil
addsd (%rdi,%rsi,8), %xmm1
cvttsd2si %xmm1, %rsi
addq (%rax), %rsi
movq %rsi, 0x10(%rax)
movq %rcx, %rax
testq %rcx, %rcx
jne 0xd594
leaq 0x50(%rbx), %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movq %rsp, %r12
movq 0xa8(%rbx), %r13
movq 0x88(%r13), %rbp
testq %rbp, %rbp
je 0xd7aa
xorl %eax, %eax
movapd %xmm0, (%rsp)
movq 0x10(%rbp), %r15
cmpq %r15, 0x10(%r13)
jle 0xd69e
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %ecx
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x8b17
testb %al, %al
jne 0xd656
incq %r15
cmpq %r15, 0x10(%r13)
jg 0xd7db
cmpq %r14, 0x8(%rsp)
jle 0xd722
movq %r14, 0x8(%rsp)
movsd 0x40(%r13), %xmm0
movapd %xmm0, %xmm2
movapd 0x7858(%rip), %xmm4     # 0x14ed0
andpd %xmm4, %xmm2
movsd 0x40(%rbp), %xmm1
movapd %xmm1, %xmm3
andpd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0xd6a6
cmpq %r14, 0x28(%rbp)
jne 0xd6b2
movq 0x20(%rbp), %rax
jmp 0xd71e
movq %rbp, %r13
jmp 0xd779
cmpq %r14, 0x28(%r13)
jne 0xd6e9
movq 0x20(%r13), %rax
jmp 0xd71e
movq %r14, %rax
subq 0x8(%rbp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd %xmm0, %xmm1
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm1, %xmm0
seta %al
leaq 0x8017(%rip), %rcx      # 0x156f0
addsd (%rcx,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq (%rbp), %rax
jmp 0xd71e
movq %r14, %rax
subq 0x8(%r13), %rax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd %xmm1, %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
leaq 0x7fe0(%rip), %rcx      # 0x156f0
addsd (%rcx,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq (%r13), %rax
movq %rax, (%rsp)
movl $0x20, %edi
callq 0x3210
movq %rax, 0x20(%rsp)
movq %r13, (%rax)
movq %rbp, 0x8(%rax)
movapd (%rsp), %xmm0
movupd %xmm0, 0x10(%rax)
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0xd756
movq %rax, (%rsi)
addq $0x8, 0x58(%rbx)
jmp 0xd765
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x12eea
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd2a4
movb $0x1, %al
xorpd %xmm0, %xmm0
movq 0x88(%r13), %rbp
testq %rbp, %rbp
jne 0xd61c
movq 0x90(%r13), %rcx
testq %rcx, %rcx
je 0xd7c1
movq $0x0, 0x88(%rcx)
testb $0x1, %al
jne 0xd603
jmp 0xd7c1
movq 0x90(%r13), %rax
testq %rax, %rax
je 0xd7c1
movq $0x0, 0x88(%rax)
movq $0x0, 0xa8(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x30f0
movq %rax, %rbx
leaq 0x8051(%rip), %rsi      # 0x15840
movq %rax, %rdi
callq 0x11cba
leaq 0xe56a(%rip), %rsi      # 0x1bd68
leaq 0x44ef(%rip), %rdx      # 0x11cf4
movq %rbx, %rdi
callq 0x3370
movq %rax, %r14
movq %rbx, %rdi
callq 0x3170
movq %r14, %rdi
callq 0x3380