// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rdi, %r14
movq (%rdi), %rsi
addq $0x14, %rsi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x2b67
movl $0xd8, %edi
addq (%r14), %rdi
movq 0x8(%rbx), %rax
subq (%rbx), %rax
pushq $0xc
popq %r13
cqto
idivq %r13
cmpl $0x3, %eax
pushq $0x3
popq %rcx
cmovll %eax, %ecx
movslq %ecx, %rsi
callq 0x467c
movq (%r14), %rcx
movq 0xd8(%rcx), %rbx
movq 0xe0(%rcx), %rax
cmpq %rax, %rbx
je 0x3300
movq %r14, 0x8(%rsp)
movq 0x18(%rsp), %r14
movq 0x10(%rsp), %rcx
xorl %r15d, %r15d
leaq (%rcx,%r15), %r12
cmpq %r14, %r12
je 0x3228
leaq (%rbx,%r15), %rdx
cmpq %rax, %rdx
je 0x3228
movq (%rcx,%r15), %rsi
movq %rsi, (%rdx)
movl 0x8(%rcx,%r15), %esi
movl %esi, 0x8(%rdx)
addq $0xc, %r15
jmp 0x3201
movq %r15, %rax
cqto
idivq %r13
movq %rax, (%rsp)
cmpq $0x18, %r15
jl 0x3272
movq (%rsp), %rbp
addq $-0x2, %rbp
shrq %rbp
imulq $0xc, %rbp, %rax
leaq (%rax,%rbx), %r13
addq $0x8, %r13
movq -0x8(%r13), %rcx
movl (%r13), %r8d
movq %rbx, %rdi
movq %rbp, %rsi
movq (%rsp), %rdx
callq 0x3c5c
addq $-0xc, %r13
addq $-0x1, %rbp
jb 0x3251
addq $-0xc, %r15
cmpq %r14, %r12
je 0x32a7
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3d94
testb %al, %al
je 0x32a1
movq (%r12), %rcx
movl 0x8(%r12), %r8d
movq %rbx, %rdi
xorl %esi, %esi
movq (%rsp), %rdx
callq 0x3c5c
addq $0xc, %r12
jmp 0x3276
pushq $0xc
popq %r13
leaq 0xc(%r15), %rax
cmpq $0xd, %rax
jl 0x32e8
movq (%rbx,%r15), %rcx
movl 0x8(%rbx,%r15), %r8d
movq (%rbx), %rax
movq %rax, (%rbx,%r15)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rbx,%r15)
movq %r15, %rax
cqto
idivq %r13
addq $-0xc, %r15
movq %rbx, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x3c5c
jmp 0x32ab
movq 0x8(%rsp), %rax
movq (%rax), %rcx
movq 0xd8(%rcx), %rbx
movq 0xe0(%rcx), %rax
jmp 0x3303
movq %rbx, %rax
cvtsi2sdl 0x4(%rcx), %xmm0
subq %rbx, %rax
cqto
idivq %r13
addq $0x8, %rbx
xorl %edx, %edx
leaq 0x9e63(%rip), %rsi      # 0xd180
movsd 0x9e7b(%rip), %xmm1     # 0xd1a0
movsd 0x9e7b(%rip), %xmm2     # 0xd1a8
cmpq %rdx, %rax
je 0x3377
xorl %edi, %edi
testq %rdx, %rdx
sete %dil
movsd (%rsi,%rdi,8), %xmm3
cvtsi2sdl -0x8(%rbx), %xmm4
mulsd %xmm3, %xmm4
addsd %xmm0, %xmm4
cvtsi2sdl -0x4(%rbx), %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm1, %xmm5
addsd %xmm4, %xmm5
cvtsi2sdl (%rbx), %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm5, %xmm0
incq %rdx
addq $0xc, %rbx
jmp 0x332d
imull $0x15, 0x10(%rcx), %eax
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
addsd 0xd0(%rcx), %xmm0
movsd %xmm0, 0xc8(%rcx)
leaq 0x10(%rsp), %rdi
callq 0x9f22
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33b2
jmp 0x33b2
jmp 0x33b2
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x9f22
movq %rbx, %rdi
callq 0x2250