// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r12
movq %rsi, (%rdi)
movsd %xmm0, 0x8(%rdi)
leaq 0x10(%rdi), %r13
leaq 0x20(%rdi), %rbx
movq %rbx, 0x10(%rdi)
movq (%rdx), %rsi
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x9912
movb %r14b, 0x30(%r12)
movb %bpl, 0x31(%r12)
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x38(%r12)
movq $0x0, 0x40(%r12)
movq %rax, 0x48(%r12)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x50(%r12)
movupd %xmm0, 0x60(%r12)
movq (%r12), %rdi
callq 0x8404
leaq 0x70(%r12), %r14
movzbl %bpl, %edx
movq %r14, %rdi
movl %eax, %esi
callq 0xa74c
leaq 0x118(%r12), %rbp
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0xe168
movq (%r12), %rdi
callq 0x8404
movl %eax, %r15d
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x149a6
movq %rbp, 0x8(%rsp)
movq %r14, 0x28(%rsp)
movq %r13, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
movl %r15d, %ebx
imull %r15d, %ebx
testl %r15d, %r15d
je 0x10a21
cmpl $0x1, %ebx
movl %ebx, %ebp
adcl $0x0, %ebp
leaq 0x50(%r12), %r14
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
leaq 0x40(%rsp), %r13
xorpd %xmm1, %xmm1
movsd %xmm1, 0x30(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xa924
movq (%r12), %rsi
movq %r13, %rdi
callq 0xb4e8
movq %r13, %rdi
callq 0xa8de
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
callq 0xa8ea
movsd 0x38(%r12), %xmm1
movsd 0x20(%rsp), %xmm2
ucomisd %xmm2, %xmm1
jbe 0x109c7
movsd %xmm2, 0x38(%r12)
ucomisd 0x40(%r12), %xmm2
jbe 0x109dd
movsd 0x20(%rsp), %xmm1
movsd %xmm1, 0x40(%r12)
movsd 0x48(%r12), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x109f1
movsd %xmm0, 0x48(%r12)
ucomisd (%r14), %xmm0
movsd 0x30(%rsp), %xmm1
jbe 0x10a03
movsd %xmm0, (%r14)
movsd (%rsp), %xmm2
addsd 0x20(%rsp), %xmm2
movsd %xmm2, (%rsp)
addsd %xmm0, %xmm1
decl %ebp
jne 0x10979
jmp 0x10a2e
xorpd %xmm1, %xmm1
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd (%rsp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x58(%r12)
divsd %xmm0, %xmm1
movsd %xmm1, 0x60(%r12)
movsd 0x8(%r12), %xmm0
movsd 0x10c71(%rip), %xmm2    # 0x216d0
movsd 0x10c71(%rip), %xmm1    # 0x216d8
subsd %xmm0, %xmm1
mulsd %xmm2, %xmm0
mulsd %xmm2, %xmm1
movq %r12, %rdi
movq 0x28(%rsp), %r14
movq %r14, %rsi
movsd %xmm0, 0x30(%rsp)
movsd %xmm1, 0x38(%rsp)
callq 0x10c68
testl %r15d, %r15d
je 0x10b30
movapd %xmm0, %xmm1
cmpl $0x1, %ebx
adcl $0x0, %ebx
xorl %ebp, %ebp
leaq 0x40(%rsp), %r13
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm1, 0x20(%rsp)
movq (%r12), %rsi
movq %r13, %rdi
callq 0xa924
movq (%r12), %rsi
movq %r13, %rdi
callq 0xb4e8
movq %r12, %rdi
movq %r13, %rsi
movsd 0x30(%rsp), %xmm0
movsd 0x38(%rsp), %xmm1
callq 0x10c68
movapd %xmm0, %xmm1
subsd 0x20(%rsp), %xmm1
xorl %eax, %eax
ucomisd 0x10bed(%rip), %xmm1    # 0x216e8
seta %cl
jbe 0x10b0e
movsd (%rsp), %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%rsp)
movb %cl, %al
addl %eax, %ebp
movapd %xmm0, %xmm1
decl %ebx
jne 0x10ab2
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
jmp 0x10b38
movsd 0x10ba8(%rip), %xmm0    # 0x216e0
movsd %xmm0, 0x68(%r12)
leaq 0xd8(%rsp), %rbx
movq %rbx, %rdi
callq 0xe0e0
movq -0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x10b68
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x10bad
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
xorl %eax, %eax
movq %rax, 0x98(%rsp)
movl %eax, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
movl %eax, 0xb0(%rsp)
movq %rax, 0xb8(%rsp)
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x10bca
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x10be1
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x6390
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x10c0c
jmp 0x10bf7
movq %rax, %r12
jmp 0x10c3c
movq %rax, %r12
jmp 0x10c44
movq %rax, %r12
jmp 0x10c4c
jmp 0x10c0c
jmp 0x10c1b
jmp 0x10c1b
movq %rax, %r12
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r13
jmp 0x10c2d
movq %rax, %r12
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r13
movq 0x28(%rsp), %r14
movq 0x8(%rsp), %rbp
leaq 0x40(%rsp), %rdi
callq 0x14a9e
movq %rbp, %rdi
callq 0xe0e0
movq %r14, %rdi
callq 0x14a9e
movq (%r13), %rdi
cmpq %rbx, %rdi
je 0x10c60
movq (%rbx), %rsi
incq %rsi
callq 0x6390
movq %r12, %rdi
callq 0x6640