// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::JoinHorz(ClipperLib::OutPt*, ClipperLib::OutPt*, ClipperLib::OutPt*, ClipperLib::OutPt*, ClipperLib::IntPoint, bool)
bool JoinHorz(OutPt* op1, OutPt* op1b, OutPt* op2, OutPt* op2b,
  const IntPoint Pt, bool DiscardLeft)
{
  Direction Dir1 = (op1->Pt.X > op1b->Pt.X ? dRightToLeft : dLeftToRight);
  Direction Dir2 = (op2->Pt.X > op2b->Pt.X ? dRightToLeft : dLeftToRight);
  if (Dir1 == Dir2) return false;

  //When DiscardLeft, we want Op1b to be on the Left of Op1, otherwise we
  //want Op1b to be on the Right. (And likewise with Op2 and Op2b.)
  //So, to facilitate this while inserting Op1b and Op2b ...
  //when DiscardLeft, make sure we're AT or RIGHT of Pt before adding Op1b,
  //otherwise make sure we're AT or LEFT of Pt. (Likewise with Op2b.)
  if (Dir1 == dLeftToRight) 
  {
    while (op1->Next->Pt.X <= Pt.X && 
      op1->Next->Pt.X >= op1->Pt.X && op1->Next->Pt.Y == Pt.Y)  
        op1 = op1->Next;
    if (DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
    op1b = DupOutPt(op1, !DiscardLeft);
    if (op1b->Pt != Pt) 
    {
      op1 = op1b;
      op1->Pt = Pt;
      op1b = DupOutPt(op1, !DiscardLeft);
    }
  } 
  else
  {
    while (op1->Next->Pt.X >= Pt.X && 
      op1->Next->Pt.X <= op1->Pt.X && op1->Next->Pt.Y == Pt.Y) 
        op1 = op1->Next;
    if (!DiscardLeft && (op1->Pt.X != Pt.X)) op1 = op1->Next;
    op1b = DupOutPt(op1, DiscardLeft);
    if (op1b->Pt != Pt)
    {
      op1 = op1b;
      op1->Pt = Pt;
      op1b = DupOutPt(op1, DiscardLeft);
    }
  }

  if (Dir2 == dLeftToRight)
  {
    while (op2->Next->Pt.X <= Pt.X && 
      op2->Next->Pt.X >= op2->Pt.X && op2->Next->Pt.Y == Pt.Y)
        op2 = op2->Next;
    if (DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next;
    op2b = DupOutPt(op2, !DiscardLeft);
    if (op2b->Pt != Pt)
    {
      op2 = op2b;
      op2->Pt = Pt;
      op2b = DupOutPt(op2, !DiscardLeft);
    };
  } else
  {
    while (op2->Next->Pt.X >= Pt.X && 
      op2->Next->Pt.X <= op2->Pt.X && op2->Next->Pt.Y == Pt.Y) 
        op2 = op2->Next;
    if (!DiscardLeft && (op2->Pt.X != Pt.X)) op2 = op2->Next;
    op2b = DupOutPt(op2, DiscardLeft);
    if (op2b->Pt != Pt)
    {
      op2 = op2b;
      op2->Pt = Pt;
      op2b = DupOutPt(op2, DiscardLeft);
    };
  };

  if ((Dir1 == dLeftToRight) == DiscardLeft)
  {
    op1->Prev = op2;
    op2->Next = op1;
    op1b->Next = op2b;
    op2b->Prev = op1b;
  }
  else
  {
    op1->Next = op2;
    op2->Prev = op1;
    op1b->Prev = op2b;
    op2b->Next = op1b;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rdx, %rbp
movq 0x8(%rdi), %r8
movq 0x8(%rsi), %rsi
cmpq %rsi, %r8
setle %dl
movq 0x8(%rbp), %r9
movq 0x8(%rcx), %rbx
cmpq %rbx, %r9
setle %cl
movl %edx, %eax
xorb %cl, %al
cmpb %cl, %dl
je 0xc7cc
movb 0x60(%rsp), %dl
movzbl %dl, %ecx
movl %ecx, 0x4(%rsp)
cmpq %rsi, %r8
movb %al, 0x3(%rsp)
movq %r8, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %r9, 0x10(%rsp)
jg 0xc664
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jg 0xc624
cmpq 0x8(%r12), %rcx
jl 0xc624
cmpq %r14, 0x10(%rdi)
je 0xc607
testb %dl, %dl
je 0xc631
cmpq %r15, 0x8(%r12)
cmovneq %rdi, %r12
movl %edx, %eax
xorb $0x1, %al
movzbl %al, %esi
movq %r12, %rdi
movl %esi, 0x8(%rsp)
callq 0xc55b
movq %rax, %r13
cmpq %r15, 0x8(%rax)
jne 0xc653
cmpq %r14, 0x10(%r13)
je 0xc6a9
movq %r15, 0x8(%r13)
movq %r14, 0x10(%r13)
movq %r13, %rdi
movl 0x8(%rsp), %esi
jmp 0xc6c2
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jl 0xc681
cmpq 0x8(%r12), %rcx
jg 0xc681
cmpq %r14, 0x10(%rdi)
je 0xc664
testb %dl, %dl
jne 0xc68e
cmpq %r15, 0x8(%r12)
cmovneq %rdi, %r12
movq %r12, %rdi
movl 0x4(%rsp), %esi
callq 0xc55b
movq %rax, %r13
cmpq %r15, 0x8(%rax)
jne 0xc6b3
cmpq %r14, 0x10(%r13)
jne 0xc6b3
movq %r13, 0x8(%rsp)
movq %r12, %r13
jmp 0xc6cc
movq %r15, 0x8(%r13)
movq %r14, 0x10(%r13)
movq %r13, %rdi
movl 0x4(%rsp), %esi
callq 0xc55b
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
movb 0x60(%rsp), %cl
jg 0xc733
movq %rbp, %r12
movq 0x18(%rbp), %rbp
movq 0x8(%rbp), %rax
cmpq %r15, %rax
jg 0xc6f7
cmpq 0x8(%r12), %rax
jl 0xc6f7
cmpq %r14, 0x10(%rbp)
je 0xc6da
testb %cl, %cl
je 0xc704
cmpq %r15, 0x8(%r12)
cmovneq %rbp, %r12
movl %ecx, %eax
xorb $0x1, %al
movzbl %al, %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0xc55b
movq %rax, %rbp
cmpq %r15, 0x8(%rax)
jne 0xc724
cmpq %r14, 0x10(%rbp)
je 0xc792
movq %r15, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movq %rbp, %rdi
movl %ebx, %esi
jmp 0xc787
movq %rbp, %r12
movq 0x18(%rbp), %rbp
movq 0x8(%rbp), %rax
cmpq %r15, %rax
jl 0xc750
cmpq 0x8(%r12), %rax
jg 0xc750
cmpq %r14, 0x10(%rbp)
je 0xc733
testb %cl, %cl
jne 0xc75d
cmpq %r15, 0x8(%r12)
cmovneq %rbp, %r12
movq %r12, %rdi
movl 0x4(%rsp), %esi
callq 0xc55b
movq %rax, %rbp
cmpq %r15, 0x8(%rax)
jne 0xc778
cmpq %r14, 0x10(%rbp)
je 0xc792
movq %r15, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movq %rbp, %rdi
movl 0x4(%rsp), %esi
callq 0xc55b
movq %rbp, %r12
movq %rax, %rbp
movb 0x3(%rsp), %al
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
cmpq %rdx, %rcx
setle %dl
xorb 0x60(%rsp), %dl
movzbl %dl, %ecx
xorb $0x1, %dl
movzbl %dl, %edx
movq %r12, 0x18(%r13,%rdx,8)
movq %r13, 0x18(%r12,%rcx,8)
movq 0x8(%rsp), %rsi
movq %rbp, 0x18(%rsi,%rcx,8)
movq %rsi, 0x18(%rbp,%rdx,8)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop