// File: /workspace/github_cpp_makefile_star2_O2/czinn[P]homeworlds/negamax.cc
// Function: Negamax::get_actions(int)
std::vector<Action> Negamax::get_actions(int depth) {
  if (depth == 0 || root_game->winner() != 0) {
    return std::vector<Action>({Action{PASS}});
  }

  int best = -10000000;
  const Turn *best_turn;
  std::vector<Turn*> turns = get_turns(root_game);
  std::sort(turns.begin(), turns.end(),
      [this](const Turn *a, const Turn *b) {
        int ha = a->game->hash();
        int hb = b->game->hash();
        int sa = this->transpositions.count(ha) > 0 ? this->transpositions[ha].value : 0;
        int sb = this->transpositions.count(hb) > 0 ? this->transpositions[hb].value : 0;
        return sa < sb;
      });
  int a = -10000000;
  int b = 10000000;
  for (const Turn *turn : turns) {
    int value = -negamax(turn->game, depth - 1, -b, -a);
    if (value > best) {
      best = value;
      best_turn = turn;
    }
    /*
    std::cout << "Value: " << value << std::endl;
    for (const Action& action : turn->actions) {
      std::cout << action << std::endl;
    }
    std::cout << std::endl;
    */
    a = std::max(a, value);
    if (a >= b) {
      break;
    }
  }

  std::vector<Action> actions(best_turn->actions.begin(), best_turn->actions.end());
  for (Turn *turn : turns) {
    delete turn;
  }
  return actions;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbp
movl %edx, 0x1c(%rsp)
testl %edx, %edx
je 0x5877
movq %rsi, %rbx
movq (%rsi), %rdi
callq 0x2754
testl %eax, %eax
je 0x589b
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
pushq $0x1
popq %rdx
leaq 0xf(%rsp), %rcx
movq %rbp, %rdi
callq 0x6936
jmp 0x5a11
movq (%rbx), %rdx
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %rbx, 0x10(%rsp)
movq %rbx, %rsi
callq 0x5a42
movq (%r15), %r12
movq 0x8(%r15), %r15
cmpq %r15, %r12
je 0x5932
movq %r15, %rbx
subq %r12, %rbx
movq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r12, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rcx
callq 0x6018
cmpq $0x81, %rbx
jl 0x5922
leaq 0x80(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq 0x10(%rsp), %rdx
callq 0x63ca
cmpq %r15, %r13
je 0x5932
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x6455
addq $0x8, %r13
jmp 0x590a
movq %r12, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %rdx
callq 0x63ca
movq %rbp, 0x48(%rsp)
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %r13
decl 0x1c(%rsp)
movl $0xff676980, %ebx       # imm = 0xFF676980
movl $0xff676980, %ebp       # imm = 0xFF676980
cmpq %r13, %r12
je 0x5995
movq (%r12), %r14
movq (%r14), %rsi
movl %ebx, %r8d
negl %r8d
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %edx
movl $0xff676980, %ecx       # imm = 0xFF676980
callq 0x5d0e
movl %eax, %ecx
negl %ecx
cmpl %ecx, %ebp
cmovlq %r14, %r15
cmpl $0xff676980, %eax       # imm = 0xFF676980
jle 0x5995
cmpl %ecx, %ebx
cmovlel %ecx, %ebx
cmpl %ecx, %ebp
cmovlel %ecx, %ebp
addq $0x8, %r12
jmp 0x594f
movups 0x18(%r15), %xmm0
leaq 0x70(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x28(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
movups 0x38(%r15), %xmm0
leaq 0x50(%rsp), %rdx
movaps %xmm0, (%rdx)
movups 0x48(%r15), %xmm0
movaps %xmm0, 0x10(%rdx)
leaq 0xf(%rsp), %rcx
movq 0x48(%rsp), %rbp
movq %rbp, %rdi
callq 0x6970
movq 0x20(%rsp), %rbx
movq 0x28(%rsp), %r12
pushq $0x58
popq %r14
cmpq %r12, %rbx
je 0x5a07
movq (%rbx), %r15
testq %r15, %r15
je 0x59f6
movq %r15, %rdi
callq 0x57f0
movq %r15, %rdi
movq %r14, %rsi
callq 0x21f0
addq $0x8, %rbx
jmp 0x59e1
leaq 0x20(%rsp), %rdi
callq 0x6ee6
movq %rbp, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5a2c
jmp 0x5a2c
jmp 0x5a2c
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x6ee6
movq %rbx, %rdi
callq 0x2300
nop