// File: /workspace/github_cpp_makefile_star2_O1/ATOMIC-LICHESS[P]ATOMKRAFT/movepick.cpp
// Function: MovePicker::get_next_move()
Move MovePicker::get_next_move() {

  Move move;

  while (true)
  {
      while (curMove == lastMove)
          go_next_phase();

      switch (phase) {

      case PH_TT_MOVES:
          move = (curMove++)->move;
          
          if (   move != MOVE_NONE
              && pos.move_is_legal(move, pinned))
              return move;
          break;

      case PH_GOOD_CAPTURES:
          move = pick_best(curMove++, lastMove).move;
          if (   move != ttMoves[0].move
              && move != ttMoves[1].move
              && pos.pl_move_is_legal(move, pinned))
          {
              // Check for a non negative SEE now
              int seeValue = pos.see_sign(move);
              if (seeValue >= badCaptureThreshold)
                  return move;

              // Losing capture, move it to the tail of the array, note
              // that move has now been already checked for legality.
              (--badCaptures)->move = move;
              badCaptures->score = seeValue;
          }
          break;

      case PH_KILLERS:
          move = (curMove++)->move;
          if (   move != MOVE_NONE
              && pos.move_is_legal(move, pinned)
              && move != ttMoves[0].move
              && move != ttMoves[1].move
              && !pos.move_is_capture(move))
              return move;
          break;

      case PH_NONCAPTURES:
          // Sort negative scored moves only when we get there
          if (curMove == lastGoodNonCapture)
              insertion_sort<MoveStack>(lastGoodNonCapture, lastMove);

          move = (curMove++)->move;
          if (   move != ttMoves[0].move
              && move != ttMoves[1].move
              && move != killers[0].move
              && move != killers[1].move
              && pos.pl_move_is_legal(move, pinned))
              return move;
          break;

      case PH_BAD_CAPTURES:
          move = pick_best(curMove++, lastMove).move;
          return move;

      case PH_EVASIONS:
      case PH_QCAPTURES:
          move = pick_best(curMove++, lastMove).move;
          if (move != ttMoves[0].move && pos.pl_move_is_legal(move, pinned)) {
              return move;
          }
          break;

      case PH_QCHECKS:
          move = (curMove++)->move;
          if (   move != ttMoves[0].move
              && pos.pl_move_is_legal(move, pinned))
              return move;
          break;

      case PH_STOP:
          return MOVE_NONE;

      default:
          assert(false);
          break;
      }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x162e3(%rip), %r15     # 0x31924
movq 0x48(%rbx), %rdx
movq 0x50(%rbx), %rax
cmpq %rax, %rdx
jne 0x1b658
movq %rbx, %rdi
callq 0x1b214
jmp 0x1b641
movl 0x3c(%rbx), %ecx
cmpq $0x8, %rcx
ja 0x1b641
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
leaq 0x8(%rdx), %rcx
movq %rcx, 0x48(%rbx)
movq (%rdx), %r14
cmpq %rax, %rcx
je 0x1b6a6
movq %r14, %rdx
shrq $0x20, %rdx
cmpl 0x4(%rcx), %edx
jge 0x1b69d
movl %r14d, %esi
movq (%rcx), %r14
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%rcx)
movq %r14, %rdx
shrq $0x20, %rdx
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x1b681
cmpl %r14d, 0x18(%rbx)
je 0x1b641
jmp 0x1b7d3
leaq 0x8(%rdx), %rax
movq %rax, 0x48(%rbx)
movl (%rdx), %r14d
cmpl 0x18(%rbx), %r14d
je 0x1b641
jmp 0x1b7d3
leaq 0x8(%rdx), %rax
movq %rax, 0x48(%rbx)
movl (%rdx), %r14d
testq %r14, %r14
je 0x1b641
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
movl %r14d, %esi
callq 0x1e81a
testb %al, %al
je 0x1b641
cmpl 0x18(%rbx), %r14d
je 0x1b641
cmpl 0x20(%rbx), %r14d
je 0x1b641
testl $0x18000, %r14d         # imm = 0x18000
je 0x1b8b2
movl %r14d, %eax
notl %eax
testl $0xc000, %eax           # imm = 0xC000
jmp 0x1b8bf
movq 0x58(%rbx), %rcx
cmpq %rcx, %rdx
jne 0x1b79c
cmpq %rax, %rcx
sete %dl
leaq 0x8(%rcx), %r8
cmpq %rax, %r8
sete %sil
orb %dl, %sil
jne 0x1b79c
movl $0x8, %edx
movq %rcx, %rsi
movq %rsi, %r9
movq 0x8(%rsi), %rdi
movq %r8, %rsi
movq %rdi, %r8
shrq $0x20, %r8
cmpl %r8d, 0x4(%r9)
jge 0x1b78f
movq %rdx, %r10
movq -0x8(%rcx,%r10), %r9
movq %r9, (%rcx,%r10)
cmpq $0x8, %r10
je 0x1b789
leaq -0x8(%r10), %r9
cmpl %r8d, -0xc(%rcx,%r10)
movq %r9, %r10
jl 0x1b767
addq %rcx, %r9
jmp 0x1b78c
movq %rcx, %r9
movq %rdi, (%r9)
leaq 0x8(%rsi), %r8
addq $0x8, %rdx
cmpq %rax, %r8
jne 0x1b74d
movq 0x48(%rbx), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x48(%rbx)
movl (%rax), %r14d
cmpl 0x18(%rbx), %r14d
je 0x1b641
cmpl 0x20(%rbx), %r14d
je 0x1b641
cmpl 0x28(%rbx), %r14d
je 0x1b641
cmpl 0x30(%rbx), %r14d
je 0x1b641
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
movl %r14d, %esi
callq 0x1e44a
jmp 0x1b807
leaq 0x8(%rdx), %rax
movq %rax, 0x48(%rbx)
movl (%rdx), %r14d
testl %r14d, %r14d
je 0x1b641
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
movl %r14d, %esi
callq 0x1e81a
testb %al, %al
je 0x1b641
jmp 0x1b90d
leaq 0x8(%rdx), %rcx
movq %rcx, 0x48(%rbx)
movq (%rdx), %r14
cmpq %rax, %rcx
je 0x1b850
movq %r14, %rdx
shrq $0x20, %rdx
cmpl 0x4(%rcx), %edx
jge 0x1b847
movl %r14d, %esi
movq (%rcx), %r14
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%rcx)
movq %r14, %rdx
shrq $0x20, %rdx
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x1b82b
cmpl %r14d, 0x18(%rbx)
je 0x1b641
cmpl %r14d, 0x20(%rbx)
je 0x1b641
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
movl %r14d, %esi
callq 0x1e44a
testb %al, %al
je 0x1b641
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x2073c
movl 0x38(%rbx), %ecx
cmpl %ecx, %eax
jge 0x1b8a2
movq 0x60(%rbx), %rdx
leaq -0x8(%rdx), %rsi
movq %rsi, 0x60(%rbx)
movl %r14d, -0x8(%rdx)
movl %eax, -0x4(%rdx)
jmp 0x1b8a5
movl %r14d, %ebp
movl %ebp, %r14d
cmpl %ecx, %eax
jl 0x1b641
jmp 0x1b90d
movq (%rbx), %rax
movl %r14d, %ecx
andl $0x3f, %ecx
cmpl $0x10, (%rax,%rcx,4)
setne %al
testb %al, %al
jne 0x1b641
jmp 0x1b90d
xorl %r14d, %r14d
jmp 0x1b90d
leaq 0x8(%rdx), %rcx
movq %rcx, 0x48(%rbx)
movq (%rdx), %r14
cmpq %rax, %rcx
je 0x1b90d
movq %r14, %rdx
shrq $0x20, %rdx
cmpl 0x4(%rcx), %edx
jge 0x1b904
movl %r14d, %esi
movq (%rcx), %r14
shlq $0x20, %rdx
orq %rdx, %rsi
movq %rsi, (%rcx)
movq %r14, %rdx
shrq $0x20, %rdx
addq $0x8, %rcx
cmpq %rax, %rcx
jne 0x1b8e8
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nop