// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xa0(%rdi), %r15
movq %rsp, %rbp
movq %r15, %r13
movq (%r13), %r13
movq %r13, (%rsp)
testq %r13, %r13
je 0xa295
cmpq %rbx, 0x28(%r13)
jne 0xa170
cmpq $0x0, 0x70(%r13)
je 0xa208
movq 0x70(%r13), %rax
testq %rax, %rax
je 0xa170
cmpq $0x0, 0x38(%rax)
je 0xa243
movq %r13, %rdi
movq %rbx, %rsi
callq 0xf607
movq %rax, 0x10(%r13)
movq %rbx, 0x18(%r13)
cmpb $0x1, 0xbe(%r14)
jne 0xa1ff
cmpl $0x0, 0x5c(%r13)
js 0xa1ff
movq 0x80(%r13), %rsi
cmpl $0x0, 0x50(%r13)
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xa1ff
cmpl $0x0, 0x5c(%rsi)
js 0xa1ff
movq 0x10(%rsi), %rax
cmpq 0x10(%r13), %rax
jne 0xa1ff
cmpl $0x0, 0x50(%rsi)
je 0xa1ff
leaq 0x10(%r13), %rbp
movq %r14, %rdi
movq %rbp, %rdx
callq 0xad78
movq %rax, %r12
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rsp, %rbp
callq 0xad78
movq 0x10(%r13), %rcx
movq 0x18(%r13), %r8
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xae86
addq $0x78, %r13
jmp 0xa13a
movq %r13, %rdi
callq 0xbc1c
testq %rax, %rax
je 0xa220
cmpq $0x0, 0x38(%rax)
je 0xa15c
movq 0x80(%r13), %r12
movq %r14, %rdi
movq %r13, %rsi
callq 0xc39c
leaq 0x78(%r12), %r13
testq %r12, %r12
cmoveq %r15, %r13
jmp 0xa13a
movq %r14, %rdi
movq %rbp, %rsi
callq 0xbf5c
movq (%rsp), %r13
cmpl $0x0, 0x5c(%r13)
js 0xa267
movq %r14, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0xad78
movq 0xa8(%r14), %rax
andq $0x0, 0x90(%r13)
testq %rax, %rax
je 0xa282
movq %r13, 0x90(%rax)
movq %r13, 0xa8(%r14)
movq %rax, 0x88(%r13)
jmp 0xa183
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xa022
movq (%r15), %r15
movq %r15, (%rsp)
testq %r15, %r15
je 0xa3d8
cmpq %rbx, 0x28(%r15)
jne 0xa3cf
cmpq $0x0, 0x70(%r15)
je 0xa3cf
cmpl $0x0, 0x5c(%r15)
js 0xa2e0
leaq 0x20(%r15), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0xad78
movq %rax, %r13
jmp 0xa2e3
xorl %r13d, %r13d
movq %r14, %rdi
movq %rsp, %rsi
callq 0xbf5c
movq (%rsp), %r15
movq 0x78(%r15), %r12
movq 0x80(%r15), %rbp
testq %rbp, %rbp
je 0xa34f
movq 0x10(%rbp), %rax
cmpq (%r15), %rax
jne 0xa34f
testq %r13, %r13
je 0xa34f
movq 0x18(%rbp), %rax
cmpq 0x8(%r15), %rax
jne 0xa34f
cmpl $0x0, 0x5c(%rbp)
js 0xa34f
cmpq 0x28(%rbp), %rax
jle 0xa34f
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x7ee7
testb %al, %al
je 0xa34f
cmpl $0x0, 0x50(%r15)
je 0xa34f
cmpl $0x0, 0x50(%rbp)
jne 0xa3ab
testq %r12, %r12
je 0xa3cf
movq 0x10(%r12), %rax
cmpq (%r15), %rax
jne 0xa3cf
testq %r13, %r13
je 0xa3cf
movq 0x18(%r12), %rax
cmpq 0x8(%r15), %rax
jne 0xa3cf
cmpl $0x0, 0x5c(%r12)
js 0xa3cf
cmpq 0x28(%r12), %rax
jle 0xa3cf
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x7ee7
testb %al, %al
je 0xa3cf
cmpl $0x0, 0x50(%r15)
je 0xa3cf
cmpl $0x0, 0x50(%r12)
movq %r12, %rbp
je 0xa3cf
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0xad78
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xae86
addq $0x78, %r15
jmp 0xa2a0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop