// File: hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::ProcessEdgesAtTopOfScanbeam(long long)
void Clipper::ProcessEdgesAtTopOfScanbeam(const cInt topY)
{
  TEdge* e = m_ActiveEdges;
  while( e )
  {
    //1. process maxima, treating them as if they're 'bent' horizontal edges,
    //   but exclude maxima with horizontal edges. nb: e can't be a horizontal.
    bool IsMaximaEdge = IsMaxima(e, topY);

    if(IsMaximaEdge)
    {
      TEdge* eMaxPair = GetMaximaPair(e);
      IsMaximaEdge = (!eMaxPair || !IsHorizontal(*eMaxPair));
    }

    if(IsMaximaEdge)
    {
      TEdge* ePrev = e->PrevInAEL;
      DoMaxima(e);
      if( !ePrev ) e = m_ActiveEdges;
      else e = ePrev->NextInAEL;
    }
    else
    {
      //2. promote horizontal edges, otherwise update Curr.X and Curr.Y ...
      if (IsIntermediate(e, topY) && IsHorizontal(*e->NextInLML))
      {
        UpdateEdgeIntoAEL(e);
        if (e->OutIdx >= 0)
          AddOutPt(e, e->Bot);
        AddEdgeToSEL(e);
      } 
      else
      {
        e->Curr.X = TopX( *e, topY );
        e->Curr.Y = topY;
      }

      if (m_StrictSimple)
      {  
        TEdge* ePrev = e->PrevInAEL;
        if ((e->OutIdx >= 0) && (e->WindDelta != 0) && ePrev && (ePrev->OutIdx >= 0) &&
          (ePrev->Curr.X == e->Curr.X) && (ePrev->WindDelta != 0))
        {
          OutPt* op = AddOutPt(ePrev, e->Curr);
          OutPt* op2 = AddOutPt(e, e->Curr);
          AddJoin(op, op2, e->Curr); //StrictlySimple (type-3) join
        }
      }

      e = e->NextInAEL;
    }
  }

  //3. Process horizontals at the Top of the scanbeam ...
  ProcessHorizontals(true);

  //4. Promote intermediate vertices ...
  e = m_ActiveEdges;
  while(e)
  {
    if(IsIntermediate(e, topY))
    {
      OutPt* op = 0;
      if( e->OutIdx >= 0 ) 
        op = AddOutPt(e, e->Top);
      UpdateEdgeIntoAEL(e);

      //if output polygons share an edge, they'll need joining later ...
      TEdge* ePrev = e->PrevInAEL;
      TEdge* eNext = e->NextInAEL;
      if (ePrev && ePrev->Curr.X == e->Bot.X &&
        ePrev->Curr.Y == e->Bot.Y && op &&
        ePrev->OutIdx >= 0 && ePrev->Curr.Y > ePrev->Top.Y &&
        SlopesEqual(*e, *ePrev, m_UseFullRange) &&
        (e->WindDelta != 0) && (ePrev->WindDelta != 0))
      {
        OutPt* op2 = AddOutPt(ePrev, e->Bot);
        AddJoin(op, op2, e->Top);
      }
      else if (eNext && eNext->Curr.X == e->Bot.X &&
        eNext->Curr.Y == e->Bot.Y && op &&
        eNext->OutIdx >= 0 && eNext->Curr.Y > eNext->Top.Y &&
        SlopesEqual(*e, *eNext, m_UseFullRange) &&
        (e->WindDelta != 0) && (eNext->WindDelta != 0))
      {
        OutPt* op2 = AddOutPt(eNext, e->Bot);
        AddJoin(op, op2, e->Top);
      }
    }
    e = e->NextInAEL;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq 0xa0(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x15fce
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x21370
andb $0x1, %al
movb %al, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
je 0x15e04
movq -0x18(%rbp), %rdi
callq 0x192d0
movq %rax, -0x28(%rbp)
movb $0x1, %al
cmpq $0x0, -0x28(%rbp)
movb %al, -0xa9(%rbp)
je 0x15df9
movq -0x28(%rbp), %rdi
callq 0x20510
xorb $-0x1, %al
movb %al, -0xa9(%rbp)
movb -0xa9(%rbp), %al
andb $0x1, %al
movb %al, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
je 0x15e55
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rsi
callq 0x1a2b0
cmpq $0x0, -0x30(%rbp)
jne 0x15e44
movq -0xa8(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x15e50
movq -0x30(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x15fc9
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x213c0
testb $0x1, %al
jne 0x15e68
jmp 0x15ebb
movq -0x18(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x20510
testb $0x1, %al
jne 0x15e7b
jmp 0x15ebb
movq -0xa8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19aa0
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x15ea9
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x175e0
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x17c90
jmp 0x15edf
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x20580
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xa8(%rbp), %rax
testb $0x1, 0xbe(%rax)
je 0x15fbd
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x15fbb
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x15fbb
cmpq $0x0, -0x38(%rbp)
je 0x15fbb
movq -0x38(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x15fbb
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x15fbb
movq -0x38(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x15fbb
movq -0xa8(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x10, %rdx
callq 0x175e0
movq -0xa8(%rbp), %rdi
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x10, %rdx
callq 0x175e0
movq -0xa8(%rbp), %rdi
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rcx
movq -0x50(%rbp), %r8
callq 0x17850
jmp 0x15fbd
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x15da9
movq -0xa8(%rbp), %rdi
movl $0x1, %esi
callq 0x15bb0
movq -0xa8(%rbp), %rax
movq 0xa0(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x16273
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x213c0
testb $0x1, %al
jne 0x16012
jmp 0x16262
movq $0x0, -0x60(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x16040
movq -0xa8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x20, %rdx
callq 0x175e0
movq %rax, -0x60(%rbp)
movq -0xa8(%rbp), %rdi
leaq -0x18(%rbp), %rsi
callq 0x19aa0
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x16161
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x16161
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x16161
cmpq $0x0, -0x60(%rbp)
je 0x16161
movq -0x68(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x16161
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x68(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jle 0x16161
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movb 0x18(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x118c0
testb $0x1, %al
jne 0x160fa
jmp 0x16161
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x16161
movq -0x68(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x16161
movq -0xa8(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x175e0
movq -0xa8(%rbp), %rdi
movq %rax, -0x78(%rbp)
movq -0x60(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rcx
movq -0x80(%rbp), %r8
callq 0x17850
jmp 0x16260
cmpq $0x0, -0x70(%rbp)
je 0x1625e
movq -0x70(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x1625e
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1625e
cmpq $0x0, -0x60(%rbp)
je 0x1625e
movq -0x70(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jl 0x1625e
movq -0x70(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x70(%rbp), %rcx
cmpq 0x28(%rcx), %rax
jle 0x1625e
movq -0xa8(%rbp), %rax
movq -0x18(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movb 0x18(%rax,%rcx), %al
andb $0x1, %al
movzbl %al, %edx
callq 0x118c0
testb $0x1, %al
jne 0x161f0
jmp 0x1625e
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x1625e
movq -0x70(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x1625e
movq -0xa8(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x175e0
movq -0xa8(%rbp), %rdi
movq %rax, -0x90(%rbp)
movq -0x60(%rbp), %rsi
movq -0x90(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x28(%rax), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rcx
movq -0x98(%rbp), %r8
callq 0x17850
jmp 0x16260
jmp 0x16262
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x15ff1
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)