// File: /workspace/github_cpp_makefile_star2_O1/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::ClipperBase::ProcessBound(ClipperLib::TEdge*, bool)
TEdge* ClipperBase::ProcessBound(TEdge* E, bool IsClockwise)
{
  TEdge *EStart = E, *Result = E;
  TEdge *Horz = 0;
  cInt StartX;
  if (IsHorizontal(*E))
  {
    //it's possible for adjacent overlapping horz edges to start heading left
    //before finishing right, so ...
    if (IsClockwise) StartX = E->Prev->Bot.X;
    else StartX = E->Next->Bot.X;
    if (E->Bot.X != StartX) ReverseHorizontal(*E);
  }
  
  if (Result->OutIdx != Skip)
  {
    if (IsClockwise)
    {
      while (Result->Top.Y == Result->Next->Bot.Y && Result->Next->OutIdx != Skip)
        Result = Result->Next;
      if (IsHorizontal(*Result) && Result->Next->OutIdx != Skip)
      {
        //nb: at the top of a bound, horizontals are added to the bound
        //only when the preceding edge attaches to the horizontal's left vertex
        //unless a Skip edge is encountered when that becomes the top divide
        Horz = Result;
        while (IsHorizontal(*Horz->Prev)) Horz = Horz->Prev;
        if (Horz->Prev->Top.X == Result->Next->Top.X) 
        {
          if (!IsClockwise) Result = Horz->Prev;
        }
        else if (Horz->Prev->Top.X > Result->Next->Top.X) Result = Horz->Prev;
      }
      while (E != Result) 
      {
        E->NextInLML = E->Next;
        if (IsHorizontal(*E) && E != EStart &&
          E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E);
        E = E->Next;
      }
      if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Prev->Top.X) 
        ReverseHorizontal(*E);
      Result = Result->Next; //move to the edge just beyond current bound
    } else
    {
      while (Result->Top.Y == Result->Prev->Bot.Y && Result->Prev->OutIdx != Skip) 
        Result = Result->Prev;
      if (IsHorizontal(*Result) && Result->Prev->OutIdx != Skip)
      {
        Horz = Result;
        while (IsHorizontal(*Horz->Next)) Horz = Horz->Next;
        if (Horz->Next->Top.X == Result->Prev->Top.X) 
        {
          if (!IsClockwise) Result = Horz->Next;
        }
        else if (Horz->Next->Top.X > Result->Prev->Top.X) Result = Horz->Next;
      }

      while (E != Result)
      {
        E->NextInLML = E->Prev;
        if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) 
          ReverseHorizontal(*E);
        E = E->Prev;
      }
      if (IsHorizontal(*E) && E != EStart && E->Bot.X != E->Next->Top.X) 
        ReverseHorizontal(*E);
      Result = Result->Prev; //move to the edge just beyond current bound
    }
  }

  if (Result->OutIdx == Skip) 
  {
    //if edges still remain in the current bound beyond the skip edge then
    //create another LocMin and call ProcessBound once more
    E = Result;
    if (IsClockwise)
    {
      while (E->Top.Y == E->Next->Bot.Y) E = E->Next;
      //don't include top horizontals when parsing a bound a second time,
      //they will be contained in the opposite bound ...
      while (E != Result && IsHorizontal(*E)) E = E->Prev;
    } else
    {
      while (E->Top.Y == E->Prev->Bot.Y) E = E->Prev;
      while (E != Result && IsHorizontal(*E)) E = E->Next;
    }
    if (E == Result)
    {
      if (IsClockwise) Result = E->Next;
      else Result = E->Prev;
    } else
    {
      //there are more edges in the bound beyond result starting with E
      if (IsClockwise)
        E = Result->Next; 
      else
        E = Result->Prev;
      LocalMinima* locMin = new LocalMinima;
      locMin->Next = 0;
      locMin->Y = E->Bot.Y;
      locMin->LeftBound = 0;
      locMin->RightBound = E;
      locMin->RightBound->WindDelta = 0;
      Result = ProcessBound(locMin->RightBound, IsClockwise);
      InsertLocalMinima(locMin);
    }
  }
  return Result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rdi, %rbx
