// File: 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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movss %xmm2, -0x24(%rbp)
movb $0x1, -0x25(%rbp)
movss -0x24(%rbp), %xmm0
movss 0x23b31(%rip), %xmm1    # 0x2b0b8
divss %xmm1, %xmm0
movss %xmm0, -0x2c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x10a00
movsd %xmm0, -0x40(%rbp)
movsd %xmm1, -0x38(%rbp)
movss -0x1c(%rbp), %xmm0
movss %xmm0, -0x44(%rbp)
movss -0x44(%rbp), %xmm0
ucomiss -0x20(%rbp), %xmm0
jbe 0x7998
movq -0x8(%rbp), %rsi
movss -0x44(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq -0x60(%rbp), %rdi
xorl %edx, %edx
callq 0xc1b0
leaq -0x60(%rbp), %rdi
callq 0x82d0
cmpq $0x0, %rax
jne 0x75ef
movl $0x1, -0x64(%rbp)
jmp 0x796a
movl $0x0, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x35f0
movsd %xmm0, -0x108(%rbp)
jmp 0x7609
movsd -0x108(%rbp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x6c(%rbp)
xorl %eax, %eax
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x8ff0
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x8b00
movsd %xmm1, -0x118(%rbp)
movsd %xmm0, -0x110(%rbp)
jmp 0x7645
movsd -0x118(%rbp), %xmm0
movsd -0x110(%rbp), %xmm1
movsd %xmm1, -0x90(%rbp)
movsd %xmm0, -0x88(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x9010
movss %xmm0, -0x11c(%rbp)
jmp 0x767b
movss -0x11c(%rbp), %xmm0
movss %xmm0, -0x80(%rbp)
movl $0x0, -0x94(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x120(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x82d0
movq %rax, %rcx
movl -0x120(%rbp), %eax
cmpl %ecx, %eax
jge 0x7963
cmpl $0x0, -0x94(%rbp)
jne 0x76e8
xorps %xmm0, %xmm0
movss %xmm0, -0x68(%rbp)
jmp 0x7786
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x84c0
jmp 0x79a1
movslq -0x94(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x8ff0
movq -0x140(%rbp), %rdi
movq %rax, -0x138(%rbp)
movl -0x94(%rbp), %eax
decl %eax
movslq %eax, %rsi
callq 0x8ff0
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x8b00
movsd %xmm1, -0x130(%rbp)
movsd %xmm0, -0x128(%rbp)
jmp 0x773e
movsd -0x130(%rbp), %xmm0
movsd -0x128(%rbp), %xmm1
movsd %xmm1, -0xa8(%rbp)
movsd %xmm0, -0xa0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x9010
movss %xmm0, -0x144(%rbp)
jmp 0x7774
movss -0x144(%rbp), %xmm0
addss -0x68(%rbp), %xmm0
movss %xmm0, -0x68(%rbp)
movslq -0x94(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x8ff0
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x8b00
movsd %xmm1, -0x158(%rbp)
movsd %xmm0, -0x150(%rbp)
jmp 0x77b4
movsd -0x158(%rbp), %xmm0
movsd -0x150(%rbp), %xmm1
movsd %xmm1, -0xc0(%rbp)
movsd %xmm0, -0xb8(%rbp)
movss -0x68(%rbp), %xmm0
movss -0x6c(%rbp), %xmm1
divss %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
movss -0x80(%rbp), %xmm0
cvtss2sd %xmm0, %xmm1
movsd -0xc8(%rbp), %xmm2
movss -0x24(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
mulsd %xmm0, %xmm2
movaps %xmm1, %xmm0
subsd %xmm2, %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0xcc(%rbp)
movss -0xcc(%rbp), %xmm0
leaq -0xc0(%rbp), %rdi
callq 0x8bf0
movsd %xmm1, -0x168(%rbp)
movsd %xmm0, -0x160(%rbp)
jmp 0x7849
movsd -0x168(%rbp), %xmm0
movsd -0x160(%rbp), %xmm1
movsd %xmm1, -0xe0(%rbp)
movsd %xmm0, -0xd8(%rbp)
movups -0xe0(%rbp), %xmm0
movaps %xmm0, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8c40
movsd %xmm1, -0x178(%rbp)
movsd %xmm0, -0x170(%rbp)
jmp 0x7896
movsd -0x178(%rbp), %xmm0
movsd -0x170(%rbp), %xmm1
movsd %xmm1, -0x100(%rbp)
movsd %xmm0, -0xf8(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x8c40
movsd %xmm1, -0x188(%rbp)
movsd %xmm0, -0x180(%rbp)
jmp 0x78db
movsd -0x188(%rbp), %xmm0
movsd -0x180(%rbp), %xmm1
movsd %xmm1, -0xf0(%rbp)
movsd %xmm0, -0xe8(%rbp)
testb $0x1, -0x25(%rbp)
je 0x7922
movq -0x10(%rbp), %rdi
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq (%rdi), %rax
movq 0x48(%rax), %rax
leaq -0xf0(%rbp), %rsi
callq *%rax
jmp 0x7920
jmp 0x794b
movq -0x10(%rbp), %rdi
movss -0x2c(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq (%rdi), %rax
movq 0x50(%rax), %rax
leaq -0xf0(%rbp), %rsi
movsd 0x236eb(%rip), %xmm1    # 0x2b030
callq *%rax
jmp 0x7949
jmp 0x794b
movb $0x0, -0x25(%rbp)
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x7692
movl $0x0, -0x64(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x84c0
movl -0x64(%rbp), %eax
testl %eax, %eax
je 0x797e
jmp 0x797c
jmp 0x7998
jmp 0x7980
movss -0x24(%rbp), %xmm1
movss -0x44(%rbp), %xmm0
subss %xmm1, %xmm0
movss %xmm0, -0x44(%rbp)
jmp 0x75ad
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x3440
nopw (%rax,%rax)