// File: /workspace/github_cpp_makefile_star2_O1/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 0xdbdf
movq %rsi, %r14
movq %rdi, %rbx
movq %rax, 0xa8(%rdi)
xorpd %xmm0, %xmm0
leaq 0x7ccc(%rip), %rdi      # 0x15690
movq 0x80(%rax), %rcx
movq %rcx, 0x90(%rax)
movq 0x28(%rax), %rsi
movq 0x78(%rax), %rcx
movq %rcx, 0x88(%rax)
cmpq %rdx, %rsi
jne 0xd9ec
movq 0x20(%rax), %rsi
jmp 0xda17
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 0xd9c4
leaq 0x50(%rbx), %rax
movq %rax, 0x18(%rsp)
xorpd %xmm0, %xmm0
movq %rsp, %r12
movq 0xa8(%rbx), %r13
movq 0x88(%r13), %rbp
xorl %eax, %eax
testq %rbp, %rbp
je 0xdbb5
movapd %xmm0, (%rsp)
movq 0x10(%rbp), %r15
cmpq %r15, 0x10(%r13)
jle 0xdace
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %ecx
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x8e40
testb %al, %al
jne 0xda86
incq %r15
cmpq %r15, 0x10(%r13)
jg 0xdbee
cmpq %r14, 0x8(%rsp)
jle 0xdb52
movq %r14, 0x8(%rsp)
movsd 0x40(%r13), %xmm0
movapd %xmm0, %xmm2
movapd 0x73e8(%rip), %xmm4     # 0x14e90
andpd %xmm4, %xmm2
movsd 0x40(%rbp), %xmm1
movapd %xmm1, %xmm3
andpd %xmm4, %xmm3
ucomisd %xmm3, %xmm2
jbe 0xdad6
cmpq %r14, 0x28(%rbp)
jne 0xdae2
movq 0x20(%rbp), %rax
jmp 0xdb4e
movq %rbp, %r13
jmp 0xdba9
cmpq %r14, 0x28(%r13)
jne 0xdb19
movq 0x20(%r13), %rax
jmp 0xdb4e
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 0x7b87(%rip), %rcx      # 0x15690
addsd (%rcx,%rax,8), %xmm1
cvttsd2si %xmm1, %rax
addq (%rbp), %rax
jmp 0xdb4e
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 0x7b50(%rip), %rcx      # 0x15690
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 0xdb86
movq %rax, (%rsi)
addq $0x8, 0x58(%rbx)
jmp 0xdb95
movq 0x18(%rsp), %rdi
leaq 0x20(%rsp), %rdx
callq 0x134a0
movq %rbx, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xd6d6
movb $0x1, %al
xorpd %xmm0, %xmm0
movq 0x88(%r13), %rbp
jmp 0xda43
movq 0x90(%r13), %rcx
testq %rcx, %rcx
je 0xdbd4
movq $0x0, 0x88(%rcx)
testb $0x1, %al
jne 0xda33
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 0x7bce(%rip), %rsi      # 0x157d0
movq %rax, %rdi
callq 0x1225c
leaq 0xe157(%rip), %rsi      # 0x1bd68
leaq 0x467e(%rip), %rdx      # 0x12296
movq %rbx, %rdi
callq 0x3370
movq %rax, %r14
movq %rbx, %rdi
callq 0x3170
movq %r14, %rdi
callq 0x3380
nop