// File: /workspace/github_cpp_makefile_star2_O1/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 0xe4d1
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 0xe369
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jg 0xe329
cmpq 0x8(%r12), %rcx
jl 0xe329
cmpq %r14, 0x10(%rdi)
je 0xe30c
testb %dl, %dl
je 0xe336
cmpq %r15, 0x8(%r12)
cmovneq %rdi, %r12
movl %edx, %eax
xorb $0x1, %al
movzbl %al, %esi
movq %r12, %rdi
movl %esi, 0x8(%rsp)
callq 0xe25e
movq %rax, %r13
cmpq %r15, 0x8(%rax)
jne 0xe358
cmpq %r14, 0x10(%r13)
je 0xe3ae
movq %r15, 0x8(%r13)
movq %r14, 0x10(%r13)
movq %r13, %rdi
movl 0x8(%rsp), %esi
jmp 0xe3c7
movq %rdi, %r12
movq 0x18(%rdi), %rdi
movq 0x8(%rdi), %rcx
cmpq %r15, %rcx
jl 0xe386
cmpq 0x8(%r12), %rcx
jg 0xe386
cmpq %r14, 0x10(%rdi)
je 0xe369
testb %dl, %dl
jne 0xe393
cmpq %r15, 0x8(%r12)
cmovneq %rdi, %r12
movq %r12, %rdi
movl 0x4(%rsp), %esi
callq 0xe25e
movq %rax, %r13
cmpq %r15, 0x8(%rax)
jne 0xe3b8
cmpq %r14, 0x10(%r13)
jne 0xe3b8
movq %r13, 0x8(%rsp)
movq %r12, %r13
jmp 0xe3d1
movq %r15, 0x8(%r13)
movq %r14, 0x10(%r13)
movq %r13, %rdi
movl 0x4(%rsp), %esi
callq 0xe25e
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
cmpq %rbx, %rax
movb 0x60(%rsp), %cl
jg 0xe438
movq %rbp, %r12
movq 0x18(%rbp), %rbp
movq 0x8(%rbp), %rax
cmpq %r15, %rax
jg 0xe3fc
cmpq 0x8(%r12), %rax
jl 0xe3fc
cmpq %r14, 0x10(%rbp)
je 0xe3df
testb %cl, %cl
je 0xe409
cmpq %r15, 0x8(%r12)
cmovneq %rbp, %r12
movl %ecx, %eax
xorb $0x1, %al
movzbl %al, %ebx
movq %r12, %rdi
movl %ebx, %esi
callq 0xe25e
movq %rax, %rbp
cmpq %r15, 0x8(%rax)
jne 0xe429
cmpq %r14, 0x10(%rbp)
je 0xe497
movq %r15, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movq %rbp, %rdi
movl %ebx, %esi
jmp 0xe48c
movq %rbp, %r12
movq 0x18(%rbp), %rbp
movq 0x8(%rbp), %rax
cmpq %r15, %rax
jl 0xe455
cmpq 0x8(%r12), %rax
jg 0xe455
cmpq %r14, 0x10(%rbp)
je 0xe438
testb %cl, %cl
jne 0xe462
cmpq %r15, 0x8(%r12)
cmovneq %rbp, %r12
movq %r12, %rdi
movl 0x4(%rsp), %esi
callq 0xe25e
movq %rax, %rbp
cmpq %r15, 0x8(%rax)
jne 0xe47d
cmpq %r14, 0x10(%rbp)
je 0xe497
movq %r15, 0x8(%rbp)
movq %r14, 0x10(%rbp)
movq %rbp, %rdi
movl 0x4(%rsp), %esi
callq 0xe25e
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