// File: harry830622[P]floorplanner/src/floorplanner.cpp
// Function: Floorplanner::Run()
void Floorplanner::Run() {
  if (sa_mode_ == "classical") {
    int nth_sa = 0;
    do {
      ++nth_sa;
      if (is_verbose_) {
        cout << nth_sa << " th SA" << endl;
      }

      SA();
    } while (best_floorplan_.area() == 0.0);
  } else if (sa_mode_ == "fast") {
    int nth_fsa = 0;
    do {
      ++nth_fsa;
      if (is_verbose_) {
        cout << nth_fsa << " th Fast SA" << endl;
      }

      FastSA();
    } while (best_floorplan_.area() == 0.0);
  } else if (sa_mode_ == "both") {
    Floorplan initial_floorplan(best_floorplan_);

    int nth_sa = 0;
    do {
      ++nth_sa;
      if (is_verbose_) {
        cout << nth_sa << " th SA" << endl;
      }

      SA();
    } while (best_floorplan_.area() == 0.0);
    Floorplan floorplan_sa(best_floorplan_);

    best_floorplan_ = initial_floorplan;
    int nth_fsa = 0;
    do {
      ++nth_fsa;
      if (is_verbose_) {
        cout << nth_fsa << " th Fast SA" << endl;
      }

      FastSA();
    } while (best_floorplan_.area() == 0.0);
    Floorplan floorplan_fsa(best_floorplan_);

    const double beta = 1.0 - alpha_;
    if (ComputeCost(floorplan_sa, alpha_, beta) <
        ComputeCost(floorplan_fsa, alpha_, beta)) {
      best_floorplan_ = floorplan_sa;
    } else {
      best_floorplan_ = floorplan_fsa;
    }
  } else if (sa_mode_ == "fast-5") {
    const int num_fsa = 5;

    Floorplan initial_floorplan(best_floorplan_);
    Floorplan best_floorplan(initial_floorplan);
    int nth_fsa = 0;
    for (int i = 0; i < num_fsa; ++i) {
      ++nth_fsa;

      if (is_verbose_) {
        cout << nth_fsa << " th Fast SA" << endl;
      }

      FastSA();

      if (best_floorplan_.area() != 0.0) {
        const double beta = 1.0 - alpha_;
        if (best_floorplan.area() == 0.0 ||
            ComputeCost(best_floorplan_, alpha_, beta) <
                ComputeCost(best_floorplan, alpha_, beta)) {
          best_floorplan = best_floorplan_;
        }
      }

      best_floorplan_ = initial_floorplan;
    }

    best_floorplan_ = best_floorplan;

    while (best_floorplan_.area() == 0.0) {
      ++nth_fsa;

      if (is_verbose_) {
        cout << nth_fsa << " th Fast SA" << endl;
      }

      FastSA();
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x3a0(%rbp)
addq $0x10, %rdi
leaq 0x22a0b(%rip), %rsi     # 0x4b2b0
callq 0x12880
testb $0x1, %al
jne 0x288b0
jmp 0x28928
movl $0x0, -0xc(%rbp)
movq -0x3a0(%rbp), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0xc(%rbp)
testb $0x1, 0x30(%rax)
je 0x288fa
movl -0xc(%rbp), %esi
movq 0x436c9(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, %rdi
leaq 0x229d4(%rip), %rsi     # 0x4b2ba
callq 0x94c0
movq %rax, %rdi
movq 0x43643(%rip), %rsi     # 0x6bf38
callq 0x9500
movq -0x3a0(%rbp), %rdi
callq 0x29070
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28923
jp 0x28923
jmp 0x288b7
jmp 0x29052
movq -0x3a0(%rbp), %rdi
addq $0x10, %rdi
leaq 0x22987(%rip), %rsi     # 0x4b2c1
callq 0x12880
testb $0x1, %al
jne 0x28945
jmp 0x289bd
movl $0x0, -0x10(%rbp)
movq -0x3a0(%rbp), %rax
movl -0x10(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x10(%rbp)
testb $0x1, 0x30(%rax)
je 0x2898f
movl -0x10(%rbp), %esi
movq 0x43634(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, %rdi
leaq 0x2294b(%rip), %rsi     # 0x4b2c6
callq 0x94c0
movq %rax, %rdi
movq 0x435ae(%rip), %rsi     # 0x6bf38
callq 0x9500
movq -0x3a0(%rbp), %rdi
callq 0x2a8d0
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x289b8
jp 0x289b8
jmp 0x2894c
jmp 0x29050
movq -0x3a0(%rbp), %rdi
addq $0x10, %rdi
leaq 0x22903(%rip), %rsi     # 0x4b2d2
callq 0x12880
testb $0x1, %al
jne 0x289dd
jmp 0x28cf8
movq -0x3a0(%rbp), %rsi
addq $0x70, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x2c3f0
movl $0x0, -0xbc(%rbp)
movq -0x3a0(%rbp), %rax
movl -0xbc(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0xbc(%rbp)
testb $0x1, 0x30(%rax)
je 0x28a7f
movl -0xbc(%rbp), %esi
movq 0x43579(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, -0x3a8(%rbp)
jmp 0x28a35
movq -0x3a8(%rbp), %rdi
leaq 0x22877(%rip), %rsi     # 0x4b2ba
callq 0x94c0
movq %rax, -0x3b0(%rbp)
jmp 0x28a51
movq -0x3b0(%rbp), %rdi
movq 0x434d9(%rip), %rsi     # 0x6bf38
callq 0x9500
jmp 0x28a66
jmp 0x28a7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x28ce7
movq -0x3a0(%rbp), %rdi
callq 0x29070
jmp 0x28a8d
jmp 0x28a8f
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
movsd %xmm0, -0x3b8(%rbp)
jmp 0x28aa9
movsd -0x3b8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28ac1
jp 0x28ac1
jmp 0x289fe
movq -0x3a0(%rbp), %rsi
addq $0x70, %rsi
leaq -0x178(%rbp), %rdi
callq 0x2c3f0
jmp 0x28ada
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x2c570
jmp 0x28af3
movl $0x0, -0x17c(%rbp)
movq -0x3a0(%rbp), %rax
movl -0x17c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x17c(%rbp)
testb $0x1, 0x30(%rax)
je 0x28b7e
movl -0x17c(%rbp), %esi
movq 0x4347a(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, -0x3c0(%rbp)
jmp 0x28b34
movq -0x3c0(%rbp), %rdi
leaq 0x22784(%rip), %rsi     # 0x4b2c6
callq 0x94c0
movq %rax, -0x3c8(%rbp)
jmp 0x28b50
movq -0x3c8(%rbp), %rdi
movq 0x433da(%rip), %rsi     # 0x6bf38
callq 0x9500
jmp 0x28b65
jmp 0x28b7e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x28cdb
movq -0x3a0(%rbp), %rdi
callq 0x2a8d0
jmp 0x28b8c
jmp 0x28b8e
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
movsd %xmm0, -0x3d0(%rbp)
jmp 0x28ba8
movsd -0x3d0(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28bc0
jp 0x28bc0
jmp 0x28afd
movq -0x3a0(%rbp), %rsi
addq $0x70, %rsi
leaq -0x228(%rbp), %rdi
callq 0x2c3f0
jmp 0x28bd9
movq -0x3a0(%rbp), %rdi
movsd 0x8(%rdi), %xmm1
movsd 0x2265b(%rip), %xmm0    # 0x4b248
subsd %xmm1, %xmm0
movsd %xmm0, -0x230(%rbp)
movsd 0x8(%rdi), %xmm0
movsd -0x230(%rbp), %xmm1
leaq -0x178(%rbp), %rsi
callq 0x285e0
movsd %xmm0, -0x3d8(%rbp)
jmp 0x28c1c
movq -0x3a0(%rbp), %rdi
movsd 0x8(%rdi), %xmm0
movsd -0x230(%rbp), %xmm1
leaq -0x228(%rbp), %rsi
callq 0x285e0
movsd %xmm0, -0x3e0(%rbp)
jmp 0x28c46
movsd -0x3e0(%rbp), %xmm0
movsd -0x3d8(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x28c97
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x178(%rbp), %rsi
callq 0x2c570
jmp 0x28c75
jmp 0x28cb2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x228(%rbp), %rdi
callq 0x2c510
jmp 0x28cdb
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x228(%rbp), %rsi
callq 0x2c570
jmp 0x28cb0
jmp 0x28cb2
leaq -0x228(%rbp), %rdi
callq 0x2c510
leaq -0x178(%rbp), %rdi
callq 0x2c510
leaq -0xb8(%rbp), %rdi
callq 0x2c510
jmp 0x2904e
leaq -0x178(%rbp), %rdi
callq 0x2c510
leaq -0xb8(%rbp), %rdi
callq 0x2c510
jmp 0x2905b
movq -0x3a0(%rbp), %rdi
addq $0x10, %rdi
leaq 0x22ee7(%rip), %rsi     # 0x4bbf1
callq 0x12880
testb $0x1, %al
jne 0x28d18
jmp 0x2904c
movq -0x3a0(%rbp), %rsi
movl $0x5, -0x234(%rbp)
addq $0x70, %rsi
leaq -0x2e0(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x2c3f0
movq -0x3e8(%rbp), %rsi
leaq -0x388(%rbp), %rdi
callq 0x2c3f0
jmp 0x28d55
movl $0x0, -0x38c(%rbp)
movl $0x0, -0x390(%rbp)
cmpl $0x5, -0x390(%rbp)
jge 0x28f5f
movq -0x3a0(%rbp), %rax
movl -0x38c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x38c(%rbp)
testb $0x1, 0x30(%rax)
je 0x28e1e
movl -0x38c(%rbp), %esi
movq 0x431fd(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, -0x3f0(%rbp)
jmp 0x28db1
movq -0x3f0(%rbp), %rdi
leaq 0x22507(%rip), %rsi     # 0x4b2c6
callq 0x94c0
movq %rax, -0x3f8(%rbp)
jmp 0x28dcd
movq -0x3f8(%rbp), %rdi
movq 0x4315d(%rip), %rsi     # 0x6bf38
callq 0x9500
jmp 0x28de2
jmp 0x28e1e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0x2903e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0x388(%rbp), %rdi
callq 0x2c510
jmp 0x2903e
movq -0x3a0(%rbp), %rdi
callq 0x2a8d0
jmp 0x28e2c
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
movsd %xmm0, -0x400(%rbp)
jmp 0x28e46
movsd -0x400(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28e5e
jp 0x28e5e
jmp 0x28f30
movq -0x3a0(%rbp), %rax
movsd 0x8(%rax), %xmm1
movsd 0x223d6(%rip), %xmm0    # 0x4b248
subsd %xmm1, %xmm0
movsd %xmm0, -0x398(%rbp)
leaq -0x388(%rbp), %rdi
callq 0x167c0
movsd %xmm0, -0x408(%rbp)
jmp 0x28e94
movsd -0x408(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x28ea9
jp 0x28ea9
jmp 0x28f13
movq -0x3a0(%rbp), %rdi
movq %rdi, %rsi
addq $0x70, %rsi
movsd 0x8(%rdi), %xmm0
movsd -0x398(%rbp), %xmm1
callq 0x285e0
movsd %xmm0, -0x410(%rbp)
jmp 0x28ed3
movq -0x3a0(%rbp), %rdi
movsd 0x8(%rdi), %xmm0
movsd -0x398(%rbp), %xmm1
leaq -0x388(%rbp), %rsi
callq 0x285e0
movsd %xmm0, -0x418(%rbp)
jmp 0x28efd
movsd -0x418(%rbp), %xmm0
movsd -0x410(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x28f2e
movq -0x3a0(%rbp), %rsi
addq $0x70, %rsi
leaq -0x388(%rbp), %rdi
callq 0x2c570
jmp 0x28f2c
jmp 0x28f2e
jmp 0x28f30
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x2e0(%rbp), %rsi
callq 0x2c570
jmp 0x28f49
jmp 0x28f4b
movl -0x390(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x390(%rbp)
jmp 0x28d69
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
leaq -0x388(%rbp), %rsi
callq 0x2c570
jmp 0x28f78
jmp 0x28f7a
movq -0x3a0(%rbp), %rdi
addq $0x70, %rdi
callq 0x167c0
movsd %xmm0, -0x420(%rbp)
jmp 0x28f94
movsd -0x420(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x29024
jp 0x29024
movq -0x3a0(%rbp), %rax
movl -0x38c(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x38c(%rbp)
testb $0x1, 0x30(%rax)
je 0x29011
movl -0x38c(%rbp), %esi
movq 0x42fd0(%rip), %rdi     # 0x6bfa0
callq 0x98c0
movq %rax, -0x428(%rbp)
jmp 0x28fde
movq -0x428(%rbp), %rdi
leaq 0x222da(%rip), %rsi     # 0x4b2c6
callq 0x94c0
movq %rax, -0x430(%rbp)
jmp 0x28ffa
movq -0x430(%rbp), %rdi
movq 0x42f30(%rip), %rsi     # 0x6bf38
callq 0x9500
jmp 0x2900f
jmp 0x29011
movq -0x3a0(%rbp), %rdi
callq 0x2a8d0
jmp 0x2901f
jmp 0x28f7a
leaq -0x388(%rbp), %rdi
callq 0x2c510
leaq -0x2e0(%rbp), %rdi
callq 0x2c510
jmp 0x2904c
leaq -0x2e0(%rbp), %rdi
callq 0x2c510
jmp 0x2905b
jmp 0x2904e
jmp 0x29050
jmp 0x29052
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
movq -0xc8(%rbp), %rdi
callq 0x98f0
nopw (%rax,%rax)