// File: /workspace/github_cpp_makefile_star2_O1/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 0xb598
leaq 0xa0(%r14), %r15
leaq 0xa2d1(%rip), %rbp      # 0x15690
cmpq %rbx, 0x28(%r12)
jne 0xb3d1
cmpq $0x0, 0x70(%r12)
sete %al
jmp 0xb3d3
xorl %eax, %eax
testb %al, %al
je 0xb3ec
movq %r12, %rdi
callq 0xd577
testq %rax, %rax
je 0xb3f0
cmpq $0x0, 0x38(%rax)
setne %al
testb %al, %al
je 0xb413
movq 0x80(%r12), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0xdfc0
leaq 0x78(%r13), %rax
testq %r13, %r13
cmoveq %r15, %rax
jmp 0xb510
movq 0x28(%r12), %rax
cmpq %rbx, %rax
jne 0xb441
cmpq $0x0, 0x70(%r12)
je 0xb435
movq 0x70(%r12), %rcx
cmpq $0x0, 0x38(%rcx)
je 0xb523
cmpq %rbx, %rax
jne 0xb441
movq 0x20(%r12), %rax
jmp 0xb474
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 (%rbp,%rax,8), %xmm0
cvttsd2si %xmm0, %rax
addq (%r12), %rax
movq %rax, 0x10(%r12)
movq %rbx, 0x18(%r12)
cmpb $0x1, 0xbe(%r14)
jne 0xb507
movq 0x8(%rsp), %r12
cmpl $0x0, 0x5c(%r12)
js 0xb507
movq 0x80(%r12), %rsi
cmpl $0x0, 0x50(%r12)
setne %al
testq %rsi, %rsi
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xb507
cmpl $0x0, 0x5c(%rsi)
js 0xb507
movq 0x10(%rsi), %rax
cmpq 0x10(%r12), %rax
jne 0xb507
cmpl $0x0, 0x50(%rsi)
je 0xb507
leaq 0x10(%r12), %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0xc328
movq %rax, 0x10(%rsp)
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xc328
movq 0x10(%r12), %rcx
movq 0x18(%r12), %r8
movq %r14, %rdi
movq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0xc452
movq 0x8(%rsp), %rax
addq $0x78, %rax
movq (%rax), %r12
movq %r12, 0x8(%rsp)
testq %r12, %r12
jne 0xb3bf
jmp 0xb598
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd894
movq 0x8(%rsp), %r12
cmpl $0x0, 0x5c(%r12)
js 0xb54b
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc328
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0xb57e
movq %rax, 0x88(%r12)
movq $0x0, 0x90(%r12)
movq %r12, 0x90(%rax)
movq %r12, 0xa8(%r14)
jmp 0xb47e
movq %r12, 0xa8(%r14)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x88(%r12)
jmp 0xb47e
movq %r14, %rdi
movl $0x1, %esi
callq 0xb232
movq 0xa0(%r14), %rsi
movq %rsi, 0x8(%rsp)
testq %rsi, %rsi
je 0xb6e3
cmpq %rbx, 0x28(%rsi)
jne 0xb6d5
cmpq $0x0, 0x70(%rsi)
je 0xb6d5
cmpl $0x0, 0x5c(%rsi)
js 0xb5e6
leaq 0x20(%rsi), %rdx
movq %r14, %rdi
callq 0xc328
movq %rax, %r12
jmp 0xb5e9
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xd894
movq 0x8(%rsp), %r13
movq 0x78(%r13), %r15
movq 0x80(%r13), %rbp
testq %rbp, %rbp
je 0xb659
movq 0x10(%rbp), %rax
cmpq (%r13), %rax
jne 0xb659
testq %r12, %r12
je 0xb659
movq 0x18(%rbp), %rax
cmpq 0x8(%r13), %rax
jne 0xb659
cmpl $0x0, 0x5c(%rbp)
js 0xb659
cmpq 0x28(%rbp), %rax
jle 0xb659
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x8cba
testb %al, %al
je 0xb659
cmpl $0x0, 0x50(%r13)
je 0xb659
cmpl $0x0, 0x50(%rbp)
jne 0xb6b1
testq %r15, %r15
je 0xb6d5
movq 0x10(%r15), %rax
cmpq (%r13), %rax
jne 0xb6d5
testq %r12, %r12
je 0xb6d5
movq 0x18(%r15), %rax
cmpq 0x8(%r13), %rax
jne 0xb6d5
cmpl $0x0, 0x5c(%r15)
js 0xb6d5
cmpq 0x28(%r15), %rax
jle 0xb6d5
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x8cba
testb %al, %al
je 0xb6d5
cmpl $0x0, 0x50(%r13)
je 0xb6d5
cmpl $0x0, 0x50(%r15)
movq %r15, %rbp
je 0xb6d5
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xc328
movq 0x20(%r13), %rcx
movq 0x28(%r13), %r8
movq %r14, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0xc452
movq 0x8(%rsp), %rax
movq 0x78(%rax), %rsi
jmp 0xb5ac
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq