// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
movl %edi, %ebx
leaq 0x8258(%rip), %r14      # 0xd8d8
leaq 0x470(%rsp), %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x3c82
leaq 0x874(%rsp), %rdi
movq %r14, %rsi
movl %ebp, 0x18(%rsp)
movl %ebp, %edx
callq 0x4b7e
pushq $0x3
popq %rax
movl %ebx, 0x10(%rsp)
subl %ebx, %eax
movl %eax, 0x20(%rsp)
movb $0x1, %bpl
xorl %r15d, %r15d
leaq 0xc78(%rsp), %rbx
cmpl 0x870(%rsp), %r15d
jae 0x575b
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2b6c
movslq %r15d, %rax
movzwl 0x470(%rsp,%rax,2), %r12d
movq %rbx, %rdi
movl 0x20(%rsp), %esi
movl %r12d, %edx
callq 0x39a8
testb %al, %al
jne 0x5711
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl %r12d, %edx
callq 0x3bda
movb $0x1, %r13b
testb %al, %al
jne 0x5747
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl %r12d, %edx
callq 0x39a8
movb $0x1, %r13b
testb %al, %al
je 0x5747
movq %rbx, %rdi
movl 0x10(%rsp), %esi
movl %r12d, %edx
callq 0x2cc2
movq %rbx, %rdi
movl %r12d, %esi
callq 0x443a
movl %eax, %r13d
andb %al, %bpl
movq %rbx, %rdi
callq 0x2c5e
incl %r15d
testb %r13b, %r13b
jne 0x56c3
movw $0x8000, %r14w          # imm = 0x8000
testb $0x1, %bpl
jne 0x5fcf
movq %rsp, %rdi
callq 0x62dc
movzwl 0x18(%rsp), %ebx
leaq 0x815a(%rip), %rdi      # 0xd8d8
movl %ebx, %esi
callq 0x4488
movw %ax, 0x30(%rsp)
leaq 0x8147(%rip), %rdi      # 0xd8d8
movl 0x10(%rsp), %esi
movl %ebx, %edx
callq 0x44e2
movw %ax, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
xorl %ebx, %ebx
leaq 0x8126(%rip), %r15      # 0xd8d8
leaq 0xc78(%rsp), %r13
leaq 0x914f(%rip), %rbp      # 0xe910
movl 0x870(%rsp), %eax
cmpl %eax, %ebx
jae 0x5ba9
movq %r13, %rdi
movq %r15, %rsi
callq 0x2b6c
movslq %ebx, %rax
movzwl 0x470(%rsp,%rax,2), %r12d
movzwl %r12w, %r14d
movq %r13, %rdi
movl 0x10(%rsp), %esi
movl %r14d, %edx
callq 0x39a8
testb %al, %al
je 0x5b29
movq %r13, %rdi
movl 0x10(%rsp), %esi
movl %r14d, %edx
callq 0x2cc2
movq %r13, %rdi
movl %r14d, %esi
callq 0x443a
testb %al, %al
jne 0x5b29
movl %r12d, %eax
negw %ax
jno 0x5a04
movq (%rsp), %rbp
pushq $0x28
popq %rdi
callq 0x21a0
movq %rax, %r15
movq %rax, %rdi
callq 0x6318
movq %rbp, 0x18(%r15)
movw %r12w, 0x10(%r15)
movl 0x20(%rsp), %edi
movq %r13, %rsi
callq 0x605d
andl $0x0, 0x6c(%rsp)
andl $0x0, 0x28(%rsp)
movl 0x10(%rsp), %edi
movq %r13, %rsi
leaq 0x6c(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x6212
movss 0x6c(%rsp), %xmm0
movss 0x28(%rsp), %xmm1
movss %xmm0, 0x18(%rsp)
ucomiss %xmm1, %xmm0
jbe 0x5896
incl (%r15)
cvttss2si 0x18(%rsp), %eax
movss %xmm1, 0x34(%rsp)
cvttss2si %xmm1, %ecx
subl %ecx, %eax
cltq
movq %rax, 0x8(%r15)
movq 0x20(%rbp), %rax
movswq 0x12(%rbp), %rcx
movq %r15, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movw %ax, 0x12(%rbp)
movq %rsp, %rdi
movq %r15, %rsi
callq 0x551e
leaq 0x589c(%rip), %rax      # 0xb170
movl (%rax), %ebp
leaq 0x7ffb(%rip), %rdi      # 0xd8d8
movl 0x10(%rsp), %esi
movl %r14d, %edx
callq 0x3bda
imull %ebp, %ebp
shrl $0x3, %ebp
testb %al, %al
je 0x591d
addl %ebp, 0x4(%r15)
leaq 0x7fda(%rip), %rdi      # 0xd8d8
movl 0x20(%rsp), %esi
movl %r14d, %edx
callq 0x39a8
testb %al, %al
jne 0x591d
imull $0xa, %ebp, %eax
addl %eax, 0x4(%r15)
addq $-0xe10, 0x8(%r15)      # imm = 0xF1F0
leaq 0x584c(%rip), %rax      # 0xb170
movl (%rax), %esi
leal -0x1(%rsi), %ecx
imull %esi, %ecx
cmpl $0x9, %esi
je 0x5a2d
cmpl $0x13, %esi
je 0x5943
cmpl $0xd, %esi
jne 0x5a70
movl 0x870(%rsp), %eax
subl %ecx, %eax
jbe 0x5a70
movzbl %r14b, %edi
cmpl $0x13, %edi
je 0x5a65
cmpw $0x1, %di
je 0x5a65
movl %r14d, %r8d
shrl $0x8, %r8d
cmpw $0x1, %r8w
je 0x5a65
cmpw $0x13, %r8w
je 0x5a65
imull %ebp, %eax
xorl %edx, %edx
divl %esi
cmpw $0x4, %r8w
sete %r9b
leal -0x3(%rsi), %edx
cmpl %r8d, %edx
sete %r10b
orb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x59c5
leal (%rax,%rax), %r9d
movq (%r15), %xmm0
movd %r9d, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15)
cmpw $0x4, %di
sete %r9b
cmpl %edi, %edx
sete %dl
orb %r9b, %dl
cmpb $0x1, %dl
jne 0x59f4
leal (%rax,%rax), %edx
movq (%r15), %xmm0
movd %edx, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15)
cmpw $0x3, %r8w
jne 0x5b38
addl %eax, (%r15)
jmp 0x5a6c
movq %r13, %rdi
callq 0x4e7a
movl 0x10efe(%rip), %ecx     # 0x16910
testl %ecx, %ecx
jle 0x5830
leaq -0x1(%rcx), %rdx
cmpq -0x8(%rbp,%rcx,8), %rax
movq %rdx, %rcx
jne 0x5a12
jmp 0x5b29
movl 0x870(%rsp), %eax
subl %ecx, %eax
jbe 0x5a70
movl %r14d, %edx
shrl $0x8, %edx
cmpw $0x1, %dx
je 0x5a65
cmpw $0x9, %dx
setne %dl
movl %r12d, %esi
andl $0xf7, %esi
cmpw $0x1, %si
setne %sil
testb %dl, %sil
jne 0x5b5b
leal (,%rbp,2), %eax
addl %eax, 0x4(%r15)
cmpw 0x30(%rsp), %r12w
jne 0x5a93
leal (%rbp,%rbp,4), %eax
movq (%r15), %xmm0
movd %eax, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15)
cmpw 0x50(%rsp), %r12w
jne 0x5ab6
leal (%rbp,%rbp,4), %eax
movq (%r15), %xmm0
movd %eax, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15)
cmpl %ecx, 0x870(%rsp)
jae 0x5b01
leaq 0x874(%rsp), %rdi
movl %r14d, %esi
callq 0x6348
cmpl $-0x1, %eax
je 0x5af8
movl 0xc74(%rsp), %ecx
decl %ecx
movzwl 0x874(%rsp,%rcx,2), %edx
cltq
movw %dx, 0x874(%rsp,%rax,2)
movl %ecx, 0xc74(%rsp)
jmp 0x5b01
addl %ebp, (%r15)
addl %ebp, %ebp
addl %ebp, 0x4(%r15)
movss 0x18(%rsp), %xmm1
subss 0x34(%rsp), %xmm1
movaps 0x40(%rsp), %xmm0
addss %xmm1, %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0x7db6(%rip), %r15      # 0xd8d8
leaq 0x8de7(%rip), %rbp      # 0xe910
movq %r13, %rdi
callq 0x2c5e
incl %ebx
jmp 0x57c1
addl $-0x2, %esi
cmpl %edi, %esi
je 0x59ff
cmpw $0x3, %di
je 0x59ff
cmpl %r8d, %esi
jne 0x5a70
jmp 0x59ff
imull %ebp, %eax
xorl %edx, %edx
pushq $0x9
popq %rsi
divl %esi
movl %r12d, %edx
andl $0xfb00, %edx           # imm = 0xFB00
cmpw $0x300, %dx             # imm = 0x300
jne 0x5b8f
leal (%rax,%rax), %edx
movq (%r15), %xmm0
movd %edx, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
paddd %xmm0, %xmm1
movq %xmm1, (%r15)
movl %r12d, %edx
andl $0xfb, %edx
cmpw $0x3, %dx
jne 0x5a70
addl %eax, %eax
jmp 0x59ff
movq (%rsp), %rcx
cmpw $0x0, 0x12(%rcx)
je 0x5fc2
movl %eax, %eax
cvtsi2ss %rax, %xmm0
movaps 0x40(%rsp), %xmm1
divss %xmm0, %xmm1
movaps 0x2451(%rip), %xmm0     # 0x8020
movaps %xmm1, 0x40(%rsp)
xorps %xmm1, %xmm0
movaps %xmm0, 0x50(%rsp)
leaq 0xc78(%rsp), %rbp
movq %rsp, %r14
xorl %r15d, %r15d
cmpl 0x5593(%rip), %r15d     # 0xb184
jge 0x5e42
movq %rbp, %rdi
leaq 0x7cd7(%rip), %rsi      # 0xd8d8
callq 0x2b6c
movl 0x10(%rsp), %eax
movl %eax, 0xc(%rsp)
orl $-0x1, 0x38(%rsp)
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
movq %rbp, %rdx
leaq 0x38(%rsp), %rcx
callq 0x53cc
movq %rax, %r12
pushq $0x28
popq %rdi
callq 0x21a0
leaq 0x1151e(%rip), %r14     # 0x17158
movq %rax, %r13
movq %rax, %rdi
callq 0x6318
movq %r12, 0x18(%r13)
movl 0xc(%rsp), %edx
leaq 0x6c(%rsp), %rdi
movq %rbp, %rsi
callq 0x3c82
movq %r13, 0x20(%rsp)
movl %r15d, 0x18(%rsp)
movl 0x46c(%rsp), %eax
movw $0x8000, 0x6c(%rsp,%rax,2) # imm = 0x8000
leal 0x1(%rax), %r15d
movl %r15d, 0x46c(%rsp)
leaq (,%r15,4), %rdi
callq 0x2030
movq %rax, %rbx
xorl %r13d, %r13d
movl %r15d, %eax
cmpq %rax, %r13
jae 0x5cca
andl $0x0, 0x28(%rsp)
movl %r13d, 0x2c(%rsp)
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x5544
cltq
movl (%rbx,%rax,4), %ecx
movl %ecx, (%rbx,%r13,4)
movl %r13d, (%rbx,%rax,4)
incq %r13
movl 0x46c(%rsp), %r15d
jmp 0x5c91
movq %rbp, %r14
xorl %ebp, %ebp
xorl %r13d, %r13d
movl %r15d, %eax
cmpq %rax, %rbp
jae 0x5d35
movslq (%rbx,%rbp,4), %rax
movzwl 0x6c(%rsp,%rax,2), %r13d
movzwl 0x12(%r12), %eax
testw %ax, %ax
movl $0x0, %ecx
cmovlel %ecx, %eax
movzwl %ax, %eax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x5d14
movq 0x20(%r12), %rdx
movq (%rdx,%rcx,8), %rdx
incq %rcx
cmpw 0x10(%rdx), %r13w
jne 0x5cfa
jmp 0x5d30
movl 0xc(%rsp), %esi
movzwl %r13w, %edx
movq %r14, %rdi
callq 0x39a8
testb %al, %al
jne 0x5d35
movl 0x46c(%rsp), %r15d
incq %rbp
jmp 0x5cd2
movq %rbx, %rdi
callq 0x21d0
movq 0x20(%rsp), %rax
movw %r13w, 0x10(%rax)
movl 0xc(%rsp), %esi
movzwl %r13w, %ebx
movq %r14, %rbp
movq %r14, %rdi
movl %ebx, %edx
callq 0x2cc2
pushq $0x3
popq %rdi
subl 0xc(%rsp), %edi
movq %rbp, %rsi
callq 0x605d
andl $0x0, 0x28(%rsp)
andl $0x0, 0x3c(%rsp)
movl 0xc(%rsp), %edi
movq %rbp, %rsi
leaq 0x28(%rsp), %rdx
leaq 0x3c(%rsp), %rcx
callq 0x6212
movq %rsp, %r14
movl 0x18(%rsp), %r15d
movq 0x20(%rsp), %r13
movaps 0x50(%rsp), %xmm0
movl 0x10(%rsp), %eax
cmpl %eax, 0xc(%rsp)
je 0x5dac
movaps 0x40(%rsp), %xmm0
addss 0x28(%rsp), %xmm0
movss 0x3c(%rsp), %xmm1
movss %xmm0, 0x34(%rsp)
movss %xmm1, 0x30(%rsp)
ucomiss %xmm1, %xmm0
jbe 0x5de5
incl (%r13)
movl 0x38(%rsp), %edx
testl %edx, %edx
je 0x5dfb
leaq 0x10b38(%rip), %rdi     # 0x16914
movl %ebx, %esi
callq 0x6366
jmp 0x5dfb
movl 0x38(%rsp), %edx
testl %edx, %edx
je 0x5dfb
leaq 0x10b20(%rip), %rdi     # 0x16914
movl %ebx, %esi
callq 0x6398
cvttss2si 0x34(%rsp), %eax
cvttss2si 0x30(%rsp), %ecx
subl %ecx, %eax
cltq
movq %rax, 0x8(%r13)
movq 0x20(%r12), %rax
movswq 0x12(%r12), %rcx
movq %r13, (%rax,%rcx,8)
leal 0x1(%rcx), %eax
movw %ax, 0x12(%r12)
movq %r14, %rdi
movq %r13, %rsi
callq 0x551e
movq %rbp, %rdi
callq 0x2c5e
incl %r15d
jmp 0x5bea
movq (%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rax
movzwl 0x10(%rax), %r14d
leaq 0x10abb(%rip), %rdi     # 0x16914
callq 0x63ca
movq $-0x40000000, %r12      # imm = 0xC0000000
xorps %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
xorl %ebx, %ebx
leaq 0x11839(%rip), %r15     # 0x176b0
leaq 0x21b7(%rip), %r13      # 0x8035
leaq 0x21b4(%rip), %rbp      # 0x8039
movq (%rsp), %rax
movswq 0x12(%rax), %rcx
cmpq %rcx, %rbx
jge 0x5fb4
movq 0x20(%rax), %rax
movq (%rax,%rbx,8), %rax
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
cvtsi2sdl 0x4(%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
cmpb $0x1, (%r15)
jne 0x5f5b
movq 0x512b(%rip), %rdi      # 0xaff0
leaq 0x2164(%rip), %rsi      # 0x8030
callq 0x2190
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movzbl 0x11(%rcx), %esi
movq %rax, %rdi
callq 0x2280
movq %rax, %rdi
leaq 0x213f(%rip), %rsi      # 0x8032
callq 0x2190
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movzbl 0x10(%rcx), %esi
movq %rax, %rdi
callq 0x2280
movq %rax, %rdi
movq %r13, %rsi
callq 0x2190
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movl (%rcx), %esi
movq %rax, %rdi
callq 0x2280
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
movq (%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movl 0x4(%rcx), %esi
movq %rax, %rdi
callq 0x2280
movq %rax, %rdi
callq 0x20d0
movsd 0x10(%rsp), %xmm1
divsd 0x20(%rsp), %xmm1
movapd %xmm1, %xmm0
ucomisd 0x18(%rsp), %xmm1
jbe 0x5f85
movq (%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%rbx,8), %rcx
movq 0x8(%rcx), %rax
jmp 0x5f9e
jne 0x5fac
jp 0x5fac
movq (%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax,%rbx,8), %rcx
movq 0x8(%rcx), %rax
cmpq %r12, %rax
jle 0x5fac
movzwl 0x10(%rcx), %r14d
movsd %xmm0, 0x18(%rsp)
movq %rax, %r12
incq %rbx
jmp 0x5e85
leaq 0x10959(%rip), %rdi     # 0x16914
callq 0x63f6
jmp 0x5fc7
movw $0x8000, %r14w          # imm = 0x8000
movq %rsp, %rdi
callq 0x6424
movl %r14d, %eax
addq $0x1ca8, %rsp           # imm = 0x1CA8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6024
jmp 0x6024
jmp 0x6019
jmp 0x603d
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r15, %rdi
jmp 0x600a
jmp 0x603d
jmp 0x603d
jmp 0x603d
jmp 0x603d
jmp 0x603d
movq %rax, %rbx
pushq $0x28
popq %rsi
movq %r13, %rdi
callq 0x21b0
jmp 0x6040
jmp 0x603d
jmp 0x603d
jmp 0x6024
jmp 0x6024
movq %rax, %rbx
jmp 0x6055
jmp 0x603d
jmp 0x603d
jmp 0x603d
movq %rax, %rbx
jmp 0x604d
movq %rax, %rbx
leaq 0xc78(%rsp), %rdi
callq 0x2c5e
jmp 0x6055
jmp 0x603d
movq %rax, %rbx
leaq 0xc78(%rsp), %rdi
callq 0x2c5e
movq %rsp, %rdi
callq 0x6424
movq %rbx, %rdi
callq 0x2290