// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
movabsq $-0x7c7c7c7c7c7c7c80, %r12 # imm = 0x8383838383838380
movabsq $0x303030303030300, %r15 # 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)
xorl %edi, %edi
xorl %esi, %esi
xorl %r8d, %r8d
xorl %eax, %eax
movl %esi, -0x40(%rbp)
movq %rax, -0x78(%rbp)
movl %r8d, -0x44(%rbp)
movl %edi, -0x48(%rbp)
movq %rbx, %rdi
callq 0x3fb6
movl %eax, -0x34(%rbp)
movq %rbx, %rdi
callq 0x4124
movl %eax, -0x38(%rbp)
movq %rbx, %rdi
callq 0x3fb6
movl %eax, -0x3c(%rbp)
movq %rbx, %rdi
callq 0x423e
movl %eax, -0x30(%rbp)
movq 0x30(%rbx), %r14
movq 0x28(%rbx), %rax
andq %r14, %rax
je 0x3f97
bsfq %rax, %rax
leaq 0xdb56(%rip), %rcx      # 0x117c0
andq (%rcx,%rax,8), %r14
movq %rbx, %rdi
callq 0x435c
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
callq 0x435c
movq (%rbx), %rdi
xorl %edx, %edx
movq 0x30(%rbx), %r8
movl $0x0, %esi
andq %rdi, %r8
je 0x3ce3
movq 0x38(%rbx), %r9
xorl %esi, %esi
movq %r8, %r10
bsfq %r10, %rcx
movl %ecx, %r11d
andl $0x7, %r11d
movq %r12, %r13
cmoveq %r15, %r13
cmpl $0x7, %r11d
movabsq $-0x7e7e7e7e7e7e7e80, %r11 # imm = 0x8181818181818180
cmoveq %r11, %r13
shlq %cl, %r13
andq %r9, %r13
testq %rdi, %r13
jne 0x3cda
shrl $0x3, %ecx
leaq 0x7faa(%rip), %r11      # 0xbc80
addl (%r11,%rcx,4), %esi
leaq -0x1(%r10), %rcx
andq %rcx, %r10
jne 0x3c9d
testq %r8, %r8
je 0x3d34
movq 0x38(%rbx), %r9
xorl %edx, %edx
bsfq %r8, %rcx
movl %ecx, %r10d
andl $0x7, %r10d
movq %r12, %r11
cmoveq %r15, %r11
cmpl $0x7, %r10d
movabsq $-0x7e7e7e7e7e7e7e80, %r10 # imm = 0x8181818181818180
cmoveq %r10, %r11
shlq %cl, %r11
andq %r9, %r11
testq %rdi, %r11
jne 0x3d2b
shrl $0x3, %ecx
leaq 0x7f59(%rip), %r10      # 0xbc80
addl (%r10,%rcx,4), %edx
leaq -0x1(%r8), %rcx
andq %rcx, %r8
jne 0x3cee
movl -0x3c(%rbp), %r9d
addl -0x30(%rbp), %r9d
movq %r14, %rcx
shrq %rcx
movabsq $0x5555555555555555, %rdi # imm = 0x5555555555555555
andq %rdi, %rcx
subq %rcx, %r14
movq %r14, %rcx
movabsq $0x3333333333333333, %rdi # imm = 0x3333333333333333
andq %rdi, %rcx
shrq $0x2, %r14
andq %rdi, %r14
addq %rcx, %r14
movq %r14, %rcx
shrq $0x4, %rcx
addq %r14, %rcx
addl %eax, %r9d
movl -0x34(%rbp), %eax
addl -0x48(%rbp), %eax
movl -0x38(%rbp), %r8d
addl -0x2c(%rbp), %r8d
addl %eax, %r8d
addl %esi, %r8d
movabsq $0xf0f0f0f0f0f0f0f, %rax # imm = 0xF0F0F0F0F0F0F0F
andq %rax, %rcx
movabsq $0x101010101010101, %rax # imm = 0x101010101010101
imulq %rax, %rcx
shrq $0x38, %rcx
leal (%rcx,%rcx,4), %eax
negl %eax
movl %eax, %edi
subl %r8d, %edi
movl -0x44(%rbp), %eax
addl %r9d, %eax
addl %edx, %r9d
movl -0x40(%rbp), %r8d
subl %r9d, %r8d
movq $-0x8, %rcx
movq 0x8(%rbx,%rcx), %rsi
bswapq %rsi
movq %rsi, 0x8(%rbx,%rcx)
addq $0x8, %rcx
cmpq $0x28, %rcx
jb 0x3dcd
movq 0x30(%rbx), %rcx
movq 0x38(%rbx), %rsi
movq %rcx, 0x38(%rbx)
movq %rsi, 0x30(%rbx)
movl $0x28, %ecx
movq 0x8(%rbx,%rcx), %rsi
bswapq %rsi
movq %rsi, 0x8(%rbx,%rcx)
addq $0x8, %rcx
cmpq $0x38, %rcx
jb 0x3df9
movb 0x42(%rbx), %cl
cmpb $0x40, %cl
je 0x3e1e
xorb $0x38, %cl
movb %cl, 0x42(%rbx)
addl %edx, %eax
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)
movq -0x78(%rbp), %rdx
leal 0x1(%rdx), %ecx
movl %eax, %esi
testb %dl, %dl
movl %ecx, %eax
je 0x3c14
movq -0x68(%rbp), %r11
movq -0x50(%rbp), %rdx
andq %r11, %rdx
movq %rdx, %rax
shrq %rax
movabsq $0x5555555555555555, %rbx # imm = 0x5555555555555555
andq %rbx, %rax
subq %rax, %rdx
movq %rdx, %rax
movabsq $0x3333333333333333, %r10 # imm = 0x3333333333333333
andq %r10, %rax
shrq $0x2, %rdx
andq %r10, %rdx
addq %rax, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
movabsq $0xf0f0f0f0f0f0f0f, %r9 # imm = 0xF0F0F0F0F0F0F0F
andq %r9, %rcx
movabsq $0x101010101010101, %rsi # imm = 0x101010101010101
imulq %rsi, %rcx
shrq $0x38, %rcx
movq -0x58(%rbp), %rdx
andq %r11, %rdx
movq %rdx, %rax
shrq %rax
andq %rbx, %rax
subq %rax, %rdx
movq %rdx, %rax
andq %r10, %rax
shrq $0x2, %rdx
andq %r10, %rdx
addq %rax, %rdx
movq %rdx, %rax
shrq $0x4, %rax
addq %rdx, %rax
andq %r9, %rax
imulq %rsi, %rax
shrq $0x38, %rax
addl %ecx, %eax
movq -0x60(%rbp), %rdx
andq %r11, %rdx
movq %rdx, %rcx
shrq %rcx
andq %rbx, %rcx
subq %rcx, %rdx
movq %rdx, %rcx
andq %r10, %rcx
shrq $0x2, %rdx
andq %r10, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
andq %r9, %rcx
imulq %rsi, %rcx
shrq $0x38, %rcx
leal (%rax,%rcx,2), %eax
movq -0x70(%rbp), %rdx
andq %r11, %rdx
movq %rdx, %rcx
shrq %rcx
andq %rbx, %rcx
subq %rcx, %rdx
movq %rdx, %rcx
andq %r10, %rcx
shrq $0x2, %rdx
andq %r10, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
andq %r9, %rcx
imulq %rsi, %rcx
shrq $0x38, %rcx
leal (%rax,%rcx,4), %eax
imull %eax, %edi
movl $0x18, %ecx
subl %eax, %ecx
imull %ecx, %r8d
addl %edi, %r8d
movslq %r8d, %rax
imulq $0x2aaaaaab, %rax, %rax # imm = 0x2AAAAAAB
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x22, %rax
addl %ecx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7cb2(%rip), %rdi      # 0xbc50
leaq 0x7cae(%rip), %rsi      # 0xbc53
leaq 0x7cb6(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100