// File: /workspace/github_cpp_makefile_star2_O3/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 0x89fe
movsd %xmm0, 0x8(%rsp)
movq (%rbx), %rdi
callq 0x8a04
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0xaf68
movsd %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0xaf6e
movsd (%rsp), %xmm5
movsd 0x8(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
ucomisd %xmm4, %xmm3
ja 0x10cad
xorpd %xmm1, %xmm1
ucomisd %xmm5, %xmm0
jbe 0x10d17
ucomisd %xmm4, %xmm3
jbe 0x10ccf
ucomisd %xmm5, %xmm0
jbe 0x10ccf
movapd %xmm5, %xmm1
mulsd %xmm4, %xmm1
movapd %xmm3, %xmm2
mulsd %xmm0, %xmm2
subsd %xmm1, %xmm2
jmp 0x10ce5
ucomisd %xmm4, %xmm3
jbe 0x10d95
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 0xaf74
movsd 0x40(%rbx), %xmm1
subsd 0x38(%rbx), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, (%rsp)
movq %r14, %rdi
callq 0xaf80
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 0x10a21(%rip), %xmm1    # 0x21790
subsd %xmm3, %xmm1
subsd %xmm2, %xmm1
mulsd 0x10a29(%rip), %xmm1    # 0x217a8
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 0x10ced
movapd %xmm0, %xmm2
subsd %xmm5, %xmm2
mulsd %xmm3, %xmm2
jmp 0x10ce9