// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movss %xmm2, 0x10(%rsp)
movss %xmm1, 0x14(%rsp)
movss %xmm0, 0x4(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, 0x50(%rsp)
callq 0x86b8
movss 0x4(%rsp), %xmm2
movsd %xmm0, 0x48(%rsp)
movsd %xmm1, 0x40(%rsp)
ucomiss 0x14(%rsp), %xmm2
jbe 0x64c3
movss 0xde7e(%rip), %xmm0     # 0x140d4
movss 0x10(%rsp), %xmm1
mulss %xmm1, %xmm0
cvtss2sd %xmm1, %xmm1
movsd %xmm1, 0x68(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movb $0x1, %r15b
leaq 0x18(%rsp), %r12
leaq 0x78(%rsp), %r13
movss %xmm2, 0x4(%rsp)
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
movq %r12, %rdi
movq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x6f1c
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rax
movq %rax, 0x58(%rsp)
cmpq %rbp, %rax
movq %rbp, 0x60(%rsp)
je 0x6484
movq %r12, %rdi
callq 0x38bc
movaps %xmm0, %xmm2
movq 0x18(%rsp), %rax
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
subsd 0x48(%rsp), %xmm0
subsd 0x40(%rsp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0xdd15(%rip), %xmm0     # 0x14008
jb 0x62fb
sqrtsd %xmm0, %xmm0
jmp 0x630c
movsd %xmm2, 0x8(%rsp)
callq 0x31a0
movsd 0x8(%rsp), %xmm2
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
testl %ecx, %ecx
jle 0x6484
xorps %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm1
movss %xmm1, 0x34(%rsp)
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm3, %xmm3
xorl %ebp, %ebp
xorl %r12d, %r12d
xorps %xmm2, %xmm2
testq %rbp, %rbp
je 0x639f
movsd (%rax,%rbp), %xmm0
subsd -0x10(%rax,%rbp), %xmm0
movsd 0x8(%rax,%rbp), %xmm1
subsd -0x8(%rax,%rbp), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0xdc8d(%rip), %xmm0     # 0x14008
jb 0x6383
sqrtsd %xmm0, %xmm0
jmp 0x6394
movss %xmm3, 0x8(%rsp)
callq 0x31a0
movss 0x8(%rsp), %xmm3
cvtsd2ss %xmm0, %xmm0
addss %xmm0, %xmm3
movaps %xmm3, %xmm2
movq 0x18(%rsp), %rax
movsd (%rax,%rbp), %xmm0
movsd 0x8(%rax,%rbp), %xmm1
movsd 0x48(%rsp), %xmm4
subsd %xmm4, %xmm0
movsd 0x40(%rsp), %xmm5
subsd %xmm5, %xmm1
movss %xmm2, 0x8(%rsp)
divss 0x34(%rsp), %xmm2
cvtss2sd %xmm2, %xmm2
mulsd 0x68(%rsp), %xmm2
movsd 0x70(%rsp), %xmm6
movapd %xmm6, %xmm3
subsd %xmm2, %xmm3
divsd %xmm6, %xmm3
xorps %xmm2, %xmm2
cvtsd2ss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movsd (%rbx), %xmm2
addsd %xmm4, %xmm2
addsd %xmm0, %xmm2
movsd 0x8(%rbx), %xmm0
addsd %xmm5, %xmm0
addsd %xmm1, %xmm0
movsd %xmm2, 0x78(%rsp)
movsd %xmm0, 0x80(%rsp)
movq (%r14), %rax
testb $0x1, %r15b
je 0x6440
movq %r14, %rdi
movq %r13, %rsi
movsd 0x38(%rsp), %xmm0
callq *0x48(%rax)
jmp 0x6457
movq %r14, %rdi
movq %r13, %rsi
movsd 0x38(%rsp), %xmm0
movsd 0xdbd4(%rip), %xmm1     # 0x14028
callq *0x50(%rax)
incq %r12
movq 0x18(%rsp), %rax
movq 0x20(%rsp), %rcx
subq %rax, %rcx
shrq $0x4, %rcx
movslq %ecx, %rcx
addq $0x10, %rbp
xorl %r15d, %r15d
movss 0x8(%rsp), %xmm3
cmpq %rcx, %r12
jl 0x6348
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x649b
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x3220
movq 0x58(%rsp), %rax
cmpq 0x60(%rsp), %rax
movss 0x4(%rsp), %xmm2
leaq 0x18(%rsp), %r12
je 0x64c3
subss 0x10(%rsp), %xmm2
ucomiss 0x14(%rsp), %xmm2
ja 0x6281
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x64ef
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x3220
movq %rbx, %rdi
callq 0x3380
nop