cmpq $0x0, 0x38(%rsi)
jne 0x98f5
movzbl %bpl, %eax
movq 0x60(%rsi,%rax,8), %rcx
movq (%rsi), %rax
cmpq (%rcx), %rax
je 0x98f5
movq 0x20(%rsi), %rcx
movq %rax, 0x20(%rsi)
movq %rcx, (%rsi)
cmpl $-0x2, 0x5c(%rsi)
je 0x9a6e
movq %rsi, %rcx
testb %bpl, %bpl
je 0x99b9
movq %rcx, %rax
movq 0x28(%rcx), %rdx
movq 0x60(%rcx), %rcx
cmpq 0x8(%rcx), %rdx
jne 0x9922
cmpl $-0x2, 0x5c(%rcx)
jne 0x990b
cmpq $0x0, 0x38(%rax)
jne 0x994b
cmpl $-0x2, 0x5c(%rcx)
je 0x994b
movq %rax, %rdx
movq 0x68(%rdx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x9932
movq 0x20(%rcx), %rcx
cmpq %rcx, 0x20(%rdx)
je 0x994b
cmovgq %rdx, %rax
movq %rsi, %rcx
cmpq %rsi, %rax
je 0x998c
movq %rsi, %rcx
movq %rcx, %rdx
movq 0x38(%rcx), %rdi
movq 0x60(%rcx), %rcx
movq %rcx, 0x70(%rdx)
cmpq %rsi, %rdx
je 0x9987
testq %rdi, %rdi
jne 0x9987
movq (%rdx), %rdi
movq 0x68(%rdx), %r8
cmpq 0x20(%r8), %rdi
je 0x9987
movq 0x20(%rdx), %r8
movq %rdi, 0x20(%rdx)
movq %r8, (%rdx)
cmpq %rax, %rcx
jne 0x9956
cmpq %rsi, %rcx
je 0x99b0
cmpq $0x0, 0x38(%rcx)
jne 0x99b0
movq (%rcx), %rdx
movq 0x68(%rcx), %rsi
cmpq 0x20(%rsi), %rdx
je 0x99b0
movq 0x20(%rcx), %rsi
movq %rdx, 0x20(%rcx)
movq %rsi, (%rcx)
addq $0x60, %rax
jmp 0x9a6b
movq %rcx, %rax
movq 0x28(%rcx), %rdx
movq 0x68(%rcx), %rcx
cmpq 0x8(%rcx), %rdx
jne 0x99d0
cmpl $-0x2, 0x5c(%rcx)
jne 0x99b9
cmpq $0x0, 0x38(%rax)
jne 0x9a02
cmpl $-0x2, 0x5c(%rcx)
je 0x9a02
movq %rax, %rdx
movq 0x60(%rdx), %rdx
cmpq $0x0, 0x38(%rdx)
je 0x99e0
movq 0x20(%rcx), %rcx
cmpq %rcx, 0x20(%rdx)
jne 0x99fe
testb %bpl, %bpl
cmoveq %rdx, %rax
jmp 0x9a02
cmovgq %rdx, %rax
movq %rsi, %rcx
cmpq %rsi, %rax
je 0x9a43
movq %rsi, %rcx
movq %rcx, %rdx
movq 0x38(%rcx), %rdi
movq 0x68(%rcx), %rcx
movq %rcx, 0x70(%rdx)
cmpq %rsi, %rdx
je 0x9a3e
testq %rdi, %rdi
jne 0x9a3e
movq (%rdx), %rdi
movq 0x60(%rdx), %r8
cmpq 0x20(%r8), %rdi
je 0x9a3e
movq 0x20(%rdx), %r8
movq %rdi, 0x20(%rdx)
movq %r8, (%rdx)
cmpq %rax, %rcx
jne 0x9a0d
cmpq %rsi, %rcx
je 0x9a67
cmpq $0x0, 0x38(%rcx)
jne 0x9a67
movq (%rcx), %rdx
movq 0x60(%rcx), %rsi
cmpq 0x20(%rsi), %rdx
je 0x9a67
movq 0x20(%rcx), %rsi
movq %rdx, 0x20(%rcx)
movq %rsi, (%rcx)
addq $0x68, %rax
movq (%rax), %rsi
cmpl $-0x2, 0x5c(%rsi)
jne 0x9b34
movq %rsi, %rcx
testb %bpl, %bpl
je 0x9a93
movq %rcx, %rax
movq 0x28(%rcx), %rdx
movq 0x60(%rcx), %rcx
cmpq 0x8(%rcx), %rdx
je 0x9a80
jmp 0x9ab1
movq %rcx, %rax
movq 0x28(%rcx), %rdx
movq 0x68(%rcx), %rcx
cmpq 0x8(%rcx), %rdx
je 0x9a93
jmp 0x9ac3
cmpq $0x0, 0x38(%rax)
jne 0x9ac8
movq 0x68(%rax), %rax
cmpq %rsi, %rax
jne 0x9aa6
jmp 0x9ac8
cmpq $0x0, 0x38(%rax)
jne 0x9ac8
movq 0x60(%rax), %rax
cmpq %rsi, %rax
jne 0x9ab8
cmpq %rsi, %rax
je 0x9b25
movl %ebp, %eax
xorb $0x1, %al
movzbl %al, %eax
movq 0x60(%rsi,%rax,8), %r14
movl $0x20, %edi
callq 0x3210
movq %rax, %r15
xorl %eax, %eax
movq %rax, 0x18(%r15)
movq 0x8(%r14), %rcx
movq %rcx, (%r15)
movq %rax, 0x8(%r15)
movq %r14, 0x10(%r15)
movl $0x0, 0x50(%r14)
movzbl %bpl, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x98c6
movq %rax, %r14
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9b42
movq %r14, %rax
jmp 0x9b37
testb %bpl, %bpl
je 0x9b30
movq 0x60(%rax), %rsi
jmp 0x9b34
movq 0x68(%rax), %rsi
movq %rsi, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq