// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::InsertLocalMinimaIntoAEL(long long)
void Clipper::InsertLocalMinimaIntoAEL(const cInt botY)
{
  while(  m_CurrentLM  && ( m_CurrentLM->Y == botY ) )
  {
    TEdge* lb = m_CurrentLM->LeftBound;
    TEdge* rb = m_CurrentLM->RightBound;
    PopLocalMinima();
    OutPt *Op1 = 0;
    if (!lb)
    {
      //nb: don't insert LB into either AEL or SEL
      InsertEdgeIntoAEL(rb, 0);
      SetWindingCount(*rb);
      if (IsContributing(*rb))
        Op1 = AddOutPt(rb, rb->Bot); 
    } 
    else if (!rb)
    {
      InsertEdgeIntoAEL(lb, 0);
      SetWindingCount(*lb);
      if (IsContributing(*lb))
        Op1 = AddOutPt(lb, lb->Bot);
      InsertScanbeam(lb->Top.Y);
    }
    else
    {
      InsertEdgeIntoAEL(lb, 0);
      InsertEdgeIntoAEL(rb, lb);
      SetWindingCount( *lb );
      rb->WindCnt = lb->WindCnt;
      rb->WindCnt2 = lb->WindCnt2;
      if (IsContributing(*lb))
        Op1 = AddLocalMinPoly(lb, rb, lb->Bot);      
      InsertScanbeam(lb->Top.Y);
    }

     if (rb)
     {
       if(IsHorizontal(*rb)) AddEdgeToSEL(rb);
       else InsertScanbeam( rb->Top.Y );
     }

    if (!lb || !rb) continue;

    //if any output polygons share an edge, they'll need joining later ...
    if (Op1 && IsHorizontal(*rb) && 
      m_GhostJoins.size() > 0 && (rb->WindDelta != 0))
    {
      for (JoinList::size_type i = 0; i < m_GhostJoins.size(); ++i)
      {
        Join* jr = m_GhostJoins[i];
        //if the horizontal Rb and a 'ghost' horizontal overlap, then convert
        //the 'ghost' join to a real join ready for later ...
        if (HorzSegmentsOverlap(jr->OutPt1->Pt, jr->OffPt, rb->Bot, rb->Top))
          AddJoin(jr->OutPt1, Op1, jr->OffPt);
      }
    }

    if (lb->OutIdx >= 0 && lb->PrevInAEL && 
      lb->PrevInAEL->Curr.X == lb->Bot.X &&
      lb->PrevInAEL->OutIdx >= 0 &&
      SlopesEqual(*lb->PrevInAEL, *lb, m_UseFullRange) &&
      (lb->WindDelta != 0) && (lb->PrevInAEL->WindDelta != 0))
    {
        OutPt *Op2 = AddOutPt(lb->PrevInAEL, lb->Bot);
        AddJoin(Op1, Op2, lb->Top);
    }

    if(lb->NextInAEL != rb)
    {

      if (rb->OutIdx >= 0 && rb->PrevInAEL->OutIdx >= 0 &&
        SlopesEqual(*rb->PrevInAEL, *rb, m_UseFullRange) &&
        (rb->WindDelta != 0) && (rb->PrevInAEL->WindDelta != 0))
      {
          OutPt *Op2 = AddOutPt(rb->PrevInAEL, rb->Bot);
          AddJoin(Op1, Op2, rb->Top);
      }

      TEdge* e = lb->NextInAEL;
      if (e)
      {
        while( e != rb )
        {
          //nb: For calculating winding counts etc, IntersectEdges() assumes
          //that param1 will be to the Right of param2 ABOVE the intersection ...
          IntersectEdges(rb , e , lb->Curr); //order important here
          e = e->NextInAEL;
        }
      }
    }
    
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %r14
movq %rsi, 0x10(%rsp)
movq (%r14), %rax
movq -0x18(%rax), %rax
movq 0x8(%r14,%rax), %rcx
testq %rcx, %rcx
je 0x9fc2
cmpq %r15, (%rcx)
jne 0x9fc2
movq 0x8(%rcx), %rbx
movq 0x10(%rcx), %r12
movq 0x18(%rcx), %rcx
movq %rcx, 0x8(%r14,%rax)
movq %r14, %rdi
testq %rbx, %rbx
je 0x9d1c
movq %rbx, %rsi
xorl %edx, %edx
callq 0xb184
movq %r14, %rdi
testq %r12, %r12
je 0x9d65
movq %r12, %rsi
movq %rbx, %rdx
callq 0xb184
movq %r14, %rdi
movq %rbx, %rsi
callq 0xaa10
movq 0x54(%rbx), %rax
movq %rax, 0x54(%r12)
movq %r14, %rdi
movq %rbx, %rsi
callq 0xab7e
testb %al, %al
je 0x9d9b
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0xac3e
movq %rax, (%rsp)
jmp 0x9da3
movq %r12, %rsi
xorl %edx, %edx
callq 0xb184
movq %r14, %rdi
movq %r12, %rsi
callq 0xaa10
movq %r14, %rdi
movq %r12, %rsi
callq 0xab7e
movl $0x0, %ecx
movq %rcx, (%rsp)
testb %al, %al
je 0x9d5b
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xad78
movq %rax, (%rsp)
testq %r12, %r12
jne 0x9daf
jmp 0x9c83
movq %rbx, %rsi
callq 0xaa10
movq %r14, %rdi
movq %rbx, %rsi
callq 0xab7e
testb %al, %al
je 0x9d8a
movq %r14, %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0xad78
movq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x96c6
jmp 0x9c83
movq $0x0, (%rsp)
movq 0x28(%rbx), %rsi
movq %r14, %rdi
callq 0x96c6
cmpq $0x0, 0x38(%r12)
je 0x9dc6
movq 0x28(%r12), %rsi
movq %r14, %rdi
callq 0x96c6
jmp 0x9df1
movq 0xa8(%r14), %rax
andq $0x0, 0x90(%r12)
testq %rax, %rax
je 0x9de2
movq %r12, 0x90(%rax)
movq %r12, 0xa8(%r14)
movq %rax, 0x88(%r12)
testq %rbx, %rbx
je 0x9c83
movq %rbx, 0x18(%rsp)
cmpq $0x0, (%rsp)
je 0x9e12
cmpq $0x0, 0x38(%r12)
je 0x9f35
movq 0x18(%rsp), %r13
cmpl $0x0, 0x5c(%r13)
js 0x9e88
movq 0x80(%r13), %rbp
testq %rbp, %rbp
je 0x9e88
movq 0x10(%rbp), %rax
cmpq (%r13), %rax
jne 0x9e88
cmpl $0x0, 0x5c(%rbp)
js 0x9e88
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %rbp, %rdi
movq %r13, %rsi
callq 0x7ee7
testb %al, %al
je 0x9e88
cmpl $0x0, 0x50(%r13)
je 0x9e88
cmpl $0x0, 0x50(%rbp)
je 0x9e88
movq %r14, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xad78
movq 0x20(%r13), %rcx
movq 0x28(%r13), %r8
movq %r14, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
callq 0xae86
movq 0x78(%r13), %rbp
cmpq %r12, %rbp
movq 0x10(%rsp), %r15
je 0x9c83
cmpl $0x0, 0x5c(%r12)
js 0x9f05
movq 0x80(%r12), %rbx
cmpl $0x0, 0x5c(%rbx)
js 0x9f05
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7ee7
testb %al, %al
je 0x9f05
cmpl $0x0, 0x50(%r12)
je 0x9f05
cmpl $0x0, 0x50(%rbx)
je 0x9f05
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xad78
movq 0x20(%r12), %rcx
movq 0x28(%r12), %r8
movq %r14, %rdi
movq (%rsp), %rsi
movq %rax, %rdx
callq 0xae86
movq 0x78(%r13), %rbp
testq %rbp, %rbp
je 0x9c83
addq $0x10, %r13
cmpq %r12, %rbp
je 0x9c83
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xb21a
movq 0x78(%rbp), %rbp
jmp 0x9f12
movq 0x38(%r14), %r13
movq 0x40(%r14), %rax
movq %rax, 0x8(%rsp)
cmpq %r13, %rax
je 0x9e12
cmpl $0x0, 0x50(%r12)
je 0x9e12
leaq 0x20(%r12), %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
subq %r13, %rax
sarq $0x3, %rax
cmpq %rax, %rbp
jae 0x9e12
movq (%r13,%rbp,8), %r15
movq (%r15), %rbx
leaq 0x8(%rbx), %rdi
leaq 0x10(%r15), %rsi
movq %r12, %rdx
movq 0x20(%rsp), %rcx
callq 0x8873
testb %al, %al
je 0x9fbd
movq 0x10(%r15), %rcx
movq 0x18(%r15), %r8
movq %r14, %rdi
movq %rbx, %rsi
movq (%rsp), %rdx
callq 0xae86
movq 0x38(%r14), %r13
movq 0x40(%r14), %rax
movq %rax, 0x8(%rsp)
incq %rbp
jmp 0x9f63
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop