// File: /workspace/github_cpp_makefile_star2_O2/ATOMIC-LICHESS[P]ATOMKRAFT/search.cpp
// Function: (anonymous namespace)::do_skill_level(Move*, Move*)
void do_skill_level(Move* best, Move* ponder) {

    assert(MultiPV > 1);

    static RKISS rk;

    // Rml list is already sorted by pv_score in descending order
    int s;
    int max_s = -VALUE_INFINITE;
    int size = Min(MultiPV, (int)Rml.size());
    int max = Rml[0].pv_score;
    int var = Min(max - Rml[size - 1].pv_score, PawnValueMidgame);
    int wk = 120 - 2 * SkillLevel;

    // PRNG sequence should be non deterministic
    for (int i = abs(get_system_time() % 50); i > 0; i--)
        rk.rand<unsigned>();

    // Choose best move. For each move's score we add two terms both dependent
    // on wk, one deterministic and bigger for weaker moves, and one random,
    // then we choose the move with the resulting highest score.
    for (int i = 0; i < size; i++)
    {
        s = Rml[i].pv_score;

        // Don't allow crazy blunders even at very low skills
        if (i > 0 && Rml[i-1].pv_score > s + EasyMoveMargin)
            break;

        // This is our magical formula
        s += ((max - s) * wk + var * (rk.rand<unsigned>() % wk)) / 128;

        if (s > max_s)
        {
            max_s = s;
            *best = Rml[i].pv[0];
            *ponder = Rml[i].pv[1];
        }
    }
  }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movb 0x39b08b(%rip), %al     # 0x3b9a68
testb %al, %al
je 0x1eb26
movl 0x399051(%rip), %ecx    # 0x3b7a3c
movq 0x395afe(%rip), %rax    # 0x3b44f0
movq 0x395aef(%rip), %rsi    # 0x3b44e8
subq %rsi, %rax
movl $0x1a8, %edi            # imm = 0x1A8
cqto
idivq %rdi
movq %rax, %r15
cmpl %r15d, %ecx
cmovll %ecx, %r15d
movl 0x8(%rsi), %eax
movl %eax, 0xc(%rsp)
movslq %r15d, %rax
imulq $0x1a8, %rax, %rax      # imm = 0x1A8
movl -0x1a0(%rsi,%rax), %r13d
leaq 0x16a18(%rip), %rax     # 0x35448
movl (%rax), %r14d
movl 0x398ffb(%rip), %ebx    # 0x3b7a34
addl %ebx, %ebx
callq 0x130ea
pushq $0x32
popq %rcx
cqto
idivq %rcx
movq %rdx, %rbp
negq %rbp
cmovsq %rdx, %rbp
leaq 0x39afef(%rip), %r12    # 0x3b9a48
testl %ebp, %ebp
jle 0x1ea69
movq %r12, %rdi
callq 0x8bc8
decl %ebp
jmp 0x1ea59
movl 0xc(%rsp), %r12d
subl %r13d, %r12d
cmpl %r14d, %r12d
cmovgel %r14d, %r12d
pushq $0x78
popq %r13
subl %ebx, %r13d
xorl %ebx, %ebx
testl %r15d, %r15d
cmovlel %ebx, %r15d
imulq $0x1a8, %r15, %rax      # imm = 0x1A8
movq %rax, 0x20(%rsp)
movl $0xffff8acf, %r15d      # imm = 0xFFFF8ACF
cmpq %rbx, 0x20(%rsp)
je 0x1eb17
movq 0x395a40(%rip), %rax    # 0x3b44e8
movl 0x8(%rax,%rbx), %ebp
testq %rbx, %rbx
je 0x1eac0
leal 0x200(%rbp), %ecx
cmpl %ecx, -0x1a0(%rax,%rbx)
jg 0x1eb17
movl 0xc(%rsp), %r14d
subl %ebp, %r14d
imull %r13d, %r14d
leaq 0x39af75(%rip), %rdi    # 0x3b9a48
callq 0x8bc8
xorl %edx, %edx
divl %r13d
imull %r12d, %edx
addl %r14d, %edx
shrl $0x7, %edx
addl %ebp, %edx
cmpl %r15d, %edx
jle 0x1eb0e
movq 0x3959f3(%rip), %rax    # 0x3b44e8
movl 0x10(%rax,%rbx), %ecx
movq 0x10(%rsp), %rsi
movl %ecx, (%rsi)
movl 0x14(%rax,%rbx), %eax
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
movl %edx, %r15d
addq $0x1a8, %rbx            # imm = 0x1A8
jmp 0x1ea9a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39af3b(%rip), %rdi    # 0x3b9a68
callq 0x57b0
testl %eax, %eax
je 0x1e9e5
leaq 0x39af07(%rip), %rdi    # 0x3b9a48
callq 0x8b8e
leaq 0x39af1b(%rip), %rdi    # 0x3b9a68
callq 0x5240
jmp 0x1e9e5
movq %rax, %rbx
leaq 0x39af07(%rip), %rdi    # 0x3b9a68
callq 0x5230
movq %rbx, %rdi
callq 0x5780