// File: /workspace/github_cpp_makefile_star2_O1/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 0x5a5f
movq %rsi, %r14
movq (%rsi), %rdi
callq 0x2822
testl %eax, %eax
je 0x5a95
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 0x6f1c
movq %r12, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, 0x38(%rsp)
movq (%r14), %rdx
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x5c5c
movq (%r15), %r12
movq 0x8(%r15), %r15
cmpq %r15, %r12
je 0x5b24
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 0x63c8
cmpq $0x81, %rbx
jl 0x5b16
leaq 0x80(%r12), %r13
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6828
cmpq %r15, %r13
je 0x5b24
movq %r13, %rdi
movq %r14, %rsi
callq 0x68b8
addq $0x8, %r13
jmp 0x5b00
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x6828
movq %r14, %r13
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %rax
movq %rax, 0x40(%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 0x607c
movl %eax, %ecx
negl %ecx
cmpl %ecx, %ebx
cmovlq %r14, %r15
cmpl $0xff676980, %eax       # imm = 0xFF676980
jle 0x5b88
cmpl %ecx, %ebp
cmovlel %ecx, %ebp
cmpl %ecx, %ebx
cmovlel %ecx, %ebx
addq $0x8, %r12
cmpq 0x40(%rsp), %r12
jne 0x5b44
movq 0x18(%r15), %rax
leaq 0x68(%rsp), %rsi
movq %rax, (%rsi)
movq 0x20(%r15), %rax
movq %rax, 0x8(%rsi)
movq 0x28(%r15), %rax
movq %rax, 0x10(%rsi)
movq 0x30(%r15), %rax
movq %rax, 0x18(%rsi)
movq 0x38(%r15), %rax
leaq 0x48(%rsp), %rdx
movq %rax, (%rdx)
movq 0x40(%r15), %rax
movq %rax, 0x8(%rdx)
movq 0x48(%r15), %rax
movq %rax, 0x10(%rdx)
movq 0x50(%r15), %rax
movq %rax, 0x18(%rdx)
leaq 0xb(%rsp), %rcx
movq 0x38(%rsp), %r12
movq %r12, %rdi
callq 0x6f64
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r15
cmpq %r15, %rbx
je 0x5c14
movq (%rbx), %r14
testq %r14, %r14
je 0x5c0e
movq %r14, %rdi
callq 0x59cc
movl $0x58, %esi
movq %r14, %rdi
callq 0x21d0
addq $0x8, %rbx
jmp 0x5bec
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5a80
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
jmp 0x5a80
jmp 0x5c3a
jmp 0x5c3a
jmp 0x5c3a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x5c54
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21d0
movq %rbx, %rdi
callq 0x22d0