// File: /workspace/github_cpp_makefile_star2_O3/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 $0x48, %rsp
movq %r9, %r14
movq %r8, %r15
movq %rdx, %r13
movq 0x8(%rdi), %r8
movq 0x8(%rsi), %rsi
cmpq %rsi, %r8
setle %dl
movq 0x8(%r13), %r9
movq 0x8(%rcx), %r10
cmpq %r10, %r9
setle %cl
movl %edx, %eax
xorb %cl, %al
cmpb %cl, %dl
je 0xe167
cmpq %rsi, %r8
movb %al, 0x7(%rsp)
movq %r8, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %r9, 0x10(%rsp)
movq %r10, 0x8(%rsp)
jg 0xdf1d
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jg 0xdf07
cmpq 0x8(%r12), %rcx
jl 0xdf07
cmpq %r14, 0x10(%rdi)
je 0xdeea
cmpb $0x0, 0x80(%rsp)
jne 0xdf44
movl $0x18, %ebx
movl $0x20, %eax
jmp 0xdf57
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jl 0xdf3a
cmpq 0x8(%r12), %rcx
jg 0xdf3a
cmpq %r14, 0x10(%rdi)
je 0xdf1d
cmpb $0x0, 0x80(%rsp)
jne 0xdf11
cmpq %r15, 0x8(%r12)
cmovneq %rdi, %r12
movl $0x20, %ebx
movl $0x18, %eax
movq %rax, 0x18(%rsp)
movl $0x28, %edi
callq 0x3210
movq %rax, %rbp
leaq 0x8(%rax), %rdx
movups 0x8(%r12), %xmm0
movups %xmm0, 0x8(%rax)
movl (%r12), %esi
movl %esi, (%rax)
movq (%r12,%rbx), %rax
leaq (%rbp,%rbx), %rdi
movq %rax, (%rbp,%rbx)
movq 0x18(%rsp), %rcx
movq %r12, (%rbp,%rcx)
movq %rbp, (%rax,%rcx)
movq %rbp, (%r12,%rbx)
cmpq %r15, 0x8(%rbp)
movq %rcx, %rax
jne 0xdfac
cmpq %r14, 0x10(%rbp)
je 0xe00b
movq %rdx, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movq %rdi, 0x30(%rsp)
movq %rbx, 0x18(%rsp)
movq %rbp, %r12
movq %r15, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movl $0x28, %edi
movq %rax, %rbx
callq 0x3210
movq %rax, %rbp
movq 0x28(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x8(%rbp)
movl 0x24(%rsp), %eax
movl %eax, (%rbp)
movq 0x30(%rsp), %rcx
movq (%rcx), %rax
movq 0x18(%rsp), %rdx
movq %rax, (%rbp,%rdx)
movq %r12, (%rbp,%rbx)
movq %rbp, (%rax,%rbx)
movq %rbp, (%rcx)
movq 0x8(%rsp), %rax
cmpq %rax, 0x10(%rsp)
jg 0xe04e
movq %r13, %rbx
movq 0x18(%r13), %r13
movq 0x8(%r13), %rax
cmpq %r15, %rax
jg 0xe033
cmpq 0x8(%rbx), %rax
jl 0xe033
cmpq %r14, 0x10(%r13)
je 0xe017
cmpb $0x0, 0x80(%rsp)
jne 0xe074
movl $0x18, %eax
movq %rax, 0x10(%rsp)
movl $0x20, %eax
jmp 0xe08b
movq %r13, %rbx
movq 0x18(%r13), %r13
movq 0x8(%r13), %rax
cmpq %r15, %rax
jl 0xe06a
cmpq 0x8(%rbx), %rax
jg 0xe06a
cmpq %r14, 0x10(%r13)
je 0xe04e
cmpb $0x0, 0x80(%rsp)
jne 0xe03d
cmpq %r15, 0x8(%rbx)
cmovneq %r13, %rbx
movl $0x20, %eax
movq %rax, 0x10(%rsp)
movl $0x18, %eax
movq %rax, 0x8(%rsp)
movl $0x28, %edi
callq 0x3210
movq %rax, %r13
leaq 0x8(%rax), %rdx
movups 0x8(%rbx), %xmm0
movups %xmm0, 0x8(%rax)
movl (%rbx), %esi
movl %esi, (%rax)
movq 0x10(%rsp), %rcx
movq (%rbx,%rcx), %rax
leaq (%r13,%rcx), %rdi
movq %rax, (%r13,%rcx)
movq 0x8(%rsp), %r8
movq %rbx, (%r13,%r8)
movq %r13, (%rax,%r8)
movq %r13, (%rbx,%rcx)
cmpq %r15, 0x8(%r13)
movq %rcx, %rax
movq %r8, %rcx
jne 0xe0e4
cmpq %r14, 0x10(%r13)
je 0xe133
movl %esi, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movq %r15, 0x8(%r13)
movq %r14, 0x10(%r13)
movq %rdi, %rbx
movl $0x28, %edi
movq %rcx, %r14
movq %rdx, %r15
callq 0x3210
movups (%r15), %xmm0
movups %xmm0, 0x8(%rax)
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
movq (%rbx), %rcx
movq 0x10(%rsp), %rdx
movq %rcx, (%rax,%rdx)
movq %r13, (%rax,%r14)
movq %rax, (%rcx,%r14)
movq %rax, (%rbx)
movq %r13, %rbx
movq %rax, %r13
movq 0x38(%rsp), %rax
cmpq %rax, 0x40(%rsp)
setle %al
xorb 0x80(%rsp), %al
movzbl %al, %ecx
xorb $0x1, %al
movzbl %al, %eax
movq %rbx, 0x18(%r12,%rax,8)
movq %r12, 0x18(%rbx,%rcx,8)
movq %r13, 0x18(%rbp,%rcx,8)
movq %rbp, 0x18(%r13,%rax,8)
movb 0x7(%rsp), %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq