// File: /workspace/github_cpp_makefile_star2_O3/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 %r12
pushq %rbx
movl %edx, %ebp
movq %rsi, %rax
movq %rdi, %rbx
cmpq $0x0, 0x38(%rsi)
jne 0x95c7
movzbl %bpl, %ecx
movq 0x60(%rax,%rcx,8), %rdx
movq (%rax), %rcx
cmpq (%rdx), %rcx
je 0x95c7
movq 0x20(%rax), %rdx
movq %rcx, 0x20(%rax)
movq %rdx, (%rax)
cmpl $-0x2, 0x5c(%rax)
je 0x9736
movq %rax, %rdx
testb %bpl, %bpl
je 0x9688
movq %rdx, %rcx
movq 0x28(%rdx), %rsi
movq 0x60(%rdx), %rdx
cmpq 0x8(%rdx), %rsi
jne 0x95f4
cmpl $-0x2, 0x5c(%rdx)
jne 0x95dd
cmpq $0x0, 0x38(%rcx)
jne 0x961d
cmpl $-0x2, 0x5c(%rdx)
je 0x961d
movq %rcx, %rsi
movq 0x68(%rsi), %rsi
cmpq $0x0, 0x38(%rsi)
je 0x9604
movq 0x20(%rdx), %rdx
cmpq %rdx, 0x20(%rsi)
je 0x961d
cmovgq %rsi, %rcx
cmpq %rax, %rcx
je 0x967f
movq %rax, %rdx
movq %rdx, %rsi
movq 0x38(%rdx), %rdi
movq 0x60(%rdx), %rdx
movq %rdx, 0x70(%rsi)
cmpq %rax, %rsi
je 0x9656
testq %rdi, %rdi
jne 0x9656
movq (%rsi), %rdi
movq 0x68(%rsi), %r8
cmpq 0x20(%r8), %rdi
je 0x9656
movq 0x20(%rsi), %r8
movq %rdi, 0x20(%rsi)
movq %r8, (%rsi)
cmpq %rcx, %rdx
jne 0x9625
cmpq %rax, %rdx
je 0x967f
cmpq $0x0, 0x38(%rdx)
jne 0x967f
movq (%rdx), %rax
movq 0x68(%rdx), %rsi
cmpq 0x20(%rsi), %rax
je 0x967f
movq 0x20(%rdx), %rsi
movq %rax, 0x20(%rdx)
movq %rsi, (%rdx)
addq $0x60, %rcx
jmp 0x9733
movq %rdx, %rcx
movq 0x28(%rdx), %rsi
movq 0x68(%rdx), %rdx
cmpq 0x8(%rdx), %rsi
jne 0x969f
cmpl $-0x2, 0x5c(%rdx)
jne 0x9688
cmpq $0x0, 0x38(%rcx)
jne 0x96cd
cmpl $-0x2, 0x5c(%rdx)
je 0x96cd
movq %rcx, %rsi
movq 0x60(%rsi), %rsi
cmpq $0x0, 0x38(%rsi)
je 0x96af
movq 0x20(%rdx), %rdx
cmpq %rdx, 0x20(%rsi)
jne 0x96c9
movq %rsi, %rcx
jmp 0x96cd
cmovgq %rsi, %rcx
cmpq %rax, %rcx
je 0x972f
movq %rax, %rdx
movq %rdx, %rsi
movq 0x38(%rdx), %rdi
movq 0x68(%rdx), %rdx
movq %rdx, 0x70(%rsi)
cmpq %rax, %rsi
je 0x9706
testq %rdi, %rdi
jne 0x9706
movq (%rsi), %rdi
movq 0x60(%rsi), %r8
cmpq 0x20(%r8), %rdi
je 0x9706
movq 0x20(%rsi), %r8
movq %rdi, 0x20(%rsi)
movq %r8, (%rsi)
cmpq %rcx, %rdx
jne 0x96d5
cmpq %rax, %rdx
je 0x972f
cmpq $0x0, 0x38(%rdx)
jne 0x972f
movq (%rdx), %rax
movq 0x60(%rdx), %rsi
cmpq 0x20(%rsi), %rax
je 0x972f
movq 0x20(%rdx), %rsi
movq %rax, 0x20(%rdx)
movq %rsi, (%rdx)
addq $0x68, %rcx
movq (%rcx), %rax
cmpl $-0x2, 0x5c(%rax)
jne 0x981e
movq %rax, %rdx
testb %bpl, %bpl
je 0x975b
movq %rdx, %rcx
movq 0x28(%rdx), %rsi
movq 0x60(%rdx), %rdx
cmpq 0x8(%rdx), %rsi
je 0x9748
jmp 0x9779
movq %rdx, %rcx
movq 0x28(%rdx), %rsi
movq 0x68(%rdx), %rdx
cmpq 0x8(%rdx), %rsi
je 0x975b
jmp 0x978b
cmpq $0x0, 0x38(%rcx)
jne 0x9790
movq 0x68(%rcx), %rcx
cmpq %rax, %rcx
jne 0x976e
jmp 0x9790
cmpq $0x0, 0x38(%rcx)
jne 0x9790
movq 0x60(%rcx), %rcx
cmpq %rax, %rcx
jne 0x9780
cmpq %rax, %rcx
je 0x9800
movl %ebp, %ecx
xorb $0x1, %cl
movzbl %cl, %ecx
movq 0x60(%rax,%rcx,8), %r15
movl $0x20, %edi
callq 0x3210
movq %rax, %r14
xorl %eax, %eax
movq %rax, 0x18(%r14)
movq 0x8(%r15), %r12
movq %r12, (%r14)
movq %rax, 0x8(%r14)
movq %r15, 0x10(%r14)
movl $0x0, 0x50(%r15)
movzbl %bpl, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9594
movq 0x10(%rbx), %rcx
addq $0x10, %rbx
testq %rcx, %rcx
je 0x981b
cmpq (%rcx), %r12
jge 0x9817
movq %rcx, %rbx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x9811
cmpq (%rcx), %r12
jl 0x97ed
jmp 0x9813
testb %bpl, %bpl
je 0x980b
movq 0x60(%rcx), %rax
jmp 0x981e
movq 0x68(%rcx), %rax
jmp 0x981e
xorl %ecx, %ecx
addq $0x18, %rbx
movq %rcx, 0x18(%r14)
movq %r14, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop