// File: /workspace/github_cpp_makefile_star2_O3/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, 0x4(%rsp)
movss %xmm1, 0x8(%rsp)
movss %xmm0, (%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x40(%rsp)
callq 0x8384
movss (%rsp), %xmm2
movaps %xmm0, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
ucomiss 0x8(%rsp), %xmm2
jbe 0x622e
movss 0xe105(%rip), %xmm0     # 0x1410c
movss 0x4(%rsp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x50(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movaps 0x70(%rsp), %xmm0
unpcklpd 0x60(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movaps %xmm0, 0x80(%rsp)
movb $0x1, %r15b
leaq 0x28(%rsp), %rbp
leaq 0x90(%rsp), %r13
movss %xmm2, (%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movq %rbp, %rdi
movq 0x40(%rsp), %rsi
xorl %edx, %edx
callq 0x6c88
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r12
movq %r12, 0x48(%rsp)
subq %rdi, %r12
movq %rdi, 0x10(%rsp)
je 0x61f5
movq %rbp, %rdi
callq 0x38dc
shrq $0x4, %r12
testl %r12d, %r12d
jle 0x61f0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x10(%rsp), %rdi
movsd (%rdi), %xmm0
movsd 0x8(%rdi), %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, 0xc(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
testq %r12, %r12
je 0x6131
movupd (%rdi,%r12), %xmm0
movsd -0x10(%rdi,%r12), %xmm1
movapd %xmm0, %xmm2
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
subsd -0x8(%rdi,%r12), %xmm3
subsd %xmm1, %xmm2
mulsd %xmm3, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm3, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss 0xc(%rsp), %xmm2
addss %xmm1, %xmm2
jmp 0x6138
movupd (%rdi), %xmm0
xorps %xmm2, %xmm2
movapd 0x80(%rsp), %xmm3
subpd %xmm3, %xmm0
movss %xmm2, 0xc(%rsp)
movaps %xmm2, %xmm1
divss 0x1c(%rsp), %xmm1
cvtss2sd %xmm1, %xmm1
mulsd 0x50(%rsp), %xmm1
movsd 0x58(%rsp), %xmm4
movapd %xmm4, %xmm2
subsd %xmm1, %xmm2
divsd %xmm4, %xmm2
xorps %xmm1, %xmm1
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 0x61b1
movq %r14, %rdi
movq %r13, %rsi
movsd 0x20(%rsp), %xmm0
callq *0x48(%rax)
jmp 0x61c8
movq %r14, %rdi
movq %r13, %rsi
movsd 0x20(%rsp), %xmm0
movsd 0xdedb(%rip), %xmm1     # 0x140a0
callq *0x50(%rax)
incq %rbp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rax
subq %rdi, %rax
shrq $0x4, %rax
cltq
addq $0x10, %r12
xorl %r15d, %r15d
cmpq %rax, %rbp
jl 0x60e5
jmp 0x61f5
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x6207
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3220
movq 0x48(%rsp), %rax
cmpq 0x10(%rsp), %rax
movss (%rsp), %xmm2
leaq 0x28(%rsp), %rbp
je 0x622e
subss 0x4(%rsp), %xmm2
ucomiss 0x8(%rsp), %xmm2
ja 0x6048
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x625a
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x3220
movq %rbx, %rdi
callq 0x3380