// File: 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 %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq (%rax), %rdi
callq 0xdd40
movq -0x70(%rbp), %rax
movsd %xmm0, -0x28(%rbp)
movq (%rax), %rdi
callq 0xdd60
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
callq 0x16780
movsd %xmm0, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0x167a0
movsd %xmm0, -0x40(%rbp)
movsd 0x22c14(%rip), %xmm0    # 0x4b258
movsd %xmm0, -0x48(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x38(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
ja 0x2866d
movsd -0x40(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x2877e
movsd -0x38(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x286c4
movsd -0x40(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x286c4
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd -0x30(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x28724
movsd -0x38(%rbp), %xmm0
ucomisd -0x28(%rbp), %xmm0
jbe 0x286f3
movsd -0x38(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd -0x40(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x28722
movsd -0x40(%rbp), %xmm0
ucomisd -0x30(%rbp), %xmm0
jbe 0x28720
movsd -0x38(%rbp), %xmm0
movsd -0x40(%rbp), %xmm2
subsd -0x30(%rbp), %xmm2
movsd -0x50(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x28722
jmp 0x28724
movq -0x70(%rbp), %rax
movsd -0x38(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd -0x38(%rbp), %xmm2
subsd -0x28(%rbp), %xmm2
movsd -0x40(%rbp), %xmm1
subsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm3
subsd -0x30(%rbp), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movsd 0x40(%rax), %xmm1
subsd 0x38(%rax), %xmm1
movsd -0x50(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x167c0
movq -0x70(%rbp), %rax
movsd 0x40(%rax), %xmm1
subsd 0x38(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x10(%rbp), %rdi
callq 0x167e0
movq -0x70(%rbp), %rax
movsd 0x50(%rax), %xmm1
subsd 0x48(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x18(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movsd -0x20(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd 0x22a66(%rip), %xmm0    # 0x4b248
subsd -0x18(%rbp), %xmm0
subsd -0x20(%rbp), %xmm0
movsd 0x22a64(%rip), %xmm2    # 0x4b258
mulsd %xmm2, %xmm0
movsd -0x50(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)