// File: /workspace/github_cpp_makefile_star2_O3/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 $0x88, %rsp
movq %rdi, %r12
movl %edx, 0xc(%rsp)
testl %edx, %edx
je 0x596b
movq %rsi, %r14
movq (%rsi), %rdi
callq 0x283e
testl %eax, %eax
je 0x59a1
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq 0xb(%rsp), %rcx
movl $0x1, %edx
movq %r12, %rdi
callq 0x6d80
movq %r12, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0x30(%rsp)
movq (%r14), %rdx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5b52
movq (%r15), %r12
movq 0x8(%r15), %r15
cmpq %r15, %r12
je 0x5a30
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 %r14, %rcx
callq 0x62e6
cmpq $0x81, %rbx
jl 0x5a22
leaq 0x80(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x66fb
cmpq %r15, %r13
je 0x5a30
movq %r13, %rdi
movq %r14, %rsi
callq 0x677a
addq $0x8, %r13
jmp 0x5a0c
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x66fb
movq %r14, %r13
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
decl 0xc(%rsp)
movl $0xff676980, %ebx       # imm = 0xFF676980
movl $0xff676980, %ebp       # imm = 0xFF676980
movq (%r12), %r14
movq (%r14), %rsi
movl %ebp, %r8d
negl %r8d
movq %r13, %rdi
movl 0xc(%rsp), %edx
movl $0xff676980, %ecx       # imm = 0xFF676980
callq 0x5f9e
movl %eax, %ecx
negl %ecx
cmpl %ecx, %ebx
cmovlq %r14, %r15
cmpl $0xff676980, %eax       # imm = 0xFF676980
jle 0x5a94
cmpl %ecx, %ebp
cmovlel %ecx, %ebp
cmpl %ecx, %ebx
cmovlel %ecx, %ebx
addq $0x8, %r12
cmpq 0x38(%rsp), %r12
jne 0x5a50
movups 0x18(%r15), %xmm0
leaq 0x60(%rsp), %rsi
movaps %xmm0, (%rsi)
movups 0x28(%r15), %xmm0
movaps %xmm0, 0x10(%rsi)
movups 0x38(%r15), %xmm0
leaq 0x40(%rsp), %rdx
movaps %xmm0, (%rdx)
movups 0x48(%r15), %xmm0
movaps %xmm0, 0x10(%rdx)
leaq 0xb(%rsp), %rcx
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x6dc8
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
je 0x5b0c
movq (%r14), %r15
testq %r15, %r15
je 0x5af1
movq %r15, %rdi
callq 0x58d8
movl $0x58, %esi
movq %r15, %rdi
callq 0x21d0
addq $0x8, %r14
cmpq %rbx, %r14
jne 0x5ae1
movq 0x10(%rsp), %r14
testq %r14, %r14
je 0x598c
movq 0x20(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x21d0
jmp 0x598c
jmp 0x5b30
jmp 0x5b30
jmp 0x5b30
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5b4a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22d0