// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0xa0(%rdi), %r12
movq %r12, 0x8(%rsp)
testq %r12, %r12
je 0xb25f
leaq 0xa0(%r14), %rbp
leaq 0xa639(%rip), %r15      # 0x156f0
cmpq %rbx, 0x28(%r12)
jne 0xb0e6
cmpq $0x0, 0x70(%r12)
je 0xb1cc
movq 0x70(%r12), %rax
testq %rax, %rax
je 0xb0df
cmpq $0x0, 0x38(%rax)
je 0xb204
movq 0x20(%r12), %rax
jmp 0xb119
movq %rbx, %rax
subq 0x8(%r12), %rax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x40(%r12), %xmm0
xorl %eax, %eax
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
seta %al
addsd (%r15,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq (%r12), %rax
movq %rax, 0x10(%r12)
movq %rbx, 0x18(%r12)
cmpb $0x1, 0xbe(%r14)
jne 0xb1b1
cmpl $0x0, 0x5c(%r12)
js 0xb1b1
movq 0x80(%r12), %rsi
cmpl $0x0, 0x50(%r12)
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xb1b1
cmpl $0x0, 0x5c(%rsi)
js 0xb1b1
movq 0x10(%rsi), %rax
cmpq 0x10(%r12), %rax
jne 0xb1b1
cmpl $0x0, 0x50(%rsi)
je 0xb1b1
leaq 0x10(%r12), %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0xbfae
movq %rbp, 0x10(%rsp)
movq %rax, %rbp
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xbfae
movq 0x10(%r12), %rcx
movq 0x18(%r12), %r8
movq %r14, %rdi
movq %rbp, %rsi
movq 0x10(%rsp), %rbp
movq %rax, %rdx
callq 0xc0c0
addq $0x78, %r12
movq (%r12), %r12
movq %r12, 0x8(%rsp)
testq %r12, %r12
jne 0xb0b7
jmp 0xb25f
movq %r12, %rdi
callq 0xd138
testq %rax, %rax
je 0xb1e4
cmpq $0x0, 0x38(%rax)
je 0xb0ca
movq 0x80(%r12), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0xdb94
leaq 0x78(%r13), %r12
testq %r13, %r13
cmoveq %rbp, %r12
jmp 0xb1b5
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd47a
movq 0x8(%rsp), %r12
cmpl $0x0, 0x5c(%r12)
js 0xb22c
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xbfae
movq 0xa8(%r14), %rax
movq $0x0, 0x90(%r12)
testq %rax, %rax
je 0xb24b
movq %r12, 0x90(%rax)
movq %r12, 0xa8(%r14)
movq %rax, 0x88(%r12)
jmp 0xb123
movq %r14, %rdi
movl $0x1, %esi
callq 0xaf38
movq 0xa0(%r14), %r12
movq %r12, 0x8(%rsp)
testq %r12, %r12
je 0xb3b6
cmpq %rbx, 0x28(%r12)
jne 0xb3ac
cmpq $0x0, 0x70(%r12)
je 0xb3ac
cmpl $0x0, 0x5c(%r12)
js 0xb2b5
leaq 0x20(%r12), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0xbfae
movq %rax, %r13
jmp 0xb2b8
xorl %r13d, %r13d
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd47a
movq 0x8(%rsp), %r12
movq 0x78(%r12), %r15
movq 0x80(%r12), %rbp
testq %rbp, %rbp
je 0xb32c
movq 0x10(%rbp), %rax
cmpq (%r12), %rax
jne 0xb32c
testq %r13, %r13
je 0xb32c
movq 0x18(%rbp), %rax
cmpq 0x8(%r12), %rax
jne 0xb32c
cmpl $0x0, 0x5c(%rbp)
js 0xb32c
cmpq 0x28(%rbp), %rax
jle 0xb32c
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x8991
testb %al, %al
je 0xb32c
cmpl $0x0, 0x50(%r12)
je 0xb32c
cmpl $0x0, 0x50(%rbp)
jne 0xb386
testq %r15, %r15
je 0xb3ac
movq 0x10(%r15), %rax
cmpq (%r12), %rax
jne 0xb3ac
testq %r13, %r13
je 0xb3ac
movq 0x18(%r15), %rax
cmpq 0x8(%r12), %rax
jne 0xb3ac
cmpl $0x0, 0x5c(%r15)
js 0xb3ac
cmpq 0x28(%r15), %rax
jle 0xb3ac
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r12, %rdi
movq %r15, %rsi
callq 0x8991
testb %al, %al
je 0xb3ac
cmpl $0x0, 0x50(%r12)
je 0xb3ac
cmpl $0x0, 0x50(%r15)
movq %r15, %rbp
je 0xb3ac
movq %r14, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xbfae
movq 0x20(%r12), %rcx
movq 0x28(%r12), %r8
movq %r14, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0xc0c0
movq 0x78(%r12), %r12
jmp 0xb273
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop