// File: /workspace/github_cpp_makefile_star2_O3/kmyk[P]codevs-for-student-2016/Main.cpp
// Function: evaluate_photon_for_search(std::shared_ptr<photon_t> const&)
void evaluate_photon_for_search(shared_ptr<photon_t> const & pho) {
    vector<pair<result_t, int> > estimateds = estimate_with_erasing_all(pho->field);
    pho->evaluation.estimateds.resize(min<int>(3, estimateds.size()));
    partial_sort_copy(estimateds.begin(), estimateds.end(), pho->evaluation.estimateds.begin(), pho->evaluation.estimateds.end(), [&](pair<result_t, int> const & a, pair<result_t, int> const & b) {
        return make_tuple(a.first.score, a.first.chain, - a.second) > make_tuple(b.first.score, b.first.chain, - b.second); // reversed
    });
    double acc = 0;
    acc += pho->score; // scoreを基準に
    repeat (i, pho->evaluation.estimateds.size()) {
        double k1 = i == 0 ? 1.0 : 0.2;
        acc += k1 * pho->evaluation.estimateds[i].first.score; // 不正確な値だけど比較可能だろうからよい
        acc += k1 * pho->evaluation.estimateds[i].first.chain * 40; // 大連鎖だと誤差、小連鎖でscoreを気にされると不利
        acc -= k1 * pho->evaluation.estimateds[i].second * 4;
    }
    acc += 21 * pho->dropped_numbers; // 無駄に消すべきでない
    pho->evaluation.score = acc + pho->evaluation.permanent_bonus;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
movq (%rdi), %rsi
addq $0x14, %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2dab
movl $0xd8, %edi
addq (%r15), %rdi
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x2, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
cmpl $0x3, %eax
movl $0x3, %ecx
cmovll %eax, %ecx
movslq %ecx, %rsi
callq 0x4f26
movq (%r15), %rax
movq 0xd8(%rax), %rbx
movq 0xe0(%rax), %rax
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rax, %rbx
je 0x3832
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %r13
movq %rbx, %r14
movq %rbx, %rbp
cmpq %rdx, %r13
je 0x372c
movq (%r13), %rcx
movq %rcx, (%rbp)
movl 0x8(%r13), %ecx
movl %ecx, 0x8(%rbp)
addq $0xc, %rbp
addq $0xc, %r13
addq $0xc, %r14
cmpq %rdx, %r13
je 0x372c
cmpq %rax, %rbp
jne 0x3707
movq %rdx, 0x10(%rsp)
movq %r15, 0x30(%rsp)
subq %rbx, %r14
movq %r14, %rax
sarq $0x2, %rax
imulq %r12, %rax
movq %rax, 0x8(%rsp)
cmpq $0x18, %r14
jl 0x3788
movq 0x8(%rsp), %rax
leaq -0x2(%rax), %r12
shrq %r12
leaq (%r12,%r12,2), %rax
leaq (%rbx,%rax,4), %r15
addq $0x8, %r15
movq -0x8(%r15), %rcx
movl (%r15), %r8d
movq %rbx, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
callq 0x444f
addq $-0xc, %r15
addq $-0x1, %r12
jb 0x3767
movq 0x10(%rsp), %rdx
cmpq %rdx, %r13
movq 0x30(%rsp), %r15
movq 0x8(%rsp), %r12
je 0x37e4
movl 0x8(%r13), %r8d
movl (%r13), %eax
movl (%rbx), %ecx
cmpl %eax, %ecx
jge 0x37c2
movq (%r13), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x444f
movq 0x10(%rsp), %rdx
jmp 0x37c4
jle 0x37cf
addq $0xc, %r13
cmpq %rdx, %r13
jne 0x379c
jmp 0x37e4
movl 0x4(%r13), %eax
movl 0x4(%rbx), %ecx
cmpl %eax, %ecx
jl 0x37aa
jg 0x37c4
cmpl 0x8(%rbx), %r8d
jl 0x37aa
jmp 0x37c4
cmpq $0xd, %r14
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jl 0x3832
leaq -0x4(%rbp), %r14
subq %rbx, %rbp
movq -0x8(%r14), %rcx
movl (%r14), %r8d
movq (%rbx), %rax
movq %rax, -0x8(%r14)
movl 0x8(%rbx), %eax
movl %eax, (%r14)
addq $-0xc, %rbp
movq %rbp, %rdx
sarq $0x2, %rdx
imulq %r12, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x444f
addq $-0xc, %r14
cmpq $0xc, %rbp
jg 0x37fb
movq (%r15), %rax
cvtsi2sdl 0x4(%rax), %xmm0
movq 0xd8(%rax), %rcx
movq 0xe0(%rax), %rdx
subq %rcx, %rdx
je 0x38d1
sarq $0x2, %rdx
imulq %r12, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
addq $0x8, %rcx
xorl %esi, %esi
leaq 0xb7d2(%rip), %rdi      # 0xf040
movsd 0xb962(%rip), %xmm1     # 0xf1d8
movsd 0xb962(%rip), %xmm2     # 0xf1e0
xorl %r8d, %r8d
testq %rsi, %rsi
sete %r8b
xorps %xmm3, %xmm3
cvtsi2sdl -0x8(%rcx), %xmm3
movsd (%rdi,%r8,8), %xmm4
mulsd %xmm4, %xmm3
xorps %xmm5, %xmm5
cvtsi2sdl -0x4(%rcx), %xmm5
addsd %xmm0, %xmm3
mulsd %xmm4, %xmm5
mulsd %xmm1, %xmm5
addsd %xmm3, %xmm5
xorps %xmm0, %xmm0
cvtsi2sdl (%rcx), %xmm0
mulsd %xmm4, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm5, %xmm0
incq %rsi
addq $0xc, %rcx
cmpq %rsi, %rdx
jne 0x387e
movl 0x10(%rax), %ecx
leal (%rcx,%rcx,4), %edx
leal (%rcx,%rdx,4), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
addsd %xmm0, %xmm1
addsd 0xd0(%rax), %xmm1
movsd %xmm1, 0xc8(%rax)
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x390c
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x3935
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2230