// File: hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::SetWindingCount(ClipperLib::TEdge&)
void Clipper::SetWindingCount(TEdge &edge)
{
  TEdge *e = edge.PrevInAEL;
  //find the edge of the same polytype that immediately preceeds 'edge' in AEL
  while (e  && ((e->PolyTyp != edge.PolyTyp) || (e->WindDelta == 0))) e = e->PrevInAEL;
  if (!e)
  {
    edge.WindCnt = (edge.WindDelta == 0 ? 1 : edge.WindDelta);
    edge.WindCnt2 = 0;
    e = m_ActiveEdges; //ie get ready to calc WindCnt2
  }   
  else if (edge.WindDelta == 0 && m_ClipType != ctUnion)
  {
    edge.WindCnt = 1;
    edge.WindCnt2 = e->WindCnt2;
    e = e->NextInAEL; //ie get ready to calc WindCnt2
  }
  else if (IsEvenOddFillType(edge))
  {
    //EvenOdd filling ...
    if (edge.WindDelta == 0)
    {
      //are we inside a subj polygon ...
      bool Inside = true;
      TEdge *e2 = e->PrevInAEL;
      while (e2)
      {
        if (e2->PolyTyp == e->PolyTyp && e2->WindDelta != 0) 
          Inside = !Inside;
        e2 = e2->PrevInAEL;
      }
      edge.WindCnt = (Inside ? 0 : 1);
    }
    else
    {
      edge.WindCnt = edge.WindDelta;
    }
    edge.WindCnt2 = e->WindCnt2;
    e = e->NextInAEL; //ie get ready to calc WindCnt2
  } 
  else
  {
    //nonZero, Positive or Negative filling ...
    if (e->WindCnt * e->WindDelta < 0)
    {
      //prev edge is 'decreasing' WindCount (WC) toward zero
      //so we're outside the previous polygon ...
      if (Abs(e->WindCnt) > 1)
      {
        //outside prev poly but still inside another.
        //when reversing direction of prev poly use the same WC 
        if (e->WindDelta * edge.WindDelta < 0) edge.WindCnt = e->WindCnt;
        //otherwise continue to 'decrease' WC ...
        else edge.WindCnt = e->WindCnt + edge.WindDelta;
      } 
      else
        //now outside all polys of same polytype so set own WC ...
        edge.WindCnt = (edge.WindDelta == 0 ? 1 : edge.WindDelta);
    } else
    {
      //prev edge is 'increasing' WindCount (WC) away from zero
      //so we're inside the previous polygon ...
      if (edge.WindDelta == 0) 
        edge.WindCnt = (e->WindCnt < 0 ? e->WindCnt - 1 : e->WindCnt + 1);
      //if wind direction is reversing prev then use same WC
      else if (e->WindDelta * edge.WindDelta < 0) edge.WindCnt = e->WindCnt;
      //otherwise add to WC ...
      else edge.WindCnt = e->WindCnt + edge.WindDelta;
    }
    edge.WindCnt2 = e->WindCnt2;
    e = e->NextInAEL; //ie get ready to calc WindCnt2
  }

  //update WindCnt2 ...
  if (IsEvenOddAltFillType(edge))
  {
    //EvenOdd filling ...
    while (e != &edge)
    {
      if (e->WindDelta != 0)
        edge.WindCnt2 = (edge.WindCnt2 == 0 ? 1 : 0);
      e = e->NextInAEL;
    }
  } else
  {
    //nonZero, Positive or Negative filling ...
    while ( e != &edge )
    {
      edge.WindCnt2 += e->WindDelta;
      e = e->NextInAEL;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x18(%rbp)
xorl %eax, %eax
cmpq $0x0, -0x18(%rbp)
movb %al, -0x31(%rbp)
je 0x16d5c
movq -0x18(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x10(%rbp), %rdx
movb $0x1, %al
cmpl 0x48(%rdx), %ecx
movb %al, -0x32(%rbp)
jne 0x16d56
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
sete %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x16d65
jmp 0x16d76
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16d27
cmpq $0x0, -0x18(%rbp)
jne 0x16dc4
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x16d91
movl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x16d9b
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movl -0x38(%rbp), %edx
movq -0x10(%rbp), %rcx
movl %edx, 0x54(%rcx)
movq -0x10(%rbp), %rcx
movl $0x0, 0x58(%rcx)
movq 0xa0(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16fda
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x16e02
movq -0x30(%rbp), %rax
cmpl $0x1, 0x68(%rax)
je 0x16e02
movq -0x10(%rbp), %rax
movl $0x1, 0x54(%rax)
movq -0x18(%rbp), %rax
movl 0x58(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16fd8
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x17070
testb $0x1, %al
jne 0x16e18
jmp 0x16eb7
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x16e8a
movb $0x1, -0x19(%rbp)
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x16e71
movq -0x28(%rbp), %rax
movl 0x48(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x48(%rcx), %eax
jne 0x16e60
movq -0x28(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x16e60
movb -0x19(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x19(%rbp)
movq -0x28(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x16e35
movb -0x19(%rbp), %dl
movl $0x1, %ecx
xorl %eax, %eax
testb $0x1, %dl
cmovnel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16e98
movq -0x10(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
movq -0x18(%rbp), %rax
movl 0x58(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16fd6
movq -0x18(%rbp), %rax
movl 0x54(%rax), %eax
movq -0x18(%rbp), %rcx
imull 0x50(%rcx), %eax
cmpl $0x0, %eax
jge 0x16f43
movq -0x18(%rbp), %rax
movslq 0x54(%rax), %rdi
callq 0x20680
cmpq $0x1, %rax
jle 0x16f19
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x50(%rcx), %eax
cmpl $0x0, %eax
jge 0x16f02
movq -0x18(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16f17
movq -0x18(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16f41
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x16f2d
movl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x16f37
movq -0x10(%rbp), %rax
movl 0x50(%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16fbc
movq -0x10(%rbp), %rax
cmpl $0x0, 0x50(%rax)
jne 0x16f7f
movq -0x18(%rbp), %rax
cmpl $0x0, 0x54(%rax)
jge 0x16f66
movq -0x18(%rbp), %rax
movl 0x54(%rax), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x16f73
movq -0x18(%rbp), %rax
movl 0x54(%rax), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16fba
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
movq -0x10(%rbp), %rcx
imull 0x50(%rcx), %eax
cmpl $0x0, %eax
jge 0x16fa3
movq -0x18(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16fb8
movq -0x18(%rbp), %rax
movl 0x54(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x54(%rax)
jmp 0x16fba
jmp 0x16fbc
movq -0x18(%rbp), %rax
movl 0x58(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16fd8
jmp 0x16fda
movq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x170c0
testb $0x1, %al
jne 0x16fed
jmp 0x1702e
jmp 0x16fef
movq -0x18(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x1702c
movq -0x18(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x1701e
movq -0x10(%rbp), %rax
movl 0x58(%rax), %edx
xorl %ecx, %ecx
movl $0x1, %eax
cmpl $0x0, %edx
cmovel %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x16fef
jmp 0x1705b
jmp 0x17030
movq -0x18(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x17059
movq -0x18(%rbp), %rax
movl 0x50(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x58(%rax), %ecx
movl %ecx, 0x58(%rax)
movq -0x18(%rbp), %rax
movq 0x78(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x17030
jmp 0x1705b
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)