// File: kobanium[P]Ray/src/mcts/SearchManager.cpp
// Function: CalculateNextPlayouts(game_info_t const*, int, double, double, int)
void
CalculateNextPlayouts( const game_info_t *game, const int color, const double best_wp, const double finish_time, const int threads )
{
  double po_per_sec;

  if (finish_time > 0.1) {
    po_per_sec = po_info.count / finish_time;
  } else {
    po_per_sec = PLAYOUT_SPEED * threads;
  }

  if (search_setting == SearchTimeStrategy::ConstantTimeMode) {
    if (best_wp > 0.95) {
      po_info.num = static_cast<int>(po_info.count / finish_time * const_thinking_time * 0.25);
    } else if (best_wp > 0.90) {
      po_info.num = static_cast<int>(po_info.count / finish_time * const_thinking_time * 0.50);
    } else {
      po_info.num = static_cast<int>(po_info.count / finish_time * const_thinking_time);

    }                     
  } else if (search_setting == SearchTimeStrategy::TimeControlMode ||
             search_setting == SearchTimeStrategy::TimeControlWithByoYomiMode) {
    ConsumeTime(color, finish_time);
    time_limit = CalculateNextTimeLimit(color, game->moves);
    if (search_setting == SearchTimeStrategy::TimeControlWithByoYomiMode &&
        time_limit < const_thinking_time) {
      time_limit = const_thinking_time * 0.85;
    }
    if (best_wp > 0.95) {
      time_limit *= 0.25;
    } else if (best_wp > 0.90) {
      time_limit *= 0.5;
    }
    po_info.num = static_cast<int>(po_per_sec * time_limit);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movsd %xmm0, -0x18(%rbp)
movsd %xmm1, -0x20(%rbp)
movl %edx, -0x24(%rbp)
movsd -0x20(%rbp), %xmm0
movsd 0x1cf77(%rip), %xmm1    # 0xac3c0
ucomisd %xmm1, %xmm0
jbe 0x8f46f
leaq 0x1aaeddae(%rip), %rdi  # 0x1ab7d204
addq $0x8, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
divsd -0x20(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x8f47f
imull $0x3e8, -0x24(%rbp), %eax # imm = 0x3E8
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x30(%rbp)
cmpl $0x1, 0x58592(%rip)     # 0xe7a18
jne 0x8f556
movsd -0x18(%rbp), %xmm0
movsd 0x1fe37(%rip), %xmm1    # 0xaf2d0
ucomisd %xmm1, %xmm0
jbe 0x8f4d8
leaq 0x1aaedd5e(%rip), %rdi  # 0x1ab7d204
addq $0x8, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
divsd -0x20(%rbp), %xmm0
mulsd 0x58570(%rip), %xmm0    # 0xe7a30
movsd 0x1fc78(%rip), %xmm1    # 0xaf140
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1aaedd2e(%rip)  # 0x1ab7d204
jmp 0x8f551
movsd -0x18(%rbp), %xmm0
movsd 0x1ea83(%rip), %xmm1    # 0xadf68
ucomisd %xmm1, %xmm0
jbe 0x8f524
leaq 0x1aaedd12(%rip), %rdi  # 0x1ab7d204
addq $0x8, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
divsd -0x20(%rbp), %xmm0
mulsd 0x58524(%rip), %xmm0    # 0xe7a30
movsd 0x1cafc(%rip), %xmm1    # 0xac010
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1aaedce2(%rip)  # 0x1ab7d204
jmp 0x8f54f
leaq 0x1aaedcd9(%rip), %rdi  # 0x1ab7d204
addq $0x8, %rdi
callq 0x25780
cvtsi2sd %eax, %xmm0
divsd -0x20(%rbp), %xmm0
mulsd 0x584eb(%rip), %xmm0    # 0xe7a30
cvttsd2si %xmm0, %eax
movl %eax, 0x1aaedcb5(%rip)  # 0x1ab7d204
jmp 0x8f551
jmp 0x8f63d
cmpl $0x2, 0x584bb(%rip)     # 0xe7a18
je 0x8f56c
cmpl $0x3, 0x584b2(%rip)     # 0xe7a18
jne 0x8f63b
movl -0xc(%rbp), %edi
movsd -0x20(%rbp), %xmm0
callq 0x8f650
movl -0xc(%rbp), %edi
movq -0x8(%rbp), %rax
movl 0x43b0(%rax), %esi
callq 0x8f2a0
movsd %xmm0, 0x1aaedc65(%rip) # 0x1ab7d1f8
cmpl $0x3, 0x5847e(%rip)     # 0xe7a18
jne 0x8f5ca
movsd 0x1aaedc54(%rip), %xmm1 # 0x1ab7d1f8
movsd 0x58484(%rip), %xmm0    # 0xe7a30
ucomisd %xmm1, %xmm0
jbe 0x8f5ca
movsd 0x1fd0e(%rip), %xmm0    # 0xaf2c8
mulsd 0x5846e(%rip), %xmm0    # 0xe7a30
movsd %xmm0, 0x1aaedc2e(%rip) # 0x1ab7d1f8
movsd -0x18(%rbp), %xmm0
movsd 0x1fcf9(%rip), %xmm1    # 0xaf2d0
ucomisd %xmm1, %xmm0
jbe 0x8f5f7
movsd 0x1fb5b(%rip), %xmm0    # 0xaf140
mulsd 0x1aaedc0b(%rip), %xmm0 # 0x1ab7d1f8
movsd %xmm0, 0x1aaedc03(%rip) # 0x1ab7d1f8
jmp 0x8f624
movsd -0x18(%rbp), %xmm0
movsd 0x1e964(%rip), %xmm1    # 0xadf68
ucomisd %xmm1, %xmm0
jbe 0x8f622
movsd 0x1c9fe(%rip), %xmm0    # 0xac010
mulsd 0x1aaedbde(%rip), %xmm0 # 0x1ab7d1f8
movsd %xmm0, 0x1aaedbd6(%rip) # 0x1ab7d1f8
jmp 0x8f624
movsd -0x30(%rbp), %xmm0
mulsd 0x1aaedbc7(%rip), %xmm0 # 0x1ab7d1f8
cvttsd2si %xmm0, %eax
movl %eax, 0x1aaedbc9(%rip)  # 0x1ab7d204
jmp 0x8f63d
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)