// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq (%rdi), %rsi
addq $0x14, %rsi
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x2d4f
movl $0xd8, %edi
addq (%rbx), %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 0x4dda
movq (%rbx), %rax
movq 0xd8(%rax), %r14
movq 0xe0(%rax), %rax
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
cmpq %rax, %r14
je 0x3775
movq 0x20(%rsp), %rdx
movq 0x18(%rsp), %r13
movq %r14, %rbp
cmpq %rdx, %r13
je 0x3657
movq (%r13), %rcx
movq %rcx, (%rbp)
movl 0x8(%r13), %ecx
movl %ecx, 0x8(%rbp)
addq $0xc, %rbp
addq $0xc, %r13
cmpq %rdx, %r13
je 0x3657
cmpq %rax, %rbp
jne 0x3636
movq %rdx, 0x10(%rsp)
movq %rbx, 0x30(%rsp)
movq %rbp, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x2, %rax
imulq %r12, %rax
movq %rax, 0x8(%rsp)
cmpq $0x18, %r15
jl 0x36ca
movq 0x8(%rsp), %rcx
leaq -0x2(%rcx), %rax
shrq $0x3f, %rax
leaq (%rcx,%rax), %rbx
addq $-0x2, %rbx
sarq %rbx
movq %rbx, %r12
leaq (%rbx,%rbx,2), %rax
movq (%r14,%rax,4), %rcx
movl 0x8(%r14,%rax,4), %r8d
movq %r14, %rdi
movq %rbx, %rsi
movq 0x8(%rsp), %rdx
callq 0x43ed
subq $0x1, %r12
movl $0x0, %eax
cmovbq %rax, %r12
testq %rbx, %rbx
movq %r12, %rbx
jne 0x3698
movq 0x10(%rsp), %rdx
cmpq %rdx, %r13
movq 0x30(%rsp), %rbx
movq 0x8(%rsp), %r12
je 0x3728
movl 0x8(%r13), %r8d
movl (%r13), %eax
movl (%r14), %ecx
cmpl %eax, %ecx
jge 0x3705
movq (%r13), %rcx
movq %r14, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x43ed
movq 0x10(%rsp), %rdx
jmp 0x3707
jle 0x3712
addq $0xc, %r13
cmpq %rdx, %r13
jne 0x36de
jmp 0x3728
movl 0x4(%r13), %eax
movl 0x4(%r14), %ecx
cmpl %eax, %ecx
jl 0x36ed
jg 0x3707
cmpl 0x8(%r14), %r8d
jl 0x36ed
jmp 0x3707
cmpq $0xd, %r15
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jl 0x3775
addq $-0x4, %rbp
movq -0x8(%rbp), %rcx
movl (%rbp), %r8d
movq (%r14), %rax
movq %rax, -0x8(%rbp)
movl 0x8(%r14), %eax
movl %eax, (%rbp)
addq $-0xc, %r15
movq %r15, %rdx
sarq $0x2, %rdx
imulq %r12, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x43ed
addq $-0xc, %rbp
cmpq $0xc, %r15
jg 0x373c
movq (%rbx), %rax
cvtsi2sdl 0x4(%rax), %xmm0
movq 0xd8(%rax), %rcx
movq 0xe0(%rax), %rdx
subq %rcx, %rdx
je 0x3814
sarq $0x2, %rdx
imulq %r12, %rdx
cmpq $0x1, %rdx
adcq $0x0, %rdx
addq $0x8, %rcx
xorl %esi, %esi
leaq 0xb9cf(%rip), %rdi      # 0xf180
movsd 0xb9d7(%rip), %xmm1     # 0xf190
movsd 0xb9d7(%rip), %xmm2     # 0xf198
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 0x37c1
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 0x384f
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 0x3878
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq %rbx, %rdi
callq 0x2230