// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rsi, 0x10(%rsp)
movq %rdi, 0x8(%rsp)
movb 0x39aff2(%rip), %al     # 0x3c0a68
testb %al, %al
je 0x25c87
movl 0x398fb8(%rip), %eax    # 0x3bea3c
movq 0x395a65(%rip), %rcx    # 0x3bb4f0
movq 0x395a56(%rip), %rdx    # 0x3bb4e8
subq %rdx, %rcx
shrq $0x3, %rcx
imull $0x8c13521d, %ecx, %r12d # imm = 0x8C13521D
cmpl %r12d, %eax
cmovll %eax, %r12d
movl 0x8(%rdx), %r14d
movslq %r12d, %rax
imulq $0x1a8, %rax, %rax      # imm = 0x1A8
movl %r14d, %r15d
subl -0x1a0(%rdx,%rax), %r15d
leaq 0x16981(%rip), %rax     # 0x3c448
movl (%rax), %eax
cmpl %eax, %r15d
cmovgel %eax, %r15d
movl 0x398f5d(%rip), %r13d   # 0x3bea34
callq 0x16e80
movq %rax, %rcx
movabsq $-0x5c28f5c28f5c28f5, %rdx # imm = 0xA3D70A3D70A3D70B
imulq %rdx
addq %rcx, %rdx
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x5, %rdx
addq %rax, %rdx
imulq $0x32, %rdx, %rax
subq %rax, %rcx
je 0x25b81
movq 0x39af53(%rip), %rax    # 0x3c0a60
movq 0x39af44(%rip), %rdx    # 0x3c0a58
movq 0x39af35(%rip), %rsi    # 0x3c0a50
movq 0x39af26(%rip), %rdi    # 0x3c0a48
movq %rcx, %r8
negq %r8
cmovsq %rcx, %r8
incl %r8d
movq %rsi, %rcx
rolq $0x7, %rcx
movq %rdi, %r9
movq %rdx, %rdi
rolq $0xd, %rdi
xorq %rsi, %rdi
movq %rax, %rsi
rolq $0x25, %rsi
subq %rcx, %r9
addq %rdx, %rsi
movq %rax, %rdx
addq %r9, %rdx
movq %r9, %rax
addq %rdi, %rax
decl %r8d
cmpl $0x1, %r8d
jg 0x25b2f
movq %rdi, 0x39aedc(%rip)    # 0x3c0a48
movq %rsi, 0x39aedd(%rip)    # 0x3c0a50
movq %rdx, 0x39aede(%rip)    # 0x3c0a58
movq %rax, 0x39aedf(%rip)    # 0x3c0a60
testl %r12d, %r12d
jle 0x25c78
addl %r13d, %r13d
movl $0x78, %esi
subl %r13d, %esi
movq 0x39aec4(%rip), %rdi    # 0x3c0a60
movq 0x39aeb5(%rip), %rax    # 0x3c0a58
movq 0x39aea6(%rip), %r10    # 0x3c0a50
movq 0x39ae97(%rip), %r9     # 0x3c0a48
movq 0x395930(%rip), %r8     # 0x3bb4e8
movl %r12d, %ecx
imulq $0x1a8, %rcx, %r11      # imm = 0x1A8
movl $0xffff8acf, %r13d      # imm = 0xFFFF8ACF
xorl %r12d, %r12d
movl 0x8(%r8,%r12), %ebx
testq %r12, %r12
je 0x25be9
leal 0x200(%rbx), %ecx
cmpl %ecx, -0x1a0(%r8,%r12)
jg 0x25c78
movl %r14d, %ebp
subl %ebx, %ebp
imull %esi, %ebp
movq %r9, %rcx
movq %rax, %r9
rolq $0xd, %r9
xorq %r10, %r9
rolq $0x7, %r10
subq %r10, %rcx
movq %rdi, %r10
rolq $0x25, %r10
movq %r9, 0x39ae35(%rip)     # 0x3c0a48
addq %rax, %r10
movq %r10, 0x39ae33(%rip)    # 0x3c0a50
addq %rcx, %rdi
movq %rdi, 0x39ae31(%rip)    # 0x3c0a58
addq %r9, %rcx
movq %rcx, 0x39ae2f(%rip)    # 0x3c0a60
movl %ecx, %eax
xorl %edx, %edx
divl %esi
imull %r15d, %edx
addl %ebp, %edx
shrl $0x7, %edx
addl %ebx, %edx
cmpl %r13d, %edx
jle 0x25c62
movl 0x10(%r8,%r12), %eax
movq 0x8(%rsp), %rbx
movl %eax, (%rbx)
movl 0x14(%r8,%r12), %eax
movq 0x10(%rsp), %rbx
movl %eax, (%rbx)
movl %edx, %r13d
addq $0x1a8, %r12            # imm = 0x1A8
movq %rdi, %rax
movq %rcx, %rdi
cmpq %r12, %r11
jne 0x25bcb
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x39adda(%rip), %rdi    # 0x3c0a68
callq 0x57c0
testl %eax, %eax
je 0x25a7e
leaq 0x39ada6(%rip), %rdi    # 0x3c0a48
callq 0x8f3c
leaq 0x39adba(%rip), %rdi    # 0x3c0a68
callq 0x5240
jmp 0x25a7e
movq %rax, %rbx
leaq 0x39ada6(%rip), %rdi    # 0x3c0a68
callq 0x5230
movq %rbx, %rdi
callq 0x5790