// File: /workspace/github_cpp_makefile_star2_O3/cpirc[P]Monochrome/src/eval.cpp
// Function: evaluate(Position&)
int evaluate(Position& pos) {
    int opening = 0, endgame = 0;
    int phase = material_phase<>(pos);
    Colour side;

    for (side = US; side <= THEM; ++side) {
        // material + PST
        opening += evaluate_material<>(pos) + evaluate_pst<OPENING>(pos);
        endgame += evaluate_material<>(pos) + evaluate_pst<ENDGAME>(pos);

        // King safety
        opening += king_safety(pos);

        opening += evaluate_mobility<>(pos);
        endgame += evaluate_mobility<>(pos);

        // Passed pawns
        opening += evaluate_passers(pos);
        endgame += evaluate_passers(pos);

        opening = -opening;
        endgame = -endgame;
        flip_position(pos);
    }

    int score = ((phase * opening) + ((24 - phase) * endgame)) / 24;

    return score;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
movabsq $-0x7c7c7c7c7c7c7c80, %r15 # imm = 0x8383838383838380
movabsq $0x303030303030300, %r14 # imm = 0x303030303030300
movq 0x30(%rdi), %rax
movq %rax, -0x68(%rbp)
movq 0x8(%rdi), %rax
movq %rax, -0x58(%rbp)
movq 0x10(%rdi), %rax
movq %rax, -0x50(%rbp)
movq 0x18(%rdi), %rax
movq %rax, -0x60(%rbp)
movq 0x20(%rdi), %rax
movq %rax, -0x70(%rbp)
movb $0x1, %al
xorl %r13d, %r13d
xorl %ecx, %ecx
xorl %r8d, %r8d
movl %ecx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl %r8d, -0x40(%rbp)
movl %r13d, -0x44(%rbp)
movq %rbx, %rdi
callq 0x3d3c
movl %eax, %r12d
movq %rbx, %rdi
callq 0x3eaa
movl %eax, %r13d
movq %rbx, %rdi
callq 0x3d3c
movl %eax, -0x34(%rbp)
movq %rbx, %rdi
callq 0x3fc4
movl %eax, -0x30(%rbp)
movq 0x30(%rbx), %rax
movq 0x28(%rbx), %rcx
andq %rax, %rcx
je 0x3d1d
bsfq %rcx, %rcx
leaq 0xddb5(%rip), %rdx      # 0x117c0
andq (%rdx,%rcx,8), %rax
movq %rax, %rcx
shrq %rcx
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
andq %rdx, %rcx
subq %rcx, %rax
movq %rax, %rcx
movabsq $0x3333333333333333, %rdx # imm = 0x3333333333333333
andq %rdx, %rcx
shrq $0x2, %rax
andq %rdx, %rax
addq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
addq %rax, %rcx
movabsq $0xf0f0f0f0f0f0f0f, %rax # imm = 0xF0F0F0F0F0F0F0F
andq %rax, %rcx
movabsq $0x101010101010101, %rax # imm = 0x101010101010101
imulq %rax, %rcx
shrq $0x38, %rcx
leal (%rcx,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x40e2
addl -0x44(%rbp), %r12d
addl %eax, %r13d
addl %r12d, %r13d
addl -0x2c(%rbp), %r13d
movq %rbx, %rdi
callq 0x40e2
movq (%rbx), %rdx
movq 0x30(%rbx), %rsi
andq %rdx, %rsi
je 0x3b2f
movq 0x38(%rbx), %r8
xorl %edi, %edi
movq %rsi, %r9
movabsq $-0x7e7e7e7e7e7e7e80, %r12 # imm = 0x8181818181818180
bsfq %r9, %rcx
movl %ecx, %r10d
andl $0x7, %r10d
movq %r15, %r11
cmoveq %r14, %r11
cmpl $0x7, %r10d
cmoveq %r12, %r11
shlq %cl, %r11
andq %r8, %r11
testq %rdx, %r11
jne 0x3ae2
shrl $0x3, %ecx
leaq 0x81a2(%rip), %r10      # 0xbc80
addl (%r10,%rcx,4), %edi
leaq -0x1(%r9), %rcx
andq %rcx, %r9
jne 0x3aaf
xorl %r9d, %r9d
bsfq %rsi, %rcx
movl %ecx, %r10d
andl $0x7, %r10d
movq %r15, %r11
cmoveq %r14, %r11
cmpl $0x7, %r10d
cmoveq %r12, %r11
shlq %cl, %r11
andq %r8, %r11
testq %rdx, %r11
jne 0x3b21
shrl $0x3, %ecx
leaq 0x8163(%rip), %r10      # 0xbc80
addl (%r10,%rcx,4), %r9d
leaq -0x1(%rsi), %rcx
andq %rcx, %rsi
jne 0x3aee
addl %edi, %r13d
jmp 0x3b32
xorl %r9d, %r9d
movl -0x34(%rbp), %esi
addl -0x30(%rbp), %esi
addl %eax, %esi
movl -0x40(%rbp), %eax
addl %esi, %eax
addl %r9d, %esi
addl %r9d, %eax
movq $-0x8, %rcx
movq 0x8(%rbx,%rcx), %rdx
bswapq %rdx
movq %rdx, 0x8(%rbx,%rcx)
addq $0x8, %rcx
cmpq $0x28, %rcx
jb 0x3b4c
movl -0x38(%rbp), %r8d
subl %esi, %r8d
movq 0x30(%rbx), %rcx
movq 0x38(%rbx), %rdx
movq %rcx, 0x38(%rbx)
movq %rdx, 0x30(%rbx)
movl $0x28, %ecx
movq 0x8(%rbx,%rcx), %rdx
bswapq %rdx
movq %rdx, 0x8(%rbx,%rcx)
addq $0x8, %rcx
cmpq $0x38, %rcx
jb 0x3b7f
movb 0x42(%rbx), %cl
cmpb $0x40, %cl
je 0x3ba4
xorb $0x38, %cl
movb %cl, 0x42(%rbx)
movb 0x40(%rbx), %cl
leal (,%rcx,4), %edx
andb $0xc, %dl
shrb $0x2, %cl
xorb %dl, %cl
movb %cl, 0x40(%rbx)
xorb $0x1, 0x41(%rbx)
negl %r13d
movl %eax, %ecx
testb $0x1, -0x3c(%rbp)
movl $0x0, %eax
jne 0x39b5
movq -0x68(%rbp), %r10
movq -0x50(%rbp), %rdx
andq %r10, %rdx
movq %rdx, %rax
shrq %rax
movabsq $0x5555555555555555, %r11 # imm = 0x5555555555555555
andq %r11, %rax
subq %rax, %rdx
movq %rdx, %rax
movabsq $0x3333333333333333, %r9 # imm = 0x3333333333333333
andq %r9, %rax
shrq $0x2, %rdx
andq %r9, %rdx
addq %rax, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
movabsq $0xf0f0f0f0f0f0f0f, %rdi # imm = 0xF0F0F0F0F0F0F0F
andq %rdi, %rcx
movabsq $0x101010101010101, %rsi # imm = 0x101010101010101
imulq %rsi, %rcx
shrq $0x38, %rcx
movq -0x58(%rbp), %rdx
andq %r10, %rdx
movq %rdx, %rax
shrq %rax
andq %r11, %rax
subq %rax, %rdx
movq %rdx, %rax
andq %r9, %rax
shrq $0x2, %rdx
andq %r9, %rdx
addq %rax, %rdx
movq %rdx, %rax
shrq $0x4, %rax
addq %rdx, %rax
andq %rdi, %rax
imulq %rsi, %rax
shrq $0x38, %rax
addl %ecx, %eax
movq -0x60(%rbp), %rdx
andq %r10, %rdx
movq %rdx, %rcx
shrq %rcx
andq %r11, %rcx
subq %rcx, %rdx
movq %rdx, %rcx
andq %r9, %rcx
shrq $0x2, %rdx
andq %r9, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
andq %rdi, %rcx
imulq %rsi, %rcx
shrq $0x38, %rcx
leal (%rax,%rcx,2), %eax
movq -0x70(%rbp), %rdx
andq %r10, %rdx
movq %rdx, %rcx
shrq %rcx
andq %r11, %rcx
subq %rcx, %rdx
movq %rdx, %rcx
andq %r9, %rcx
shrq $0x2, %rdx
andq %r9, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
andq %rdi, %rcx
imulq %rsi, %rcx
shrq $0x38, %rcx
leal (%rax,%rcx,4), %eax
imull %eax, %r13d
movl $0x18, %ecx
subl %eax, %ecx
imull %ecx, %r8d
addl %r13d, %r8d
movslq %r8d, %rax
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7f2c(%rip), %rdi      # 0xbc50
leaq 0x7f28(%rip), %rsi      # 0xbc53
leaq 0x7f30(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100