// File: /workspace/github_cpp_makefile_star2_O3/jeffreyan11[P]go-engine/search.cpp
// Function: generateMove(int, unsigned short)
Move generateMove(Player p, Move lastMove) {
    MoveList legalMoves = game.getLegalMoves(p);
    MoveList localMoves = game.getLocalMoves(lastMove);

    // Pass if every move is either into your own eye, a suicide, or places
    // a chain into atari
    bool playPass = true;
    for (unsigned int n = 0; n < legalMoves.size(); n++) {
        Board copy = Board(game);
        Move m = legalMoves.get(n);

        if (!copy.isMoveValid(otherPlayer(p), m) && copy.isEye(p, m))
            continue;

        if (!copy.isMoveValid(p, m))
            continue;

        copy.doMove(p, m);
        if (copy.isInAtari(m))
            continue;

        playPass = false;
        break;
    }

    if (playPass)
        return MOVE_PASS;


    MCTree searchTree;
    float komiAdjustment = 0.0;
    Move captureLastStone = game.getPotentialCapture(lastMove);
    Move potentialEscape = game.getPotentialEscape(p, lastMove);

    // Add all first-level moves
    for (unsigned int n = 0; n < legalMoves.size(); n++) {
        Board copy = Board(game);
        Player genPlayer = p;

        Move next = legalMoves.get(n);
        // Check legality of moves (suicide)
        if (!copy.isMoveValid(genPlayer, next))
            continue;

        copy.doMove(genPlayer, next);
        // Never place own chain in atari
        if (copy.isInAtari(next))
            continue;

        // Check for ko rule violation
        bool koViolation = false;
        if (next != MOVE_PASS) {
            uint64_t newKey = copy.getZobristKey();
            for (int i = keyStackSize-1; i >= 0; i--) {
                if (newKey == keyStack[i]) {
                    koViolation = true;
                    break;
                }
            }
        }
        if (koViolation)
            continue;

        // First level moves are added to the root
        MCNode *leaf = searchTree.root;
        MCNode *addition = new MCNode();
        addition->parent = leaf;
        addition->m = next;

        // Play out a random game. The final board state will be stored in copy.
        playRandomGame(otherPlayer(genPlayer), copy);

        // Score the game
        float myScore = 0.0, oppScore = 0.0;
        scoreGame(genPlayer, copy, myScore, oppScore);
        if (myScore > oppScore)
            addition->numerator++;
        addition->scoreDiff = ((int) myScore) - ((int) oppScore);
        komiAdjustment += myScore - oppScore;

        // Add the new node to the tree
        leaf->children[leaf->size] = addition;
        leaf->size++;

        // Backpropagate the results
        searchTree.backPropagate(addition);

        // Do priors, if any
        // Own eye and opening priors inspired by Pachi,
        // written by Petr Baudis and Jean-loup Gailly
        int basePrior = boardSize * boardSize / 8;
        // Discourage playing into own eyes
        if (game.isEye(genPlayer, next)) {
            addition->denominator += basePrior;
            // If this eye is not ko-related we almost certainly should not play
            // in it
            if (!game.isMoveValid(otherPlayer(genPlayer), next)) {
                addition->denominator += 10 * basePrior;
                addition->scoreDiff -= 10 * 360;
            }
        }

        // Discourage playing onto edges and encourage playing onto the 4th line
        // in 13x13 and 19x19 openings
        unsigned int openingMoves = boardSize * boardSize - boardSize;
        if ((boardSize == 13 || boardSize == 19) && legalMoves.size() > openingMoves) {
            int x = getX(next);
            int y = getY(next);
            if (x == 1 || x == 19 || y == 1 || y == 19) {
                addition->denominator += 2 * basePrior;
            }
            else {
                int taperedPrior = basePrior * (legalMoves.size() - openingMoves) / boardSize;
                if (x == 4 || x == boardSize-3) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
                if (y == 4 || y == boardSize-3) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
                if (x == 3 || x == boardSize-2 || y == 3 || y == boardSize-2) {
                    addition->numerator += taperedPrior;
                    addition->denominator += taperedPrior;
                }
            }
        }
        // And the same for 9x9
        else if (boardSize == 9 && legalMoves.size() > openingMoves) {
            int x = getX(next);
            int y = getY(next);
            if (x == 1 || x == boardSize || y == 1 || y == boardSize) {
                addition->denominator += 2 * basePrior;
            }
            else {
                int taperedPrior = basePrior * (legalMoves.size() - openingMoves) / boardSize;
                if (x == 3 || x == boardSize-2) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
                if (y == 3 || y == boardSize-2) {
                    addition->numerator += 2 * taperedPrior;
                    addition->denominator += 2 * taperedPrior;
                }
            }
        }

        // Add a bonus for capturing a chain that the opponent placed
        // into atari on the previous move
        if (next == captureLastStone) {
            addition->numerator += 5 * basePrior;
            addition->denominator += 5 * basePrior;
        }

        // Add a bonus for escaping when the opponent's last move
        // placed our chain into atari
        if (next == potentialEscape) {
            addition->numerator += 5 * basePrior;
            addition->denominator += 5 * basePrior;
        }

        // Add a bonus to local moves
        if (legalMoves.size() < openingMoves) {
            int li = localMoves.find(next);
            if (li != -1) {
                localMoves.removeFast(li);
            }
            else {
                addition->numerator += basePrior;
                addition->denominator += 2 * basePrior;
            }
        }
    }

    // If we have no moves that are ko-legal, pass.
    if (searchTree.root->size == 0)
        return MOVE_PASS;

    // Calculate an estimate of a komi adjustment
    komiAdjustment /= legalMoves.size();


    // Expand the MC tree iteratively
    for (int n = 0; n < playouts; n++) {
        Board copy = Board(game);
        Player genPlayer = p;

        // Find a node in the tree to add a child to
        int depth = -1;
        MCNode *leaf = searchTree.findLeaf(genPlayer, copy, depth);

        MCNode *addition = new MCNode();
        addition->parent = leaf;
        MoveList candidates = copy.getLegalMoves(genPlayer);
        candidates.add(MOVE_PASS);

        // Set up a permutation matrix
        int *permutation = new int[candidates.size()];
        // Fisher-Yates shuffle
        for (unsigned int i = 0; i < candidates.size(); i++) {
            std::uniform_int_distribution<int> distribution(0, i);
            int j = distribution(rng);
            permutation[i] = permutation[j];
            permutation[j] = i;
        }

        // Find a random move that has not been explored yet
        Move next = 0;
        for (unsigned int i = 0; i < candidates.size(); i++) {
            next = candidates.get(permutation[i]);

            bool used = false;
            for (int j = 0; j < leaf->size; j++) {
                if (next == leaf->children[j]->m) {
                    used = true;
                    break;
                }
            }

            if (!used && copy.isMoveValid(genPlayer, next))
                break;
        }

        delete[] permutation;

        addition->m = next;
        copy.doMove(genPlayer, next);

        // Play out a random game. The final board state will be stored in copy.
        playRandomGame(otherPlayer(genPlayer), copy);

        // Score the game... somehow...
        float myScore = 0.0, oppScore = 0.0;
        scoreGame(genPlayer, copy, myScore, oppScore);
        myScore += (genPlayer == p) ? -komiAdjustment : komiAdjustment;

        if (myScore > oppScore) {
            addition->numerator++;
            // If the node is not a child of root
            if (depth)
                raveTable.inc(next, depth);
        }
        else {
            if (depth)
                raveTable.dec(next, depth);
        }
        addition->scoreDiff = ((int) myScore) - ((int) oppScore);

        // Add the new node to the tree
        leaf->children[leaf->size] = addition;
        leaf->size++;

        // Backpropagate the results
        searchTree.backPropagate(addition);
    }


    // Find the highest scoring move
    Move bestMove = searchTree.root->children[0]->m;
    double bestScore = 0.0;
    int64_t diff = -(1 << 30);
    int maxRAVE = raveTable.max();
    for (int i = 0; i < searchTree.root->size; i++) {
        double candidateScore = (double) searchTree.root->children[i]->numerator
                              / (double) searchTree.root->children[i]->denominator;
                            // +   (double) raveTable.score(searchTree.root->children[i]->m)
                            //   / ((double) maxRAVE)
                            //   / (16 + std::sqrt(searchTree.root->children[i]->denominator))
                            // +   (double) searchTree.root->children[i]->scoreDiff
                            //   / (double) (360 * 32);

        // if (candidateScore > bestScore) {
        //     bestScore = candidateScore;
        //     bestMove = searchTree.root->children[i]->m;
        // }

        if (debugOutput) {
            std::cerr << "(" << getX(searchTree.root->children[i]->m) << ", "
                      << getY(searchTree.root->children[i]->m) << "): "
                      << searchTree.root->children[i]->numerator << " / "
                      << searchTree.root->children[i]->denominator << std::endl;
        }

        if (candidateScore > bestScore
         || (candidateScore == bestScore && searchTree.root->children[i]->scoreDiff > diff)) {
            bestScore = candidateScore;
            bestMove = searchTree.root->children[i]->m;
            diff = searchTree.root->children[i]->scoreDiff;
        }
    }

    raveTable.age();

    return bestMove;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1ca8, %rsp           # imm = 0x1CA8
movl %esi, %r15d
movl %edi, %ebx
leaq 0x8d3f(%rip), %r14      # 0xe8f8
leaq 0x470(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x40dc
leaq 0x874(%rsp), %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x4fe4
movw $0x8000, %bp            # imm = 0x8000
cmpl $0x0, 0x400(%r12)
je 0x6656
movl $0x3, %ebp
movl %ebx, 0x18(%rsp)
subl %ebx, %ebp
xorl %ebx, %ebx
leaq 0x8cf0(%rip), %r12      # 0xe8f8
leaq 0xc78(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x2eb2
movslq %ebx, %rax
movzwl 0x470(%rsp,%rax,2), %r14d
movq %r13, %rdi
movl %ebp, %esi
movl %r14d, %edx
callq 0x3e0c
testb %al, %al
jne 0x5c4b
movq %r13, %rdi
movl 0x18(%rsp), %esi
movl %r14d, %edx
callq 0x4034
testb %al, %al
jne 0x5c8a
movq %r13, %rdi
movl 0x18(%rsp), %esi
movl %r14d, %edx
callq 0x3e0c
testb %al, %al
je 0x5c8a
movq %r13, %rdi
movl 0x18(%rsp), %esi
movl %r14d, %edx
callq 0x3030
movq %r13, %rdi
movl %r14d, %esi
callq 0x4928
movl %eax, %r14d
movq %r13, %rdi
callq 0x2fc2
testb %r14b, %r14b
jne 0x5c92
jmp 0x5caa
movq %r13, %rdi
callq 0x2fc2
incl %ebx
cmpl 0x870(%rsp), %ebx
jb 0x5c10
movw $0x8000, %bp            # imm = 0x8000
jmp 0x6656
leaq 0x10(%rsp), %rdi
callq 0x6980
movzwl %r15w, %r14d
leaq 0x8c39(%rip), %rdi      # 0xe8f8
movl %r14d, %esi
callq 0x4974
movw %ax, 0x2e(%rsp)
movl 0x18(%rsp), %ebx
leaq 0x8c21(%rip), %rdi      # 0xe8f8
movl %ebx, %esi
movl %r14d, %edx
callq 0x49d0
movw %ax, 0x2c(%rsp)
cmpl $0x0, 0x870(%rsp)
je 0x6154
movl %ebp, 0x38(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0x8bf1(%rip), %r14      # 0xe8f8
leaq 0xc78(%rsp), %rbp
xorl %r12d, %r12d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x2eb2
movq %rbp, %rdi
movslq %r12d, %rax
movzwl 0x470(%rsp,%rax,2), %r13d
movzwl %r13w, %r15d
movl %ebx, %esi
movl %r15d, %edx
callq 0x3e0c
testb %al, %al
je 0x6093
movq %rbp, %rdi
movl %ebx, %esi
movl %r15d, %edx
callq 0x3030
movq %rbp, %rdi
movl %r15d, %esi
callq 0x4928
testb %al, %al
jne 0x6093
movl %r13d, %eax
negw %ax
jno 0x5f75
movq 0x10(%rsp), %rbx
movl $0x28, %edi
callq 0x21b0
movq %rax, %r14
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%r14)
xorl %eax, %eax
movq %rax, 0x8(%r14)
movl $0x0, 0x10(%r14)
movq %rax, 0x18(%r14)
movl $0x1000, %edi           # imm = 0x1000
callq 0x2030
movq %rax, 0x20(%r14)
movq %rbx, 0x18(%r14)
movw %r13w, 0x10(%r14)
movl 0x38(%rsp), %edi
movq %rbp, %rsi
callq 0x66e9
xorl %eax, %eax
movl %eax, 0x6c(%rsp)
movl %eax, 0x20(%rsp)
movl 0x18(%rsp), %edi
movq %rbp, %rsi
leaq 0x6c(%rsp), %rdx
leaq 0x20(%rsp), %rcx
callq 0x68cf
movss 0x6c(%rsp), %xmm0
movss 0x20(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x5df6
incl (%r14)
movss %xmm0, 0x30(%rsp)
cvttss2si %xmm0, %eax
movss %xmm1, 0x50(%rsp)
cvttss2si %xmm1, %ecx
subl %ecx, %eax
cltq
movq %rax, 0x8(%r14)
movq 0x20(%rbx), %rax
movswq 0x12(%rbx), %rcx
movq %r14, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movw %ax, 0x12(%rbx)
leaq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x59e6
leaq 0x634e(%rip), %rax      # 0xc188
movl (%rax), %ebx
leaq 0x8ab5(%rip), %rdi      # 0xe8f8
movl 0x18(%rsp), %esi
movl %r15d, %edx
callq 0x4034
imull %ebx, %ebx
shrl $0x3, %ebx
testb %al, %al
movss 0x30(%rsp), %xmm2
je 0x5e91
addl %ebx, 0x4(%r14)
leaq 0x8a8e(%rip), %rdi      # 0xe8f8
movl 0x38(%rsp), %esi
movl %r15d, %edx
callq 0x3e0c
testb %al, %al
movss 0x30(%rsp), %xmm2
jne 0x5e91
leal (%rbx,%rbx,4), %eax
addl %eax, %eax
addl %eax, 0x4(%r14)
addq $-0xe10, 0x8(%r14)      # imm = 0xF1F0
leaq 0x62f0(%rip), %rax      # 0xc188
movl (%rax), %esi
leal -0x1(%rsi), %ecx
imull %esi, %ecx
cmpl $0x9, %esi
je 0x5fa5
cmpl $0x13, %esi
je 0x5eb7
cmpl $0xd, %esi
jne 0x5fe4
movl 0x870(%rsp), %eax
subl %ecx, %eax
jbe 0x5fe4
movzbl %r15b, %edi
cmpl $0x13, %edi
je 0x5fdd
cmpw $0x1, %di
je 0x5fdd
shrl $0x8, %r15d
cmpw $0x1, %r15w
je 0x5fdd
cmpw $0x13, %r15w
je 0x5fdd
imull %ebx, %eax
xorl %edx, %edx
divl %esi
cmpw $0x4, %r15w
sete %r8b
leal -0x3(%rsi), %edx
cmpl %r15d, %edx
sete %r9b
orb %r8b, %r9b
cmpb $0x1, %r9b
jne 0x5f36
leal (%rax,%rax), %r8d
movq (%r14), %xmm0
movd %r8d, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r14)
cmpw $0x4, %di
sete %r8b
cmpl %edi, %edx
sete %dl
orb %r8b, %dl
cmpb $0x1, %dl
jne 0x5f65
leal (%rax,%rax), %edx
movq (%r14), %xmm0
movd %edx, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r14)
cmpw $0x3, %r15w
jne 0x60d2
addl %eax, (%r14)
jmp 0x5fe0
movq %rbp, %rdi
callq 0x529c
movl 0x119ad(%rip), %ecx     # 0x17930
testl %ecx, %ecx
jle 0x5d6e
leaq -0x1(%rcx), %rdx
leaq 0x999a(%rip), %rsi      # 0xf930
cmpq -0x8(%rsi,%rcx,8), %rax
movq %rdx, %rcx
jne 0x5f83
jmp 0x6093
movl 0x870(%rsp), %eax
subl %ecx, %eax
jbe 0x5fe4
shrl $0x8, %r15d
cmpw $0x1, %r15w
je 0x5fdd
cmpw $0x9, %r15w
setne %dl
movl %r13d, %esi
andl $0xf7, %esi
cmpw $0x1, %si
setne %sil
testb %dl, %sil
jne 0x60f5
leal (%rbx,%rbx), %eax
addl %eax, 0x4(%r14)
cmpw 0x2e(%rsp), %r13w
jne 0x6006
leal (%rbx,%rbx,4), %eax
movq (%r14), %xmm0
movd %eax, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r14)
cmpw 0x2c(%rsp), %r13w
jne 0x6028
leal (%rbx,%rbx,4), %eax
movq (%r14), %xmm0
movd %eax, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r14)
cmpl %ecx, 0x870(%rsp)
jae 0x6074
movl 0xc74(%rsp), %eax
testq %rax, %rax
je 0x606b
xorl %ecx, %ecx
xorl %edx, %edx
cmpw %r13w, 0x874(%rsp,%rdx,2)
je 0x6061
incq %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
addq %rsi, %rcx
incq %rcx
cmpq %rdx, %rax
jne 0x6041
jmp 0x606b
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rdx, %rsi
jne 0x60b3
addl %ebx, (%r14)
addl %ebx, %ebx
addl %ebx, 0x4(%r14)
subss 0x50(%rsp), %xmm2
movaps 0x40(%rsp), %xmm0
addss %xmm2, %xmm0
movaps %xmm0, 0x40(%rsp)
movl 0x18(%rsp), %ebx
leaq 0x8865(%rip), %r14      # 0xe8f8
movq %rbp, %rdi
callq 0x2fc2
incl %r12d
movl 0x870(%rsp), %eax
cmpl %eax, %r12d
jb 0x5d12
jmp 0x6148
decl %eax
movzwl 0x874(%rsp,%rax,2), %edx
sarq $0x1f, %rcx
movw %dx, 0x874(%rsp,%rcx)
movl %eax, 0xc74(%rsp)
jmp 0x6074
addl $-0x2, %esi
cmpl %edi, %esi
je 0x5f70
cmpw $0x3, %di
je 0x5f70
cmpl %r15d, %esi
jne 0x5fe4
jmp 0x5f70
imull %ebx, %eax
imulq $0x38e38e39, %rax, %rax # imm = 0x38E38E39
shrq $0x21, %rax
movl %r13d, %edx
andl $0xfb00, %edx           # imm = 0xFB00
cmpl $0x300, %edx            # imm = 0x300
jne 0x612e
leal (%rax,%rax), %edx
movq (%r14), %xmm0
movd %edx, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r14)
movl %r13d, %edx
andl $0xfb, %edx
cmpw $0x3, %dx
jne 0x5fe4
addl %eax, %eax
jmp 0x5f70
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
jmp 0x615c
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq 0x10(%rsp), %rax
movzwl 0x12(%rax), %ecx
testw %cx, %cx
je 0x6648
cmpl $0x0, 0x6027(%rip)      # 0xc19c
jle 0x646c
movaps 0x40(%rsp), %xmm1
divss %xmm0, %xmm1
movaps 0x2ed5(%rip), %xmm0     # 0x9060
movaps %xmm1, 0x40(%rsp)
xorps %xmm1, %xmm0
movaps %xmm0, 0x50(%rsp)
leaq 0xc78(%rsp), %r15
leaq 0x10(%rsp), %r14
leaq 0x20(%rsp), %r13
xorl %ebp, %ebp
movl %ebp, 0x30(%rsp)
movq %r15, %rdi
leaq 0x873e(%rip), %rsi      # 0xe8f8
callq 0x2eb2
movl %ebx, 0xc(%rsp)
movl $0xffffffff, 0x28(%rsp) # imm = 0xFFFFFFFF
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movq %r15, %rdx
leaq 0x28(%rsp), %rcx
callq 0x5860
movq %rax, %r12
movl $0x28, %edi
callq 0x21b0
leaq 0x11f84(%rip), %r14     # 0x18178
movq %rax, %rbp
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, (%rbp)
xorl %eax, %eax
movq %rax, 0x8(%rbp)
movl $0x0, 0x10(%rbp)
movq %rax, 0x18(%rbp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x2030
movq %rax, 0x20(%rbp)
movq %r12, 0x18(%rbp)
movl 0xc(%rsp), %edx
leaq 0x6c(%rsp), %rdi
movq %r15, %rsi
callq 0x40dc
movl 0x46c(%rsp), %eax
movw $0x8000, 0x6c(%rsp,%rax,2) # imm = 0x8000
leal 0x1(%rax), %ebx
movl %ebx, 0x46c(%rsp)
leaq (,%rbx,4), %rdi
callq 0x2030
movq %rax, %r15
testl %ebx, %ebx
je 0x6301
xorl %ebx, %ebx
movl $0x0, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
movq %r13, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x5a12
cltq
movl (%r15,%rax,4), %ecx
movl %ecx, (%r15,%rbx,4)
movl %ebx, (%r15,%rax,4)
incq %rbx
movl 0x46c(%rsp), %eax
cmpq %rax, %rbx
jb 0x626b
testl %eax, %eax
je 0x6301
xorl %r14d, %r14d
movslq (%r15,%r14,4), %rcx
movzwl 0x6c(%rsp,%rcx,2), %ebx
movswq 0x12(%r12), %rcx
testq %rcx, %rcx
jle 0x62d6
movq 0x20(%r12), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
cmpw 0x10(%rdi), %bx
je 0x62f5
incq %rsi
cmpq %rsi, %rcx
jne 0x62c4
movl 0xc(%rsp), %esi
movzwl %bx, %edx
leaq 0xc78(%rsp), %rdi
callq 0x3e0c
testb %al, %al
jne 0x6303
movl 0x46c(%rsp), %eax
incq %r14
movl %eax, %ecx
cmpq %rcx, %r14
jb 0x62a9
jmp 0x6303
xorl %ebx, %ebx
movq %r15, %rdi
callq 0x2200
movw %bx, 0x10(%rbp)
movl 0xc(%rsp), %esi
movzwl %bx, %r15d
leaq 0xc78(%rsp), %r14
movq %r14, %rdi
movl %r15d, %edx
callq 0x3030
movl $0x3, %edi
subl 0xc(%rsp), %edi
movq %r14, %rsi
callq 0x66e9
xorl %eax, %eax
movl %eax, 0x20(%rsp)
movl %eax, 0x3c(%rsp)
movl 0xc(%rsp), %edi
movq %r14, %rsi
movq %r13, %rdx
leaq 0x3c(%rsp), %rcx
callq 0x68cf
leaq 0x10(%rsp), %r14
movaps 0x50(%rsp), %xmm0
movl 0x18(%rsp), %eax
cmpl %eax, 0xc(%rsp)
je 0x6372
movaps 0x40(%rsp), %xmm0
addss 0x20(%rsp), %xmm0
movss 0x3c(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0x63c9
incl (%rbp)
movl 0x28(%rsp), %eax
testl %eax, %eax
je 0x640a
movl %ebx, %ecx
negw %cx
jo 0x640a
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
subl %eax, %ecx
imull %eax, %ecx
addl $0x96, %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
shrl $0x8, %r15d
movzbl %bl, %eax
imulq $0x5c, %r15, %rdx
leaq 0x11573(%rip), %rsi     # 0x17934
addq %rsi, %rdx
addl %ecx, (%rdx,%rax,4)
jmp 0x640a
movl 0x28(%rsp), %eax
testl %eax, %eax
je 0x640a
movl %ebx, %ecx
negw %cx
jo 0x640a
movl $0xfffffffb, %ecx       # imm = 0xFFFFFFFB
subl %eax, %ecx
imull %eax, %ecx
addl $0x96, %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
shrl $0x8, %r15d
movzbl %bl, %eax
imulq $0x5c, %r15, %rdx
leaq 0x11530(%rip), %rsi     # 0x17934
addq %rsi, %rdx
subl %ecx, (%rdx,%rax,4)
cvttss2si %xmm0, %eax
cvttss2si %xmm1, %ecx
subl %ecx, %eax
cltq
movq %rax, 0x8(%rbp)
movq 0x20(%r12), %rax
movswq 0x12(%r12), %rcx
movq %rbp, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movw %ax, 0x12(%r12)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x59e6
movl 0x30(%rsp), %ebp
leaq 0xc78(%rsp), %r15
movq %r15, %rdi
callq 0x2fc2
incl %ebp
cmpl 0x5d43(%rip), %ebp      # 0xc19c
movl 0x18(%rsp), %ebx
jl 0x61ac
movq 0x10(%rsp), %rax
movzwl 0x12(%rax), %ecx
movq 0x20(%rax), %rdx
movq (%rdx), %rdx
movzwl 0x10(%rdx), %ebp
testw %cx, %cx
jle 0x6616
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
movq $-0x40000000, %r13      # imm = 0xC0000000
xorl %r15d, %r15d
leaq 0x12236(%rip), %r12     # 0x186d0
movq 0x5b4f(%rip), %rbx      # 0xbff0
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
cmpb $0x1, (%r12)
jne 0x65b3
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x2b92(%rip), %rsi      # 0x9070
callq 0x21f0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rax
movzbl 0x11(%rax), %esi
movq %rbx, %rdi
callq 0x22b0
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
leaq 0x2b64(%rip), %rsi      # 0x9072
callq 0x21f0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rax
movzbl 0x10(%rax), %esi
movq %r14, %rdi
callq 0x22b0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2b37(%rip), %rsi      # 0x9075
callq 0x21f0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rax
movl (%rax), %esi
movq %r14, %rdi
callq 0x22b0
movq %rax, %r14
movl $0x3, %edx
movq %rax, %rdi
leaq 0x2b0d(%rip), %rsi      # 0x9079
callq 0x21f0
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%r15,8), %rax
movl 0x4(%rax), %esi
movq %r14, %rdi
callq 0x22b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21a0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x2110
movsd 0x18(%rsp), %xmm1
divsd 0x30(%rsp), %xmm1
movapd %xmm1, %xmm0
ucomisd 0x40(%rsp), %xmm1
jbe 0x65de
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rcx
movq (%rcx,%r15,8), %rdx
movq 0x8(%rdx), %rcx
jmp 0x65f8
movq 0x10(%rsp), %rax
jne 0x6605
jp 0x6605
movq 0x20(%rax), %rcx
movq (%rcx,%r15,8), %rdx
movq 0x8(%rdx), %rcx
cmpq %r13, %rcx
jle 0x6605
movzwl 0x10(%rdx), %ebp
movsd %xmm0, 0x40(%rsp)
movq %rcx, %r13
incq %r15
movswq 0x12(%rax), %rcx
cmpq %rcx, %r15
jl 0x64a1
leaq 0x11317(%rip), %rax     # 0x17934
xorl %ecx, %ecx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
movl %esi, %edi
shrl $0x1f, %edi
addl %esi, %edi
sarl %edi
movl %edi, (%rax,%rdx,4)
incq %rdx
cmpq $0x17, %rdx
jne 0x6621
incq %rcx
addq $0x5c, %rax
cmpq $0x17, %rcx
jne 0x661f
jmp 0x664c
movw $0x8000, %bp            # imm = 0x8000
leaq 0x10(%rsp), %rdi
callq 0x69e4
movl %ebp, %eax
addq $0x1ca8, %rsp           # imm = 0x1CA8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x66ab
jmp 0x66ab
jmp 0x66b0
jmp 0x66b5
movq %rax, %rbx
movl $0x28, %esi
movq %r14, %rdi
jmp 0x6696
jmp 0x66b5
jmp 0x66b5
jmp 0x66b5
jmp 0x66ab
jmp 0x66b5
jmp 0x66b5
movq %rax, %rbx
movl $0x28, %esi
movq %rbp, %rdi
callq 0x21c0
jmp 0x66b8
jmp 0x66b5
jmp 0x66b5
jmp 0x66ab
jmp 0x66b5
jmp 0x66b5
jmp 0x66b5
jmp 0x66b5
movq %rax, %rbx
jmp 0x66c5
movq %rax, %rbx
jmp 0x66e1
movq %rax, %rbx
leaq 0xc78(%rsp), %rdi
callq 0x2fc2
leaq 0x10(%rsp), %rdi
callq 0x69e4
jmp 0x66e1
movq %rax, %rbx
leaq 0xc78(%rsp), %rdi
callq 0x2fc2
movq %rbx, %rdi
callq 0x22c0