// File: /workspace/github_cpp_makefile_star2_O1/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, %r12d
movq %rdi, 0x8(%rsp)
leaq 0x10(%rsp), %rax
movq %rsi, (%rax)
movq (%rsi), %rcx
movq 0x20(%rsi), %rdi
xorl %ebp, %ebp
cmpq %rdi, %rcx
setl %bpl
movq %rdi, %r8
cmovlq %rcx, %r8
cmovgq %rcx, %rdi
movq (%rax), %r15
movq 0x70(%r15), %rcx
testq %rcx, %rcx
je 0xcfa0
leaq 0x70(%r15), %rax
cmpq $0x0, 0x38(%rcx)
je 0xcf7f
testq %rcx, %rcx
je 0xcfa0
xorl %r14d, %r14d
jmp 0xcfb7
movq %rdi, %rbx
movq %r15, %rdi
movq %r8, %r14
callq 0xd577
movq %r14, %r8
movq %rbx, %rdi
movq %rax, %r14
movzbl %r12b, %eax
movl %eax, 0x1c(%rsp)
movq %r15, 0x40(%rsp)
movq 0x10(%rsp), %rcx
xorl %eax, %eax
cmpl $0x1, %ebp
setne %al
leaq 0x78(,%rax,8), %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, 0x48(%rsp)
movq 0x78(%rcx,%rax,8), %r12
movq %rdi, 0x28(%rsp)
movq %r8, 0x20(%rsp)
testq %r12, %r12
je 0xd197
movq 0x10(%r12), %rax
movq 0x10(%rsp), %r13
cmpq 0x20(%r13), %rax
jne 0xd026
movq 0x70(%r13), %rcx
testq %rcx, %rcx
je 0xd026
movsd 0x40(%rcx), %xmm0
ucomisd 0x40(%r12), %xmm0
ja 0xd197
testl %ebp, %ebp
setne %cl
cmpl $0x1, %ebp
setne %dl
movq 0x50(%rsp), %rsi
movq (%r12,%rsi), %rbx
cmpq %rdi, %rax
setg %sil
orb %dl, %sil
cmpq %r8, %rax
setl %dl
cmpb $0x1, %sil
jne 0xd08b
orb %dl, %cl
je 0xd08b
testl %ebp, %ebp
setne %cl
cmpl $0x1, %ebp
setne %dl
cmpq %rdi, %rax
setl %sil
orb %dl, %sil
cmpq %r8, %rax
setg %dl
movl $0x7, %eax
cmpb $0x1, %sil
jne 0xd186
orb %dl, %cl
jne 0xd152
jmp 0xd186
cmpl $0x0, 0x5c(%r13)
js 0xd0aa
cmpl $0x0, 0x50(%r13)
je 0xd0aa
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movl 0x1c(%rsp), %edx
callq 0xd848
cmpq %r15, 0x48(%rsp)
jne 0xd0d4
cmpq %r14, %r12
jne 0xd0d4
leaq 0x20(%r12), %rcx
cmpl $0x1, %ebp
je 0xd159
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
jmp 0xd164
movq %r14, %r15
cmpl $0x1, %ebp
je 0xd0ff
movq 0x10(%r12), %rax
movq 0x18(%r13), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
jmp 0xd120
movq 0x10(%r12), %rax
movq 0x18(%r13), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0x30(%rsp), %rcx
movl $0x1, %r8d
callq 0xc94e
movq 0x10(%rsp), %rsi
movq %r14, %rdi
movq %r12, %rdx
callq 0xd5d8
movq %r15, %r14
movq 0x40(%rsp), %r15
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r8
xorl %eax, %eax
movq %rbx, %r12
jmp 0xd186
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0xc94e
movl $0x1, %eax
cmpl $0x0, 0x5c(%r14)
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r8
jns 0xd512
testl %eax, %eax
je 0xcff2
cmpl $0x7, %eax
jne 0xd229
movq 0x10(%rsp), %r12
cmpl $0x0, 0x5c(%r12)
js 0xd1c7
cmpl $0x0, 0x50(%r12)
je 0xd1c7
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movl 0x1c(%rsp), %edx
callq 0xd848
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %rdi
movq 0x70(%r12), %rcx
movl $0x4, %eax
testq %rcx, %rcx
je 0xd229
cmpq $0x0, 0x38(%rcx)
jne 0xd229
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10(%rsp), %rsi
callq 0xd894
movq 0x10(%rsp), %r12
cmpl $0x0, 0x5c(%r12)
js 0xd20a
movq %rbx, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xc328
movq (%r12), %rax
movq 0x20(%r12), %rdi
xorl %ebp, %ebp
cmpq %rdi, %rax
movq %rdi, %r8
cmovlq %rax, %r8
setl %bpl
cmovgq %rax, %rdi
xorl %eax, %eax
testl %eax, %eax
je 0xcfc4
cmpl $0x4, %eax
jne 0xd503
movq 0x10(%rsp), %r15
cmpq $0x0, 0x70(%r15)
je 0xd2f5
cmpl $0x0, 0x5c(%r15)
js 0xd3ca
leaq 0x20(%r15), %rdx
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xc328
movq %rax, %r14
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0xd894
movq (%r15), %r15
cmpl $0x0, 0x50(%r15)
je 0xd503
movq 0x78(%r15), %r12
movq 0x80(%r15), %r13
testq %r13, %r13
je 0xd326
movq 0x10(%r13), %rax
cmpq (%r15), %rax
jne 0xd326
movq 0x18(%r13), %rax
cmpq 0x8(%r15), %rax
jne 0xd326
cmpl $0x0, 0x50(%r13)
je 0xd326
cmpl $0x0, 0x5c(%r13)
js 0xd326
cmpq 0x28(%r13), %rax
jle 0xd326
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rcx,%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x8cba
testb %al, %al
je 0xd326
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
jmp 0xd39e
testq %r14, %r14
je 0xd3de
cmpl $0x0, 0x5c(%r14)
js 0xd455
leaq 0x20(%r15), %rcx
cmpl $0x1, %ebp
jne 0xd4e9
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r14, %rdx
jmp 0xd4f4
testq %r12, %r12
je 0xd503
movq 0x10(%r12), %rax
cmpq (%r15), %rax
jne 0xd503
movq 0x18(%r12), %rax
cmpq 0x8(%r15), %rax
jne 0xd503
cmpl $0x0, 0x50(%r12)
je 0xd503
cmpl $0x0, 0x5c(%r12)
js 0xd503
cmpq 0x28(%r12), %rax
jle 0xd503
movq 0x8(%rsp), %rcx
movq (%rcx), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%rcx,%rax), %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x8cba
testb %al, %al
je 0xd503
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0xc328
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 0xc452
leaq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdi
callq 0xd894
jmp 0xd503
cmpl $0x0, 0x5c(%r15)
js 0xd3f6
leaq 0x20(%r15), %rdx
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xc328
movq 0x78(%r15), %rax
movq 0x80(%r15), %rcx
testq %rcx, %rcx
jne 0xd41d
testq %rax, %rax
jne 0xd41d
movq 0x8(%rsp), %rdx
cmpq %r15, 0xa0(%rdx)
jne 0xd503
addq $0x78, %r15
movq 0x8(%rsp), %rsi
addq $0xa0, %rsi
leaq 0x78(%rcx), %rdx
testq %rcx, %rcx
cmoveq %rsi, %rdx
movq %rax, (%rdx)
testq %rax, %rax
je 0xd447
movq %rcx, 0x80(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
jmp 0xd503
movq 0x78(%r15), %rcx
movq 0x80(%r15), %rdx
movq 0x8(%rsp), %rsi
leaq 0xa0(%rsi), %rax
testq %rdx, %rdx
jne 0xd47f
testq %rcx, %rcx
jne 0xd47f
cmpq %r15, 0xa0(%rsi)
jne 0xd4a6
addq $0x78, %r15
leaq 0x78(%rdx), %rsi
testq %rdx, %rdx
cmoveq %rax, %rsi
movq %rcx, (%rsi)
testq %rcx, %rcx
je 0xd49d
movq %rdx, 0x80(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq 0x78(%r14), %rcx
movq 0x80(%r14), %rdx
testq %rdx, %rdx
jne 0xd4c0
testq %rcx, %rcx
jne 0xd4c0
cmpq %r14, (%rax)
jne 0xd503
addq $0x78, %r14
leaq 0x78(%rdx), %rsi
testq %rdx, %rdx
cmovneq %rsi, %rax
movq %rcx, (%rax)
testq %rcx, %rcx
je 0xd4de
movq %rdx, 0x80(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r14)
jmp 0xd503
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0xc94e
cmpl $0x0, 0x5c(%r14)
jns 0xd544
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x30f0
movq %rax, %rbx
leaq 0x8257(%rip), %rsi      # 0x1577d
movq %rax, %rdi
callq 0x1225c
leaq 0xe833(%rip), %rsi      # 0x1bd68
leaq 0x4d5a(%rip), %rdx      # 0x12296
movq %rbx, %rdi
callq 0x3370
movl $0x28, %edi
callq 0x30f0
movq %rax, %rbx
leaq 0x8225(%rip), %rsi      # 0x1577d
movq %rax, %rdi
callq 0x1225c
jmp 0xd52e
jmp 0xd564
movq %rax, %r14
movq %rbx, %rdi
callq 0x3170
movq %r14, %rdi
callq 0x3380