// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movl %edx, %r15d
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, 0x18(%rsp)
movq (%rsi), %rax
movq 0x20(%rsi), %rcx
cmpq %rcx, %rax
setl %bpl
movq %rcx, %rdx
cmovlq %rax, %rdx
movq %rdx, 0x20(%rsp)
cmovgq %rax, %rcx
movq %rcx, 0x28(%rsp)
movq %rsi, %rax
movq %rax, %r12
movq 0x70(%rax), %rax
testq %rax, %rax
je 0xcc15
cmpq $0x0, 0x38(%rax)
je 0xcbf8
movq $0x0, (%rsp)
jmp 0xcc21
movq %r12, %rdi
callq 0xd138
movq %rax, (%rsp)
movq %rbx, 0x8(%rsp)
movzbl %r15b, %eax
movl %eax, 0x14(%rsp)
movl %ebp, %eax
notb %al
movzbl %al, %eax
andl $0x1, %eax
movq 0x78(%r14,%rax,8), %r15
testq %r15, %r15
je 0xcd3d
leaq 0x78(,%rax,8), %rax
movq %rax, 0x40(%rsp)
movq 0x10(%r15), %rax
cmpq 0x20(%r14), %rax
jne 0xcc77
movq 0x70(%r14), %rcx
testq %rcx, %rcx
je 0xcc77
movsd 0x40(%rcx), %xmm0
ucomisd 0x40(%r15), %xmm0
ja 0xcd3d
movq 0x40(%rsp), %rcx
movq (%r15,%rcx), %r13
testb $0x1, %bpl
je 0xcc92
cmpq 0x28(%rsp), %rax
jle 0xcc9d
jmp 0xcd3d
cmpq 0x20(%rsp), %rax
jl 0xcd3d
cmpl $0x0, 0x5c(%r14)
js 0xccbc
cmpl $0x0, 0x50(%r14)
je 0xccbc
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movl 0x14(%rsp), %edx
callq 0xd438
cmpq %r12, %r14
jne 0xcccb
cmpq (%rsp), %r15
je 0xcdc6
testb $0x1, %bpl
je 0xccf3
movq 0x10(%r15), %rax
movq 0x18(%r14), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0xcd13
movq 0x10(%r15), %rax
movq 0x18(%r14), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
leaq 0x30(%rsp), %rcx
movl $0x1, %r8d
callq 0xc5a2
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xd196
movq %r13, %r15
testq %r13, %r13
jne 0xcc53
cmpl $0x0, 0x5c(%r14)
movq 0x8(%rsp), %rbx
js 0xcd5f
cmpl $0x0, 0x50(%r14)
je 0xcd5f
movq %rbx, %rdi
movq %r14, %rsi
movl 0x14(%rsp), %edx
callq 0xd438
movq 0x70(%r14), %rax
testq %rax, %rax
je 0xce0d
cmpq $0x0, 0x38(%rax)
jne 0xce44
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0xd47a
movq 0x18(%rsp), %r14
cmpl $0x0, 0x5c(%r14)
js 0xcd9e
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0xbfae
movq (%r14), %rax
movq 0x20(%r14), %rcx
cmpq %rcx, %rax
setl %bpl
movq %rcx, %rdx
cmovlq %rax, %rdx
movq %rdx, 0x20(%rsp)
cmovgq %rax, %rcx
movq %rcx, 0x28(%rsp)
jmp 0xcc2e
leaq 0x20(%r15), %rcx
testb $0x1, %bpl
je 0xcddd
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
jmp 0xcde8
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
callq 0xc5a2
movq (%rsp), %rax
cmpl $0x0, 0x5c(%rax)
jns 0xd0f1
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %rax
testq %rax, %rax
je 0xcef0
cmpl $0x0, 0x5c(%rax)
js 0xd007
leaq 0x20(%r14), %rcx
movq %rbx, %rdi
testb $0x1, %bpl
je 0xd0b7
movq %r14, %rsi
movq (%rsp), %rbx
movq %rbx, %rdx
jmp 0xd0c1
cmpl $0x0, 0x5c(%r14)
js 0xcff5
leaq 0x20(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbfae
movq %rax, %r14
leaq 0x18(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd47a
movq (%r15), %r15
cmpl $0x0, 0x50(%r15)
je 0xcdfe
movq 0x78(%r15), %r12
movq 0x80(%r15), %r13
testq %r13, %r13
je 0xcf5b
movq 0x10(%r13), %rax
cmpq (%r15), %rax
jne 0xcf5b
movq 0x18(%r13), %rax
cmpq 0x8(%r15), %rax
jne 0xcf5b
cmpl $0x0, 0x50(%r13)
je 0xcf5b
cmpl $0x0, 0x5c(%r13)
js 0xcf5b
cmpq 0x28(%r13), %rax
jle 0xcf5b
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x8991
testb %al, %al
je 0xcf5b
movq %rbx, %rdi
movq %r13, %rsi
jmp 0xcfc9
cmpl $0x0, 0x5c(%r14)
js 0xcf06
leaq 0x20(%r14), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0xbfae
movq 0x78(%r14), %rax
movq 0x80(%r14), %rcx
testq %rcx, %rcx
jne 0xcf28
testq %rax, %rax
jne 0xcf28
cmpq %r14, 0xa0(%rbx)
jne 0xcdfe
addq $0x78, %r14
addq $0xa0, %rbx
leaq 0x78(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rbx, %rdx
movq %rax, (%rdx)
testq %rax, %rax
je 0xcf4d
movq %rcx, 0x80(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
jmp 0xcdfe
testq %r12, %r12
je 0xcdfe
movq 0x10(%r12), %rax
cmpq (%r15), %rax
jne 0xcdfe
movq 0x18(%r12), %rax
cmpq 0x8(%r15), %rax
jne 0xcdfe
cmpl $0x0, 0x50(%r12)
je 0xcdfe
cmpl $0x0, 0x5c(%r12)
js 0xcdfe
cmpq 0x28(%r12), %rax
jle 0xcdfe
movq (%rbx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rbx,%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x8991
testb %al, %al
je 0xcdfe
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xbfae
movq 0x20(%r15), %rcx
movq 0x28(%r15), %r8
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc0c0
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0xd47a
jmp 0xcdfe
movq 0x78(%r14), %rax
movq 0x80(%r14), %rcx
movq %rcx, %rdx
orq %rax, %rdx
setne %sil
movq 0xa0(%rbx), %rdx
addq $0xa0, %rbx
cmpq %r14, %rdx
sete %dil
orb %sil, %dil
cmpb $0x1, %dil
jne 0xd064
addq $0x78, %r14
leaq 0x78(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rbx, %rdx
movq %rax, (%rdx)
testq %rax, %rax
je 0xd058
movq %rcx, 0x80(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
movq (%rbx), %rdx
movq (%rsp), %rcx
movq 0x78(%rcx), %rax
movq 0x80(%rcx), %rcx
testq %rcx, %rcx
jne 0xd087
testq %rax, %rax
jne 0xd087
cmpq (%rsp), %rdx
jne 0xcdfe
addq $0x78, (%rsp)
leaq 0x78(%rcx), %rdx
testq %rcx, %rcx
cmovneq %rdx, %rbx
movq %rax, (%rbx)
testq %rax, %rax
je 0xd0a6
movq %rcx, 0x80(%rax)
xorpd %xmm0, %xmm0
movq (%rsp), %rax
movupd %xmm0, (%rax)
jmp 0xcdfe
movq (%rsp), %rbx
movq %rbx, %rsi
movq %r14, %rdx
xorl %r8d, %r8d
callq 0xc5a2
cmpl $0x0, 0x5c(%rbx)
js 0xcdfe
movl $0x28, %edi
callq 0x30f0
movq %rax, %rbx
leaq 0x8706(%rip), %rsi      # 0x157ed
movq %rax, %rdi
callq 0x11cba
jmp 0xd10d
movl $0x28, %edi
callq 0x30f0
movq %rax, %rbx
leaq 0x86e8(%rip), %rsi      # 0x157ed
movq %rax, %rdi
callq 0x11cba
leaq 0xec54(%rip), %rsi      # 0x1bd68
leaq 0x4bd9(%rip), %rdx      # 0x11cf4
movq %rbx, %rdi
callq 0x3370
jmp 0xd125
movq %rax, %r14
movq %rbx, %rdi
callq 0x3170
movq %r14, %rdi
callq 0x3380