// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::ProcessHorizontal(ClipperLib::TEdge*, bool)
void Clipper::ProcessHorizontal(TEdge *horzEdge, bool isTopOfScanbeam)
{
  Direction dir;
  cInt horzLeft, horzRight;

  GetHorzDirection(*horzEdge, dir, horzLeft, horzRight);

  TEdge* eLastHorz = horzEdge, *eMaxPair = 0;
  while (eLastHorz->NextInLML && IsHorizontal(*eLastHorz->NextInLML)) 
    eLastHorz = eLastHorz->NextInLML;
  if (!eLastHorz->NextInLML)
    eMaxPair = GetMaximaPair(eLastHorz);

  for (;;)
  {
    bool IsLastHorz = (horzEdge == eLastHorz);
    TEdge* e = GetNextInAEL(horzEdge, dir);
    while(e)
    {
      //Break if we've got to the end of an intermediate horizontal edge ...
      //nb: Smaller Dx's are to the right of larger Dx's ABOVE the horizontal.
      if (e->Curr.X == horzEdge->Top.X && horzEdge->NextInLML && 
        e->Dx < horzEdge->NextInLML->Dx) break;

      TEdge* eNext = GetNextInAEL(e, dir); //saves eNext for later

      if ((dir == dLeftToRight && e->Curr.X <= horzRight) ||
        (dir == dRightToLeft && e->Curr.X >= horzLeft))
      {
        if (horzEdge->OutIdx >= 0 && horzEdge->WindDelta != 0) 
          PrepareHorzJoins(horzEdge, isTopOfScanbeam);
        //so far we're still in range of the horizontal Edge  but make sure
        //we're at the last of consec. horizontals when matching with eMaxPair
        if(e == eMaxPair && IsLastHorz)
        {
          if (dir == dLeftToRight)
            IntersectEdges(horzEdge, e, e->Top);
          else
            IntersectEdges(e, horzEdge, e->Top);
          if (eMaxPair->OutIdx >= 0) throw clipperException("ProcessHorizontal error");
          return;
        }
        else if(dir == dLeftToRight)
        {
          IntPoint Pt = IntPoint(e->Curr.X, horzEdge->Curr.Y);
          IntersectEdges(horzEdge, e, Pt, true);
        }
        else
        {
          IntPoint Pt = IntPoint(e->Curr.X, horzEdge->Curr.Y);
          IntersectEdges( e, horzEdge, Pt, true);
        }
        SwapPositionsInAEL( horzEdge, e );
      }
      else if( (dir == dLeftToRight && e->Curr.X >= horzRight) ||
       (dir == dRightToLeft && e->Curr.X <= horzLeft) ) break;
      e = eNext;
    } //end while

    if (horzEdge->OutIdx >= 0 && horzEdge->WindDelta != 0)
      PrepareHorzJoins(horzEdge, isTopOfScanbeam);

    if (horzEdge->NextInLML && IsHorizontal(*horzEdge->NextInLML))
    {
      UpdateEdgeIntoAEL(horzEdge);
      if (horzEdge->OutIdx >= 0) AddOutPt(horzEdge, horzEdge->Bot);
      GetHorzDirection(*horzEdge, dir, horzLeft, horzRight);
    } else
      break;
  } //end for (;;)

  if(horzEdge->NextInLML)
  {
    if(horzEdge->OutIdx >= 0)
    {
      OutPt* op1 = AddOutPt( horzEdge, horzEdge->Top);
      UpdateEdgeIntoAEL(horzEdge);
      if (horzEdge->WindDelta == 0) return;
      //nb: HorzEdge is no longer horizontal here
      TEdge* ePrev = horzEdge->PrevInAEL;
      TEdge* eNext = horzEdge->NextInAEL;
      if (ePrev && ePrev->Curr.X == horzEdge->Bot.X &&
        ePrev->Curr.Y == horzEdge->Bot.Y && ePrev->WindDelta != 0 &&
        (ePrev->OutIdx >= 0 && ePrev->Curr.Y > ePrev->Top.Y &&
        SlopesEqual(*horzEdge, *ePrev, m_UseFullRange)))
      {
        OutPt* op2 = AddOutPt(ePrev, horzEdge->Bot);
        AddJoin(op1, op2, horzEdge->Top);
      }
      else if (eNext && eNext->Curr.X == horzEdge->Bot.X &&
        eNext->Curr.Y == horzEdge->Bot.Y && eNext->WindDelta != 0 &&
        eNext->OutIdx >= 0 && eNext->Curr.Y > eNext->Top.Y &&
        SlopesEqual(*horzEdge, *eNext, m_UseFullRange))
      {
        OutPt* op2 = AddOutPt(eNext, horzEdge->Bot);
        AddJoin(op1, op2, horzEdge->Top);
      }
    }
    else
      UpdateEdgeIntoAEL(horzEdge); 
  }
  else if (eMaxPair)
  {
    if (eMaxPair->OutIdx >= 0)
    {
      if (dir == dLeftToRight)
        IntersectEdges(horzEdge, eMaxPair, horzEdge->Top); 
      else
        IntersectEdges(eMaxPair, horzEdge, horzEdge->Top);
      if (eMaxPair->OutIdx >= 0)
        throw clipperException("ProcessHorizontal error");
    } else
    {
      DeleteFromAEL(horzEdge);
      DeleteFromAEL(eMaxPair);
    }
  } else
  {
    if (horzEdge->OutIdx >= 0) AddOutPt(horzEdge, horzEdge->Top);
    DeleteFromAEL(horzEdge);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x28(%rsp)
movq (%rsi), %rax
movq 0x20(%rsi), %rcx
cmpq %rcx, %rax
setl %r15b
movq %rcx, %rdx
cmovlq %rax, %rdx
movq %rdx, 0x30(%rsp)
cmovgq %rax, %rcx
movq %rcx, 0x38(%rsp)
movq %rsi, %rax
movq %rax, %r12
movq 0x70(%rax), %rax
testq %rax, %rax
je 0xb7df
cmpq $0x0, 0x38(%rax)
je 0xb7c1
movq $0x0, 0x20(%rsp)
jmp 0xb7ec
movq %r12, %rdi
callq 0xbc1c
movq %rax, 0x20(%rsp)
movq %rbx, 0x8(%rsp)
movzbl %bpl, %eax
movl %eax, 0x1c(%rsp)
movl %r15d, %eax
notb %al
movzbl %al, %eax
andl $0x1, %eax
leaq 0x78(,%rax,8), %rcx
movq %rcx, 0x50(%rsp)
movq 0x78(%r14,%rax,8), %r13
leaq 0x20(%r14), %rax
movq %rax, 0x10(%rsp)
testq %r13, %r13
je 0xb912
movq 0x10(%r13), %rax
movq 0x10(%rsp), %rcx
cmpq (%rcx), %rax
jne 0xb850
movq 0x70(%r14), %rcx
testq %rcx, %rcx
je 0xb850
movsd 0x40(%rcx), %xmm0
ucomisd 0x40(%r13), %xmm0
ja 0xb912
movq 0x50(%rsp), %rcx
movq (%r13,%rcx), %rbx
testb $0x1, %r15b
je 0xb86c
cmpq 0x38(%rsp), %rax
jle 0xb877
jmp 0xb912
cmpq 0x30(%rsp), %rax
jl 0xb912
cmpl $0x0, 0x5c(%r14)
js 0xb896
cmpl $0x0, 0x50(%r14)
je 0xb896
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %edx
callq 0xbf1a
cmpq %r12, %r14
jne 0xb8a6
cmpq 0x20(%rsp), %r13
je 0xb99b
testb $0x1, %r15b
je 0xb8ce
movq 0x10(%r13), %rax
movq 0x18(%r14), %rcx
movq %rax, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
jmp 0xb8ee
movq 0x10(%r13), %rax
movq 0x18(%r14), %rcx
movq %rax, 0x40(%rsp)
movq %rcx, 0x48(%rsp)
movq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r14, %rdx
leaq 0x40(%rsp), %rcx
pushq $0x1
popq %r8
callq 0xb21a
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0xbc7a
movq %rbx, %r13
jmp 0xb81f
cmpl $0x0, 0x5c(%r14)
movq 0x8(%rsp), %rbx
js 0xb934
cmpl $0x0, 0x50(%r14)
je 0xb934
movq %rbx, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %edx
callq 0xbf1a
movq 0x70(%r14), %rax
testq %rax, %rax
je 0xb9e3
cmpq $0x0, 0x38(%rax)
jne 0xba13
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0xbf5c
movq 0x28(%rsp), %r14
cmpl $0x0, 0x5c(%r14)
js 0xb973
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0xad78
movq (%r14), %rax
movq 0x20(%r14), %rcx
cmpq %rcx, %rax
setl %r15b
movq %rcx, %rdx
cmovlq %rax, %rdx
movq %rdx, 0x30(%rsp)
cmovgq %rax, %rcx
movq %rcx, 0x38(%rsp)
jmp 0xb7f9
leaq 0x20(%r13), %rcx
testb $0x1, %r15b
je 0xb9b2
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rdx
jmp 0xb9bd
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
callq 0xb21a
movq 0x20(%rsp), %rax
cmpl $0x0, 0x5c(%rax)
jns 0xbbd7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0xbaa8
cmpl $0x0, 0x5c(%rax)
js 0xbb74
movq %rbx, %rdi
testb $0x1, %r15b
je 0xbb9b
movq %r14, %rsi
movq %rax, %rdx
jmp 0xbba1
cmpl $0x0, 0x5c(%r14)
js 0xbb62
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0xad78
movq %rax, %r14
leaq 0x28(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xbf5c
movq (%r15), %r15
cmpl $0x0, 0x50(%r15)
je 0xb9d4
movq 0x78(%r15), %r12
movq 0x80(%r15), %r13
testq %r13, %r13
je 0xbac8
movq 0x10(%r13), %rax
cmpq (%r15), %rax
jne 0xbac8
movq 0x18(%r13), %rax
cmpq 0x8(%r15), %rax
jne 0xbac8
cmpl $0x0, 0x50(%r13)
je 0xbac8
cmpl $0x0, 0x5c(%r13)
js 0xbac8
cmpq 0x28(%r13), %rax
jle 0xbac8
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x7ee7
testb %al, %al
je 0xbac8
movq %rbx, %rdi
movq %r13, %rsi
jmp 0xbb36
cmpl $0x0, 0x5c(%r14)
js 0xbb82
movq %rbx, %rdi
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0xad78
jmp 0xbb82
testq %r12, %r12
je 0xb9d4
movq 0x10(%r12), %rax
cmpq (%r15), %rax
jne 0xb9d4
movq 0x18(%r12), %rax
cmpq 0x8(%r15), %rax
jne 0xb9d4
cmpl $0x0, 0x50(%r12)
je 0xb9d4
cmpl $0x0, 0x5c(%r12)
js 0xb9d4
cmpq 0x28(%r12), %rax
jle 0xb9d4
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x7ee7
testb %al, %al
je 0xb9d4
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xad78
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xae86
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0xbf5c
jmp 0xb9d4
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %r14
callq 0xb5a4
movq %rbx, %rdi
movq %r14, %rsi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb5a4
movq %rax, %rsi
movq %r14, %rdx
movq %rax, %rbx
movq 0x10(%rsp), %rcx
xorl %r8d, %r8d
callq 0xb21a
cmpl $0x0, 0x5c(%rbx)
js 0xb9d4
pushq $0x28
popq %rdi
callq 0x3100
movq %rax, %rbx
leaq 0x7c20(%rip), %rsi      # 0x137ed
movq %rax, %rdi
callq 0xf67a
jmp 0xbbf1
pushq $0x28
popq %rdi
callq 0x3100
movq %rax, %rbx
leaq 0x7c04(%rip), %rsi      # 0x137ed
movq %rax, %rdi
callq 0xf67a
leaq 0xf170(%rip), %rsi      # 0x1ad68
leaq 0x3ab5(%rip), %rdx      # 0xf6b4
movq %rbx, %rdi
callq 0x3390
jmp 0xbc09
movq %rax, %r14
movq %rbx, %rdi
callq 0x3180
movq %r14, %rdi
callq 0x33a0