// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movq 0x8(%rdi,%rcx), %rax
testq %rax, %rax
je 0xb1cf
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x8(%rdi), %r12
addq %rdi, %rcx
addq $0x8, %rcx
leaq 0x70(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x28(%rsp)
movq %r12, 0x20(%rsp)
cmpq %rbx, (%rax)
jne 0xb1cf
movq 0x8(%rax), %r13
movq 0x10(%rax), %rbp
movq 0x18(%rax), %rax
movq %rax, (%rcx)
movq %r14, %rdi
testq %r13, %r13
je 0xaeef
movq %r13, %rsi
xorl %edx, %edx
callq 0xc7ae
movq %r14, %rdi
testq %rbp, %rbp
je 0xaf32
movq %rbp, %rsi
movq %r13, %rdx
callq 0xc7ae
movq %r14, %rdi
movq %r13, %rsi
callq 0xbf46
movl 0x54(%r13), %eax
movl %eax, 0x54(%rbp)
movl 0x58(%r13), %eax
movl %eax, 0x58(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0xc0d6
testb %al, %al
je 0xaf5e
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xc186
jmp 0xaf57
movq %rbp, %rsi
xorl %edx, %edx
callq 0xc7ae
movq %r14, %rdi
movq %rbp, %rsi
callq 0xbf46
movq %r14, %rdi
movq %rbp, %rsi
callq 0xc0d6
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
testb %al, %al
je 0xaf7f
movq %r14, %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0xc328
movq %rax, 0x8(%rsp)
jmp 0xaf7f
movq %r13, %rsi
callq 0xbf46
movq %r14, %rdi
movq %r13, %rsi
callq 0xc0d6
testb %al, %al
je 0xaf5e
movq %r14, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0xc328
movq %rax, 0x8(%rsp)
jmp 0xaf67
movq $0x0, 0x8(%rsp)
movq 0x28(%r13), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd2
testq %rbp, %rbp
je 0xafe4
cmpq $0x0, 0x38(%rbp)
je 0xafa5
movq 0x28(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12fd2
jmp 0xafe4
movq 0xa8(%r14), %rax
testq %rax, %rax
je 0xafd3
movq %rax, 0x88(%rbp)
movq $0x0, 0x90(%rbp)
movq %rbp, 0x90(%rax)
movq %rbp, 0xa8(%r14)
jmp 0xafe4
movq %rbp, 0xa8(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x88(%rbp)
testq %rbp, %rbp
sete %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0xb12b
cmpq $0x0, 0x8(%rsp)
je 0xb00b
cmpq $0x0, 0x38(%rbp)
je 0xb149
cmpl $0x0, 0x5c(%r13)
js 0xb07f
movq 0x80(%r13), %r15
testq %r15, %r15
je 0xb07f
movq 0x10(%r15), %rax
cmpq (%r13), %rax
jne 0xb07f
cmpl $0x0, 0x5c(%r15)
js 0xb07f
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x8cba
testb %al, %al
je 0xb07f
cmpl $0x0, 0x50(%r13)
je 0xb07f
cmpl $0x0, 0x50(%r15)
je 0xb07f
movq %r14, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xc328
movq 0x20(%r13), %rcx
movq 0x28(%r13), %r8
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0xc452
cmpq %rbp, 0x78(%r13)
movq 0x28(%rsp), %rbx
movq 0x20(%rsp), %r12
je 0xb12b
cmpl $0x0, 0x5c(%rbp)
js 0xb0f6
movq 0x80(%rbp), %r15
cmpl $0x0, 0x5c(%r15)
js 0xb0f6
movq (%r14), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r14,%rax), %edx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x8cba
testb %al, %al
je 0xb0f6
cmpl $0x0, 0x50(%rbp)
je 0xb0f6
cmpl $0x0, 0x50(%r15)
je 0xb0f6
movq %r14, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xc328
movq 0x20(%rbp), %rcx
movq 0x28(%rbp), %r8
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0xc452
movq 0x78(%r13), %r15
testq %r15, %r15
sete %al
cmpq %rbp, %r15
sete %cl
orb %al, %cl
jne 0xb12b
addq $0x10, %r13
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xc94e
movq 0x78(%r15), %r15
cmpq %rbp, %r15
jne 0xb10e
movq (%r14), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rcx
movq 0x8(%r14,%rax), %rax
testq %rax, %rax
jne 0xae6f
jmp 0xb1cf
movq 0x40(%r14), %rax
cmpq 0x38(%r14), %rax
je 0xb00b
cmpl $0x0, 0x50(%rbp)
je 0xb00b
movq 0x38(%r14), %rax
cmpq %rax, 0x40(%r14)
je 0xb00b
leaq 0x20(%rbp), %rcx
movq %rcx, 0x30(%rsp)
xorl %r12d, %r12d
movq (%rax,%r12,8), %r15
movq (%r15), %rbx
leaq 0x8(%rbx), %rdi
leaq 0x10(%r15), %rsi
movq %rbp, %rdx
movq 0x30(%rsp), %rcx
callq 0x96cc
testb %al, %al
je 0xb1b3
movq 0x10(%r15), %rcx
movq 0x18(%r15), %r8
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0xc452
incq %r12
movq 0x38(%r14), %rax
movq 0x40(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r12
jb 0xb17b
jmp 0xb00b
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq