// File: /workspace/github_cpp_makefile_star2_O2/harry830622[P]floorplanner/src/floorplanner.cpp
// Function: Floorplanner::ComputeCost(Floorplan const&, double, double) const
double Floorplanner::ComputeCost(const Floorplan& floorplan, double alpha,
                                 double beta) const {
  const double outline_width = database_.outline_width();
  const double outline_height = database_.outline_height();
  const double width = floorplan.width();
  const double height = floorplan.height();

  const double penalty_weight = 100.0;
  double penalty = 0.0;
  if (width > outline_width || height > outline_height) {
    if (width > outline_width && height > outline_height) {
      penalty += (width * height - outline_width * outline_height);
    } else if (width > outline_width) {
      penalty += ((width - outline_width) * height);
    } else if (height > outline_height) {
      penalty += (width * (height - outline_height));
    }
    penalty += ((width - outline_width) * (width - outline_width) +
                (height - outline_height) * (height - outline_height));
    penalty /= (max_area_ - min_area_);
  }

  /* const double penalty_weight = 1.0; */
  /* double penalty = 0.0; */
  /* if (width > outline_width || height > outline_height) { */
  /*   const double ratio = height / width; */
  /*   const double outline_ratio = outline_height / outline_width; */
  /*   penalty = (ratio - outline_ratio) * (ratio - outline_ratio); */
  /* } */

  /* const double penalty_weight = 1.0; */
  /* const double ratio = height / width; */
  /* const double outline_ratio = outline_height / outline_width; */
  /* const double penalty = (ratio - outline_ratio) * (ratio - outline_ratio);
   */

  const double normalized_area = floorplan.area() / (max_area_ - min_area_);
  const double normalized_wirelength =
      floorplan.wirelength() / (max_wirelength_ - min_wirelength_);

  const double cost = alpha * normalized_area + beta * normalized_wirelength +
                      (1.0 - alpha - beta) * penalty_weight * penalty;

  return cost;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movsd %xmm1, 0x20(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rdi
callq 0x8d06
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rdi
callq 0x8d0c
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0xaccc
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0xacd2
movsd (%rsp), %xmm5
movsd 0x8(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
ucomisd %xmm4, %xmm3
ja 0xfe31
xorpd %xmm1, %xmm1
ucomisd %xmm5, %xmm0
jbe 0xfe9b
ucomisd %xmm4, %xmm3
jbe 0xfe53
ucomisd %xmm5, %xmm0
jbe 0xfe53
movapd %xmm5, %xmm1
mulsd %xmm4, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
jmp 0xfe69
ucomisd %xmm4, %xmm3
jbe 0xff19
movapd %xmm3, %xmm2
subsd %xmm4, %xmm2
mulsd %xmm0, %xmm2
xorpd %xmm1, %xmm1
addsd %xmm2, %xmm1
subsd %xmm4, %xmm3
subsd %xmm5, %xmm0
mulsd %xmm0, %xmm0
mulsd %xmm3, %xmm3
addsd %xmm0, %xmm3
addsd %xmm1, %xmm3
movsd 0x40(%rbx), %xmm0
subsd 0x38(%rbx), %xmm0
divsd %xmm0, %xmm3
movapd %xmm3, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r14, %rdi
callq 0xacd8
movsd 0x40(%rbx), %xmm1
subsd 0x38(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0xace4
movsd 0x50(%rbx), %xmm1
subsd 0x48(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd 0x20(%rsp), %xmm2
mulsd %xmm2, %xmm0
movsd 0x18(%rsp), %xmm3
movsd (%rsp), %xmm4
mulsd %xmm3, %xmm4
movsd 0xb7f5(%rip), %xmm1     # 0x1b6e8
subsd %xmm3, %xmm1
subsd %xmm2, %xmm1
mulsd 0xb7f5(%rip), %xmm1     # 0x1b6f8
addsd %xmm4, %xmm0
mulsd 0x8(%rsp), %xmm1
addsd %xmm1, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r14
retq
xorpd %xmm1, %xmm1
ucomisd %xmm5, %xmm0
jbe 0xfe71
movapd %xmm0, %xmm2
subsd %xmm5, %xmm2
mulsd %xmm3, %xmm2
jmp 0xfe6d