// File: /workspace/github_cpp_makefile_star2_O3/NathanWine[P]2048-AI-Solvers/src/Game.cpp
// Function: Game::computePossibilities() const
std::map<int, weightedmoves> Game::computePossibilities() const {
    // Note: Responsibility to check if game can continue is given to other functions
    std::map<int, weightedmoves> possibilities;
    movelist valid_moves;
    generatePossibleMoves(valid_moves);

    for (auto const &move : valid_moves) {
        int dir = move.first;
        for (int i = 0; i < DIM; ++i) {
            for (int j = 0; j < DIM; ++j) {
                if (move.second.state[i][j] == 0) {      // If space is 0, add all outcomes if tile added here
                    Game game_copy = move.second;
                    game_copy.state[i][j] = 2;
                    possibilities[dir].push_back(std::pair<float, Game>(0.9, game_copy));
                    game_copy.state[i][j] = 4;
                    possibilities[dir].push_back(std::pair<float, Game>(0.1, game_copy));
                }
            }
        }
    }

    for (auto &possibility : possibilities) {           // Normalize the probabilities
        int len = (int) possibility.second.size();
        for (int i = 0; i < len; ++i) {
            possibility.second[i].first /= len;
        }
    }

    return possibilities;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rsi, %rax
leaq 0x8(%rdi), %rdx
movl $0x0, 0x8(%rdi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rdi)
movq %rdx, 0x18(%rdi)
movq %rdx, 0x38(%rsp)
movq %rdx, 0x20(%rdi)
movq %rdi, (%rsp)
movq %rcx, 0x28(%rdi)
leaq 0x50(%rsp), %rsi
movq %rcx, 0x10(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsi)
movq %rax, %rdi
callq 0x6238
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rax, 0x40(%rsp)
cmpq %rax, %rcx
je 0x67d8
leaq 0x70(%rsp), %r14
movl (%rcx), %eax
movl %eax, 0xc(%rsp)
leaq 0x10(%rcx), %r15
xorl %eax, %eax
movq %rax, 0x48(%rsp)
leaq (%rax,%rax,2), %r13
xorl %ebx, %ebx
movq (%r15), %rax
movq (%rax,%r13,8), %rax
cmpl $0x0, (%rax,%rbx,4)
jne 0x67aa
movq %rcx, %rbp
movl 0x8(%rcx), %eax
movl %eax, 0x68(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2cc2
movq 0x70(%rsp), %rax
movq (%rax,%r13,8), %rax
movl $0x2, (%rax,%rbx,4)
movq (%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x7584
movq %rax, %r12
movl $0x3f666666, 0x10(%rsp) # imm = 0x3F666666
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2cc2
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7eb4
leaq 0x20(%rsp), %rdi
callq 0x2da2
movq 0x70(%rsp), %rax
movq (%rax,%r13,8), %rax
movl $0x4, (%rax,%rbx,4)
movq (%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x7584
movq %rax, %r12
movl $0x3dcccccd, 0x10(%rsp) # imm = 0x3DCCCCCD
movl 0x68(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x2cc2
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
callq 0x7eb4
leaq 0x20(%rsp), %rdi
callq 0x2da2
movq %r14, %rdi
callq 0x2da2
movq %rbp, %rcx
incq %rbx
cmpq $0x4, %rbx
jne 0x66cf
movq 0x48(%rsp), %rax
incq %rax
cmpq $0x4, %rax
jne 0x66c4
addq $0x28, %rcx
cmpq 0x40(%rsp), %rcx
jne 0x66b8
movq (%rsp), %rax
movq 0x18(%rax), %rax
movq 0x38(%rsp), %r14
cmpq %r14, %rax
je 0x683a
movabsq $-0x3333333333333333, %rbx # imm = 0xCCCCCCCCCCCCCCCD
movq 0x28(%rax), %rcx
movq 0x30(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
imulq %rbx, %rdx
testl %edx, %edx
jle 0x682d
xorps %xmm0, %xmm0
cvtsi2ss %edx, %xmm0
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movss (%rcx), %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%rcx)
addq $0x28, %rcx
decq %rdx
jne 0x6818
movq %rax, %rdi
callq 0x2120
cmpq %r14, %rax
jne 0x67f4
leaq 0x50(%rsp), %rdi
callq 0x3d5c
movq (%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6860
jmp 0x6876
jmp 0x6876
movq %rax, %r15
jmp 0x6881
jmp 0x6867
movq %rax, %r15
leaq 0x20(%rsp), %rdi
callq 0x2da2
jmp 0x6879
movq %rax, %r15
movq %r14, %rdi
callq 0x2da2
leaq 0x50(%rsp), %rdi
callq 0x3d5c
movq (%rsp), %rdi
callq 0x3e5a
movq %r15, %rdi
callq 0x22b0