// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/multi-shell-extrude.cc
// Function: CreateBottomPlate(std::vector<Vector2D, std::allocator<Vector2D>> const&, Printer*, Vector2D const&, float, float, float)
static void CreateBottomPlate(const Polygon &target_polygon,
                              Printer *printer,
                              const Vector2D &center_offset,
                              float outer_distance, float inner_distance,
                              float spiral_distance) {
  bool is_first = true;
  // Initial height.
  const float z_height = spiral_distance/2;
  const Vector2D centroid = Centroid(target_polygon);
  for (float poffset = outer_distance;
       poffset > inner_distance; poffset -= spiral_distance) {
    Polygon p = PolygonOffset(target_polygon, poffset);
    if (p.size() == 0)
      return;   // Natural end of moving towards center.
    float run_len = 0;
    const float polygon_len = CalcPolygonLen(p);
    // fudging a spiral: we want that the distance from the center
    // is one spiral_distance less in the end.
    float outer_distance = (p[0] - centroid).magnitude();
    for (int i = 0; i < (int) p.size(); ++i) {
      if (i == 0) {
        run_len = 0;
      } else {
        run_len += (p[i] - p[i-1]).magnitude();
      }
      Vector2D current_point_from_center = p[i] - centroid;
      const double fraction = run_len / polygon_len;
      float spiral_adjust = (outer_distance - fraction*spiral_distance)/outer_distance;
      current_point_from_center = current_point_from_center * spiral_adjust;
      Vector2D next_pos = center_offset + centroid + current_point_from_center;
      if (is_first)
        printer->MoveTo(next_pos, z_height);
      else
        printer->ExtrudeTo(next_pos, z_height, 1.0);
      is_first = false;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movss %xmm2, 0xc(%rsp)
movss %xmm1, 0x10(%rsp)
movss %xmm0, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movss 0xcd20(%rip), %xmm0     # 0x1212c
mulss %xmm2, %xmm0
movss %xmm0, 0x4(%rsp)
movq %rdi, 0x38(%rsp)
callq 0x7960
movss 0x8(%rsp), %xmm2
cvtss2sd 0xc(%rsp), %xmm3
movsd %xmm3, 0x50(%rsp)
cvtss2sd 0x4(%rsp), %xmm3
movsd %xmm3, 0x18(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
movlhps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, 0x80(%rsp)
movb $0x1, %r15b
leaq 0x20(%rsp), %r12
ucomiss 0x10(%rsp), %xmm2
jbe 0x5631
movss %xmm2, 0x8(%rsp)
cvtss2sd %xmm2, %xmm0
movq %r12, %rdi
movq 0x38(%rsp), %rsi
xorl %edx, %edx
callq 0x6280
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %r13
cmpq %rbp, %r13
movq %r13, 0x48(%rsp)
je 0x5611
movq %r12, %rdi
callq 0x352c
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x14(%rsp)
movsd (%rbp), %xmm0
movsd 0x8(%rbp), %xmm1
subsd 0x70(%rsp), %xmm0
subsd 0x60(%rsp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
sqrtsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x58(%rsp)
xorps %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
xorl %r12d, %r12d
movq %rbp, 0x40(%rsp)
movq %rbp, %rax
movq %r13, %rcx
xorl %ebp, %ebp
leaq 0x90(%rsp), %r13
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
cmpq %rcx, %rbp
jge 0x5607
testq %r12, %r12
je 0x555a
movupd (%rax,%r12), %xmm0
movsd -0x10(%rax,%r12), %xmm1
movapd %xmm0, %xmm2
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
subsd -0x8(%rax,%r12), %xmm3
subsd %xmm1, %xmm2
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
sqrtsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss 0x4(%rsp), %xmm2
addss %xmm1, %xmm2
jmp 0x5561
movupd (%rax), %xmm0
xorps %xmm2, %xmm2
movapd 0x80(%rsp), %xmm3
subpd %xmm3, %xmm0
movss %xmm2, 0x4(%rsp)
movaps %xmm2, %xmm1
divss 0x14(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm4
movapd %xmm4, %xmm2
subsd %xmm1, %xmm2
divsd %xmm4, %xmm2
cvtsd2ss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
movlhps %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm0, %xmm1
movupd (%rbx), %xmm0
addpd %xmm3, %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0x90(%rsp)
movq (%r14), %rax
testb $0x1, %r15b
je 0x55d7
movq %r14, %rdi
movq %r13, %rsi
movsd 0x18(%rsp), %xmm0
callq *0x48(%rax)
jmp 0x55ee
movq %r14, %rdi
movq %r13, %rsi
movsd 0x18(%rsp), %xmm0
movsd 0xca95(%rip), %xmm1     # 0x12080
callq *0x50(%rax)
incq %rbp
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
addq $0x10, %r12
xorl %r15d, %r15d
jmp 0x54fe
leaq 0x20(%rsp), %r12
movq 0x40(%rsp), %rbp
movq %r12, %rdi
callq 0x5b22
cmpq %rbp, 0x48(%rsp)
movss 0x8(%rsp), %xmm2
je 0x5631
subss 0xc(%rsp), %xmm2
jmp 0x545b
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5b22
movq %rbx, %rdi
callq 0x33a0