// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movq 0x8(%rdi,%rcx), %rax
testq %rax, %rax
je 0xaedb
movq %rsi, %r14
movq %rdi, %r12
leaq 0x8(%rdi), %rdx
movq %rdx, 0x38(%rsp)
addq %rdi, %rcx
addq $0x8, %rcx
leaq 0x70(%rdi), %rdx
movq %rdx, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x20(%rsp)
cmpq %r14, (%rax)
jne 0xaedb
movq 0x8(%rax), %r13
movq 0x10(%rax), %rbp
movq 0x18(%rax), %rax
movq %rax, (%rcx)
movq %r12, %rdi
testq %r13, %r13
je 0xabee
movq %r13, %rsi
xorl %edx, %edx
callq 0xc3f2
movq %r12, %rdi
testq %rbp, %rbp
je 0xac39
movq %rbp, %rsi
movq %r13, %rdx
callq 0xc3f2
movq %r12, %rdi
movq %r13, %rsi
callq 0xbbc6
movq 0x54(%r13), %rax
movq %rax, 0x54(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xbd4c
testb %al, %al
je 0xac7b
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0xbe0c
movq %rax, 0x8(%rsp)
jmp 0xac84
movq %rbp, %rsi
xorl %edx, %edx
callq 0xc3f2
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbbc6
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbd4c
movl $0x0, %ecx
movq %rcx, 0x8(%rsp)
testb %al, %al
je 0xac2f
movq %r12, %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0xbfae
movq %rax, 0x8(%rsp)
testq %rbp, %rbp
jne 0xac9c
jmp 0xae24
movq %r13, %rsi
callq 0xbbc6
movq %r12, %rdi
movq %r13, %rsi
callq 0xbd4c
testb %al, %al
je 0xac5e
movq %r12, %rdi
movq %r13, %rsi
movq %r13, %rdx
callq 0xbfae
movq 0x28(%r13), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12a16
jmp 0xae24
movq $0x0, 0x8(%rsp)
movq 0x28(%r13), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12a16
cmpq $0x0, 0x38(%rbp)
je 0xacbd
movq 0x28(%rbp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x12a16
jmp 0xaceb
movq 0xa8(%r12), %rax
movq $0x0, 0x90(%rbp)
testq %rax, %rax
je 0xacdc
movq %rbp, 0x90(%rax)
movq %rbp, 0xa8(%r12)
movq %rax, 0x88(%rbp)
testq %r13, %r13
je 0xae24
cmpq $0x0, 0x8(%rsp)
je 0xad07
cmpq $0x0, 0x38(%rbp)
je 0xae47
cmpl $0x0, 0x5c(%r13)
movq 0x20(%rsp), %r12
js 0xad81
movq 0x80(%r13), %r15
testq %r15, %r15
je 0xad81
movq 0x10(%r15), %rax
cmpq (%r13), %rax
jne 0xad81
cmpl $0x0, 0x5c(%r15)
js 0xad81
movq (%r12), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r12,%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x8991
testb %al, %al
je 0xad81
cmpl $0x0, 0x50(%r13)
je 0xad81
cmpl $0x0, 0x50(%r15)
je 0xad81
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0xbfae
movq 0x20(%r13), %rcx
movq 0x28(%r13), %r8
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0xc0c0
movq 0x78(%r13), %r15
cmpq %rbp, %r15
movq 0x30(%rsp), %r14
je 0xae24
cmpl $0x0, 0x5c(%rbp)
js 0xadf9
movq 0x80(%rbp), %rbx
cmpl $0x0, 0x5c(%rbx)
js 0xadf9
movq (%r12), %rax
movq -0x18(%rax), %rax
movzbl 0x18(%r12,%rax), %edx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x8991
testb %al, %al
je 0xadf9
cmpl $0x0, 0x50(%rbp)
je 0xadf9
cmpl $0x0, 0x50(%rbx)
je 0xadf9
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0xbfae
movq 0x20(%rbp), %rcx
movq 0x28(%rbp), %r8
movq %r12, %rdi
movq 0x8(%rsp), %rsi
movq %rax, %rdx
callq 0xc0c0
movq 0x78(%r13), %r15
testq %r15, %r15
je 0xae24
cmpq %rbp, %r15
je 0xae24
addq $0x10, %r13
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xc5a2
movq 0x78(%r15), %r15
cmpq %rbp, %r15
jne 0xae07
movq (%r12), %rax
movq -0x18(%rax), %rax
movq 0x38(%rsp), %rcx
addq %rax, %rcx
movq 0x8(%r12,%rax), %rax
testq %rax, %rax
jne 0xab6c
jmp 0xaedb
movq 0x20(%rsp), %rax
movq 0x38(%rax), %r12
movq 0x40(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq %r12, %rax
je 0xad07
cmpl $0x0, 0x50(%rbp)
je 0xad07
leaq 0x20(%rbp), %rax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
movq (%r12,%r15,8), %r14
movq (%r14), %rbx
leaq 0x8(%rbx), %rdi
leaq 0x10(%r14), %rsi
movq %rbp, %rdx
movq 0x40(%rsp), %rcx
callq 0x93ab
testb %al, %al
je 0xaec2
movq 0x10(%r14), %rcx
movq 0x18(%r14), %r8
movq 0x20(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0xc0c0
movq 0x38(%r14), %r12
movq 0x40(%r14), %rax
movq %rax, 0x28(%rsp)
incq %r15
movq 0x28(%rsp), %rax
subq %r12, %rax
sarq $0x3, %rax
cmpq %rax, %r15
jb 0xae78
jmp 0xad07
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq