// File: /workspace/github_cpp_makefile_star2_O3/harry830622[P]floorplanner/src/floorplanner.cpp
// Function: Floorplanner::Floorplanner(Database const&, double, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, bool, bool)
Floorplanner::Floorplanner(const Database& database, double alpha,
                           const string& sa_mode, bool is_verbose,
                           bool is_drawing)
    : database_(database),
      alpha_(alpha),
      sa_mode_(sa_mode),
      is_verbose_(is_verbose),
      is_drawing_(is_drawing),
      min_area_(numeric_limits<double>::max()),
      max_area_(0.0),
      min_wirelength_(numeric_limits<double>::max()),
      max_wirelength_(0.0),
      average_area_(0.0),
      average_wirelength_(0.0),
      average_uphill_cost_(0.0),
      best_floorplan_(Floorplan(database_.num_macros(), is_drawing)),
      drawing_(Json::object()) {
  const int num_macros = database_.num_macros();
  const int num_perturbations = num_macros * num_macros;
  Floorplan floorplan(best_floorplan_);

  double total_area = 0.0;
  double total_wirelength = 0.0;
  for (int i = 0; i < num_perturbations; ++i) {
    floorplan.Perturb(database_);
    floorplan.Pack(database_);
    const double area = floorplan.area();
    const double wirelength = floorplan.wirelength();
    if (area < min_area_) {
      min_area_ = area;
    }
    if (area > max_area_) {
      max_area_ = area;
    }
    if (wirelength < min_wirelength_) {
      min_wirelength_ = wirelength;
    }
    if (wirelength > max_wirelength_) {
      max_wirelength_ = wirelength;
    }
    total_area += area;
    total_wirelength += wirelength;
  }
  average_area_ = total_area / num_perturbations;
  average_wirelength_ = total_wirelength / num_perturbations;

  double total_uphill_cost = 0.0;
  int num_uphills = 0;
  double adaptive_alpha = alpha_ / 4.0;
  double adaptive_beta = (1.0 - alpha_) / 4.0;
  double last_cost =
      ComputeCost(best_floorplan_, adaptive_alpha, adaptive_beta);
  for (int i = 0; i < num_perturbations; ++i) {
    floorplan.Perturb(database_);
    floorplan.Pack(database_);
    double cost = ComputeCost(floorplan, adaptive_alpha, adaptive_beta);
    double delta_cost = cost - last_cost;
    if (delta_cost > 0) {
      ++num_uphills;
      total_uphill_cost += delta_cost;
    }
    last_cost = cost;
  }
  average_uphill_cost_ = total_uphill_cost / num_uphills;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r12
movq %rsi, (%rdi)
movsd %xmm0, 0x8(%rdi)
leaq 0x10(%rdi), %r15
leaq 0x20(%rdi), %rbx
movq %rbx, 0x10(%rdi)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x9f1a
movb %r14b, 0x30(%r12)
movb %bpl, 0x31(%r12)
movsd 0x10ebe(%rip), %xmm0    # 0x21780
movupd %xmm0, 0x38(%r12)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x48(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%r12)
movupd %xmm0, 0x60(%r12)
movq (%r12), %rdi
callq 0x8a44
leaq 0x70(%r12), %r13
movzbl %bpl, %edx
movq %r13, %rdi
movl %eax, %esi
callq 0xad54
leaq 0x118(%r12), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xe11c
movq (%r12), %rdi
callq 0x8a44
movl %eax, %r14d
leaq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0x148ec
movq %rbp, 0x8(%rsp)
movq %r13, 0x48(%rsp)
movq %r15, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movl %r14d, %ebx
imull %r14d, %ebx
testl %r14d, %r14d
je 0x10a17
leaq 0x50(%r12), %r15
cmpl $0x1, %ebx
movl %ebx, %ebp
adcl $0x0, %ebp
xorpd %xmm1, %xmm1
leaq 0x60(%rsp), %r13
movapd %xmm1, 0x20(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xafba
movq (%r12), %rsi
movq %r13, %rdi
callq 0xba40
movq %r13, %rdi
callq 0xaf74
movapd %xmm0, 0x30(%rsp)
movq %r13, %rdi
callq 0xaf80
movsd 0x38(%r12), %xmm1
movapd 0x30(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x109c3
movsd %xmm2, 0x38(%r12)
ucomisd 0x40(%r12), %xmm2
jbe 0x109d9
movapd 0x30(%rsp), %xmm1
movsd %xmm1, 0x40(%r12)
movsd 0x48(%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x109ed
movsd %xmm0, 0x48(%r12)
ucomisd (%r15), %xmm0
movapd 0x20(%rsp), %xmm1
jbe 0x109ff
movsd %xmm0, (%r15)
movapd 0x30(%rsp), %xmm2
unpcklpd %xmm0, %xmm2            # xmm2 = xmm2[0],xmm0[0]
addpd %xmm2, %xmm1
decl %ebp
jne 0x10975
jmp 0x10a1b
xorpd %xmm1, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
divpd %xmm0, %xmm1
movupd %xmm1, 0x58(%r12)
movsd 0x8(%r12), %xmm0
movsd 0x10d48(%rip), %xmm2    # 0x21788
movsd 0x10d48(%rip), %xmm1    # 0x21790
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movq %r12, %rdi
movq 0x48(%rsp), %rsi
movsd %xmm0, 0x58(%rsp)
movsd %xmm1, 0x50(%rsp)
callq 0x10c42
testl %r14d, %r14d
je 0x10b12
movapd %xmm0, %xmm1
cmpl $0x1, %ebx
adcl $0x0, %ebx
xorl %ebp, %ebp
leaq 0x60(%rsp), %r13
xorpd %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x30(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xafba
movq (%r12), %rsi
movq %r13, %rdi
callq 0xba40
movq %r12, %rdi
movq %r13, %rsi
movsd 0x58(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
callq 0x10c42
movapd %xmm0, %xmm1
subsd 0x30(%rsp), %xmm1
xorl %eax, %eax
ucomisd 0x10cc6(%rip), %xmm1    # 0x217a0
seta %cl
jbe 0x10aef
movsd 0x20(%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, 0x20(%rsp)
movb %cl, %al
addl %eax, %ebp
movapd %xmm0, %xmm1
decl %ebx
jne 0x10a91
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x10b1a
movsd 0x10c7e(%rip), %xmm0    # 0x21798
movsd %xmm0, 0x68(%r12)
leaq 0xf8(%rsp), %rbx
movq %rbx, %rdi
callq 0xe0aa
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x10b4a
movq 0xf0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x10b8f
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
xorl %eax, %eax
movq %rax, 0xb8(%rsp)
movl %eax, 0xc0(%rsp)
movq %rax, 0xc8(%rsp)
movl %eax, 0xd0(%rsp)
movq %rax, 0xd8(%rsp)
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x10bac
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x10bc9
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10bf6
jmp 0x10bdf
movq %rax, %r12
jmp 0x10c17
movq %rax, %r12
jmp 0x10c1f
movq %rax, %r12
jmp 0x10c27
jmp 0x10bf6
jmp 0x10bf6
jmp 0x10bf6
jmp 0x10bf6
movq %rax, %r12
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rbp
leaq 0x60(%rsp), %rdi
callq 0x149e4
movq 0x48(%rsp), %r13
movq %rbp, %rdi
callq 0xe0aa
movq %r13, %rdi
callq 0x149e4
movq (%r15), %rdi
cmpq %rbx, %rdi
je 0x10c3a
movq (%rbx), %rsi
incq %rsi
callq 0x6390
movq %r12, %rdi
callq 0x6640