// File: /workspace/github_cpp_makefile_star2_O1/SethKasmann[P]clever-girl/src/search.cpp
// Function: scout_search(State&, SearchInfo&, int, int, int, int, bool, bool, bool)
int scout_search(State& s, SearchInfo& si, int depth, int ply, int alpha, int beta, bool isPv, bool isNull, bool isRoot)
{
    assert(depth >= 0);
    Move best_move = nullMove;
    
    if (si.quit || (si.nodes % 3000 == 0 && interrupt(si)))
        return 0;

    si.nodes++;

    // Evaluate leaf nodes.
    if (depth == 0)
        return qsearch(s, si, ply, alpha, beta);

    // Check for draw.
    if (!isRoot && 
        (history.isThreefoldRepetition(s) ||
        s.insufficientMaterial() || 
        s.getFiftyMoveRule() > 99))
        return Draw;

    // Get a pointer to the correction transposition table location.
    const TableEntry* table_entry = ttable.probe(s.getKey());

    // Check if table entry is valid and matches the position key.
    if (table_entry->key == s.getKey() && table_entry->depth >= depth)
    {
        if (table_entry->type == pv)             // PV Node, return the score.
            return table_entry->score;
        else if (table_entry->type == cut)       // Cut Node, adjust alpha.
        {
            if (table_entry->score >= beta)
                return beta;
        }
        else
        {
            if (table_entry->score <= alpha)
                return alpha;
        }

        best_move = table_entry->best;
    }

    // Check if we are at the PV line.
    if (lineManager.getPvKey(ply) == s.getKey())
    {
        best_move = lineManager.getPvMove(ply);
    }

// -------------------------------------------------------------------------- //
//                                                                            //
// Static Evaluation. Evaluate the current position statically if the         //
// current node is not a PV node.                                             //
//                                                                            //
// -------------------------------------------------------------------------- //
    int staticEval = 0;
    if (!isPv)
    {
        Evaluate evaluate(s);
        staticEval = evaluate.getScore();
    }

// -------------------------------------------------------------------------- //
//                                                                            //
// Reverse Futility Pruning. At pre-frontier and pre-pre-frontier, if the     //
// side to move is doing so well that the static evaluation - a futility      //
// penalty still causes a beta cutoff, return beta.                           //
//                                                                            //
// -------------------------------------------------------------------------- //
    if (!isPv && 
        !isNull &&
        !s.inCheck() &&
        depth <= 2 &&
        s.getNonPawnPieceCount(s.getOurColor()))
    {
        if (staticEval - 100 * depth >= beta)
            return beta;
    }

// -------------------------------------------------------------------------- //
//                                                                            //
// Null move pruning. Make a null move and searched to a reduced to check     //
// for fail high under the following conditions:                              //
//   1. The current node is not a PV node.                                    //
//   2. The current state is not in check.                                    //
//   3. The depth is high enough.                                             //
//   4. There are enough non pawn pieces on the board.                        //
//                                                                            //
// -------------------------------------------------------------------------- //
    if (!isPv && !isNull && !s.inCheck() && depth > NullMoveDepth 
        && s.getNonPawnPieceCount(s.getOurColor()) > NullMoveCount)
    {
        State n;
        std::memmove(&n, &s, sizeof s);
        n.makeNull();
        history.push(std::make_pair(nullMove, n.getKey()));
        int nullScore = -scout_search(n, si, depth - 3, ply + 1, -(alpha + 1), -alpha, false, true, false);
        history.pop();
        if (nullScore >= beta)
            return beta;
    }

    // Internal Iterative Deepening. If no best move was found, do a small
    // search to determine which move to search first.
    if (isPv && !isNull && !s.inCheck() && best_move == nullMove && depth > 5)
    {
        // Using depth calculation from Stockfish.
        int d = 3 * depth / 4 - 2;
        scout_search(s, si, d, ply, alpha, beta, isPv, true, false);
        table_entry = ttable.probe(s.getKey());
        if (table_entry->key == s.getKey())
            best_move = table_entry->best;
    }
    // Generate moves and create the movelist.
    MoveList mlist(s, best_move, &history, ply);

    int a = alpha;
    int b = beta;
    int d;
    int score;
    int bestScore = Neg_inf;
    Move m;
    bool first = true;
    int count = 0;

    while (m = mlist.getBestMove())
    {
        d = depth - 1;
// -------------------------------------------------------------------------- //
//                                                                            //
// Early Pruning                                                              //
//                                                                            //
// It may be possible to prune before the child move is made, under the       //
// following conditions:                                                      //
//   1. Current node is not a PV node.                                        //
//   2. Best score searched is greater than the - checkmate bound.            //
//   3. Side to move is not in check.                                         //
//   4. Move itself does not give check.                                      //
//   5. Side to move has at least 1 major or minor piece.                     //
//                                                                            //
// -------------------------------------------------------------------------- //
        if (!isPv &&
            bestScore > -CheckmateBound &&
            !s.inCheck() &&
            !s.givesCheck(m) &&
            s.getNonPawnPieceCount(s.getOurColor()))
        {
// -------------------------------------------------------------------------- //
//                                                                            //
// Futility Pruning                                                           //
//                                                                            //
// Prune quiet moves at depth 1 that will not improve alpha.                  //
//                                                                            //
// -------------------------------------------------------------------------- //
            if (depth == 1 &&
                s.isQuiet(m) &&
                !isPromotion(m) &&
                staticEval + 300 < a)
                continue;

// -------------------------------------------------------------------------- //
//                                                                            //
// Pruning based on SEE.                                                      //
//                                                                            //
// Original idea from Stockfish. If the SEE is low relative to the depth,     //
// prune the move. The calculation I'm currently using is:                    //
//   see(move) < -pawn * 2^(depth - 1)                                        //
//                                                                            //
// -------------------------------------------------------------------------- //
            if (depth < 3 &&
                s.see(m) < -Pawn_wt * (1 << (depth - 1)))
                continue;
        }

        State c(s);
        c.make_t(m);                                 // Make move.
        history.push(std::make_pair(m, c.getKey())); // Add move to gamelist.
        count++;

        if (c.inCheck() && depth == 1)
            d++;

        // Scout alrogithm. Search the first node with a full window.
        if (first)
        {
            // Set the best move to the first move just in case no move
            // improves alpha.
            best_move = m;
            score = -scout_search(c, si, d, ply + 1, -b, -a, isPv, isNull, false);
            first = false;
        }       
        else
        {
// -------------------------------------------------------------------------- //
//                                                                            //
// Late move reduction. Perform a reduced depth search (by 1 ply) under the   //
// following conditions:                                                      //
//   1. A number (LmrCount) of moves have already been tried.                 //
//   2. The current node is not a PV node.                                    //
//   3. The side to move is not in check.                                     //
//   4. The move itself does not give check.                                  //
//   5. The move does not promote a piece.                                    //
//   6. The move does not capture a piece.                                    //
//                                                                            //
// -------------------------------------------------------------------------- //
            if (count > LmrCount && depth > LmrDepth && !isPv && !s.inCheck()
                && !c.inCheck() && !s.isCapture(m) && !isPromotion(m))
                score = -scout_search(c, si, d - 1, ply + 1, -(a + 1), -a, false, isNull, false);
            else
                score = a + 1;

            if (score > a)
                score = -scout_search(c, si, d, ply + 1, -(a + 1), -a, false, isNull, false);

            // If an alpha improvement caused fail high, research using a full window.
            if (a < score && b > score)
            {
                score = -scout_search(c, si, d, ply + 1, -b, -a, true, isNull, false);
            }
        }

        history.pop();                           // Remove move from gamelist.

        if (score > bestScore)
        {
            best_move = m;
            bestScore = score;
        }

        a = std::max(a, bestScore);

        // Alpha-Beta pruning. If the move that caused the Beta cutoff is a
        // quiet move, store it as a killer.
        if (a >= b)
        {
            a = b;
            if (s.isQuiet(m))
                history.update(m, depth, ply, true);
            break;
        }
        else
        {
            if (s.isQuiet(m))
                history.update(m, depth, ply, false);
        }
    }

    if (bestScore == Neg_inf)
        return s.check() ? -Checkmate + ply : Stalemate;

    if (a > alpha && a < b && !si.quit)
    {
        lineManager.pushToPv(best_move, s.getKey(), ply, a);
    }

    ttable.store(s.getKey(), best_move, a <= alpha ? all : a >= b ? cut : pv, depth, a);

    // Fail-Hard alpha beta score.
    return a;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xdd8, %rsp            # imm = 0xDD8
movl %r9d, 0xc(%rsp)
xorl %ebp, %ebp
cmpb $0x0, 0x3a(%rsi)
je 0x15569
movl %ebp, %eax
addq $0xdd8, %rsp            # imm = 0xDD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r8d, %r13d
movl %ecx, %r14d
movl %edx, %r12d
movq %rdi, %r15
movb 0xe20(%rsp), %bl
movb 0xe18(%rsp), %al
movb %al, 0xa(%rsp)
movb 0xe10(%rsp), %al
movb %al, 0xb(%rsp)
imull $0xb7a32847, 0x1c(%rsi), %eax # imm = 0xB7A32847
addl $0x576198, %eax         # imm = 0x576198
rorl $0x3, %eax
cmpl $0x15d866, %eax         # imm = 0x15D866
movq %rsi, 0x10(%rsp)
ja 0x155be
movq %rsi, %rdi
callq 0x15088
movq 0x10(%rsp), %rsi
testb %al, %al
jne 0x15555
incl 0x1c(%rsi)
testl %r12d, %r12d
je 0x15661
testb %bl, %bl
jne 0x15627
movq 0x1450d3(%rip), %rax    # 0x15a6a8
movq 0x1450c4(%rip), %rcx    # 0x15a6a0
movq %rax, %rdx
subq %rcx, %rdx
cmpq $0x41, %rdx
jb 0x1560c
shlq $0x1c, %rdx
movabsq $-0x500000000, %rsi     # imm = 0xFFFFFFFB00000000
addq %rdx, %rsi
sarq $0x1c, %rsi
movq 0x8(%rcx,%rsi), %rcx
cmpq -0x8(%rax), %rcx
je 0x15555
movq %r15, %rdi
callq 0x187ee
testb %al, %al
jne 0x15555
cmpl $0x63, 0x8(%r15)
jg 0x15555
movq 0x18(%r15), %rcx
leaq 0x14efbe(%rip), %rax    # 0x1645f0
movq (%rax), %rsi
movq 0x8(%rax), %rdi
subq %rsi, %rdi
sarq $0x5, %rdi
xorl %ebx, %ebx
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
shlq $0x5, %rdx
cmpq %rcx, (%rsi,%rdx)
jne 0x156b0
addq %rdx, %rsi
cmpl %r12d, 0x10(%rsi)
jge 0x15685
xorl %ebx, %ebx
jmp 0x156b0
movq %r15, %rdi
movl %r14d, %edx
movl %r13d, %ecx
movl 0xc(%rsp), %r8d
addq $0xdd8, %rsp            # imm = 0xDD8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x15251
movl 0xc(%rsi), %eax
movl 0x14(%rsi), %ebp
testl %eax, %eax
je 0x15555
cmpl $0x1, %eax
jne 0x156a3
cmpl 0xc(%rsp), %ebp
jl 0x156ac
jmp 0x15f5d
cmpl %r13d, %ebp
jle 0x15ee0
movzwl 0x8(%rsi), %ebx
leaq 0x140029(%rip), %rdi    # 0x1556e0
movl %r14d, %esi
callq 0xf95c
cmpq 0x18(%r15), %rax
jne 0x156d6
leaq 0x140014(%rip), %rdi    # 0x1556e0
movl %r14d, %esi
callq 0xf96a
movl %eax, %ebx
movl $0x0, 0x20(%rsp)
cmpb $0x0, 0xb(%rsp)
jne 0x1570a
movq %rbx, %rbp
leaq 0x580(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xe024
movq %rbx, %rdi
movq %rbp, %rbx
callq 0xef24
movl %eax, 0x20(%rsp)
movb 0xb(%rsp), %al
orb 0xa(%rsp), %al
movq 0x10(%rsp), %rsi
jne 0x15773
cmpl $0x2, %r12d
jg 0x1576b
cmpq $0x0, 0x28(%r15)
jne 0x1576b
movl (%r15), %ecx
leaq (%rcx,%rcx,2), %rcx
movl 0x2f0(%r15,%rcx,8), %edx
addl 0x2ec(%r15,%rcx,8), %edx
addl 0x2f4(%r15,%rcx,8), %edx
addl 0x2f8(%r15,%rcx,8), %edx
movq 0x10(%rsp), %rsi
je 0x1576b
imull $-0x64, %r12d, %ecx
addl 0x20(%rsp), %ecx
cmpl 0xc(%rsp), %ecx
movq 0x10(%rsp), %rsi
jge 0x15f5d
testb %al, %al
je 0x15e41
movb 0xb(%rsp), %al
xorb $0x1, %al
orb 0xa(%rsp), %al
je 0x15ce7
movq %rbx, 0x28(%rsp)
movzwl %bx, %edx
leaq 0x144f0e(%rip), %rcx    # 0x15a6a0
leaq 0x580(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xfd66
leal -0x1(%r12), %ecx
leaq 0x2e8(%r15), %rbx
addl $0x12c, 0x20(%rsp)      # imm = 0x12C
movl $0xffffff9c, %eax       # imm = 0xFFFFFF9C
movl %ecx, 0x50(%rsp)
shll %cl, %eax
movl %eax, 0x54(%rsp)
leal 0x1(%r14), %eax
movl %eax, 0x1c(%rsp)
movl 0xc(%rsp), %eax
negl %eax
movl %eax, 0x40(%rsp)
movq %r14, 0x58(%rsp)
movslq %r14d, %rax
movq %rax, 0x60(%rsp)
movq %r12, 0x30(%rsp)
movl %r12d, %eax
imull %r12d, %eax
movl %eax, 0x3c(%rsp)
movb $0x1, %al
movl %eax, 0x48(%rsp)
movl $0xffff3cb0, 0x24(%rsp) # imm = 0xFFFF3CB0
movl %r13d, 0x4c(%rsp)
movl $0x0, 0x44(%rsp)
cmpl $0xffff8034, 0x24(%rsp) # imm = 0xFFFF8034
setl %r14b
orb 0xb(%rsp), %r14b
leaq 0x580(%rsp), %rdi
callq 0x10030
movl %eax, %r12d
testw %ax, %ax
je 0x15bd3
cmpq $0x0, 0x28(%r15)
setne %al
orb %r14b, %al
movzwl %r12w, %ebp
jne 0x158d8
movq %r15, %rdi
movl %ebp, %esi
callq 0x17442
testb %al, %al
jne 0x158d8
movl (%r15), %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rbx,%rax,8), %ecx
addl 0x4(%rbx,%rax,8), %ecx
addl 0xc(%rbx,%rax,8), %ecx
addl 0x10(%rbx,%rax,8), %ecx
je 0x158d8
cmpl $0x1, 0x30(%rsp)
jne 0x158a5
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl 0x4(%r15), %ecx
movq 0x30(%r15), %rdx
orq 0x78(%r15,%rcx,8), %rdx
leaq 0xe31d1(%rip), %rcx     # 0xf8a70
testq %rdx, (%rcx,%rax,8)
je 0x158c2
cmpl $0x2, 0x30(%rsp)
jg 0x158d8
movq %r15, %rdi
movl %ebp, %esi
callq 0x17798
cmpl 0x54(%rsp), %eax
jl 0x15826
jmp 0x158d8
testl $0x7000, %r12d          # imm = 0x7000
jne 0x158a5
cmpl %r13d, 0x20(%rsp)
jl 0x15826
jmp 0x158a5
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x16460
movl 0xc(%rsp), %r14d
leaq 0x78(%rsp), %rdi
movl %ebp, %esi
callq 0x17b1c
movq 0x90(%rsp), %rax
movw %r12w, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movq 0x144d98(%rip), %rsi    # 0x15a6a8
cmpq 0x144d99(%rip), %rsi    # 0x15a6b0
je 0x1592d
movdqu 0x68(%rsp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x144d7d(%rip)   # 0x15a6a8
jmp 0x1593e
leaq 0x144d6c(%rip), %rdi    # 0x15a6a0
leaq 0x68(%rsp), %rdx
callq 0x14b86
movq 0xa0(%rsp), %rax
testq %rax, %rax
movl 0x50(%rsp), %edx
movl %edx, %ebp
movl $0x1, %ecx
cmovnel %ecx, %ebp
movq 0x30(%rsp), %rcx
cmpl $0x1, %ecx
cmovnel %edx, %ebp
testb $0x1, 0x48(%rsp)
je 0x159bb
movl %r13d, %r9d
negl %r9d
subq $0x8, %rsp
movzbl 0x12(%rsp), %eax
movzbl 0x13(%rsp), %r10d
leaq 0x80(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
movl 0x48(%rsp), %r8d
pushq $0x0
pushq %rax
pushq %r10
callq 0x15537
addq $0x20, %rsp
negl %eax
movl $0x0, 0x48(%rsp)
movl %r12d, %ecx
movq %rcx, 0x28(%rsp)
jmp 0x15a60
cmpl $0x3, %ecx
setl %cl
cmpl $0x3, 0x44(%rsp)
setb %dl
orb %cl, %dl
orb 0xb(%rsp), %dl
jne 0x159db
orq 0x28(%r15), %rax
je 0x15b5e
leal 0x1(%r13), %eax
cmpl %r13d, %eax
movq 0x10(%rsp), %rsi
jle 0x15a24
movl %r13d, %r8d
notl %r8d
movl %r13d, %r9d
negl %r9d
subq $0x8, %rsp
movzbl 0x12(%rsp), %eax
leaq 0x80(%rsp), %rdi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
xorl %r10d, %r10d
pushq %r10
pushq %rax
pushq %r10
callq 0x15537
addq $0x20, %rsp
negl %eax
movq 0x10(%rsp), %rsi
cmpl %eax, %r13d
jge 0x15a60
cmpl %r14d, %eax
jge 0x15a60
movl %r13d, %r9d
negl %r9d
subq $0x8, %rsp
movzbl 0x12(%rsp), %eax
leaq 0x80(%rsp), %rdi
movl %ebp, %edx
movl 0x24(%rsp), %ecx
movl 0x48(%rsp), %r8d
pushq $0x0
pushq %rax
pushq $0x1
callq 0x15537
addq $0x20, %rsp
negl %eax
movq 0x144c41(%rip), %rcx    # 0x15a6a8
cmpq %rcx, 0x144c32(%rip)    # 0x15a6a0
je 0x15a7b
addq $-0x10, %rcx
movq %rcx, 0x144c2d(%rip)    # 0x15a6a8
movl 0x24(%rsp), %ecx
cmpl %ecx, %eax
cmovgl %eax, %ecx
movq 0x28(%rsp), %rax
cmovgl %r12d, %eax
movq %rax, 0x28(%rsp)
cmpl %ecx, %r13d
movl %ecx, 0x24(%rsp)
cmovlel %ecx, %r13d
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
leaq 0xe2fc3(%rip), %rcx     # 0xf8a70
movq (%rcx,%rax,8), %rdi
cmpl %r14d, %r13d
jge 0x15adc
movl 0x4(%r15), %ecx
movq 0x30(%r15), %r8
orq 0x78(%r15,%rcx,8), %r8
leaq 0x144cb6(%rip), %rcx    # 0x15a780
movq 0x30(%rsp), %rdx
movl %r13d, %esi
movl %r13d, %ebp
testq %rdi, %r8
jne 0x15b4c
jmp 0x15b3b
movl 0x4(%r15), %ecx
movq 0x30(%r15), %rdx
orq 0x78(%r15,%rcx,8), %rdx
movl %r14d, %ebp
testq %rdi, %rdx
jne 0x15b4c
leaq 0x144ba8(%rip), %rcx    # 0x15a6a0
movq 0x60(%rsp), %rdx
movzwl 0x18(%rcx,%rdx,4), %edi
leaq 0x148c77(%rip), %rcx    # 0x15e780
movl 0x3c(%rsp), %edx
movl %r14d, %esi
cmpw %r12w, %di
je 0x15b3b
leaq 0x144b83(%rip), %rcx    # 0x15a6a0
movq 0x60(%rsp), %rdx
movw %di, 0x1a(%rcx,%rdx,4)
movw %r12w, 0x18(%rcx,%rdx,4)
leaq 0x148c4c(%rip), %rcx    # 0x15e780
movl 0x3c(%rsp), %edx
movl %r14d, %esi
andl $0x3f, %r12d
shll $0x8, %r12d
addq %rcx, %r12
addl %edx, (%r12,%rax,4)
movl %esi, %ebp
incl 0x44(%rsp)
cmpl %r14d, %r13d
movl %ebp, %r13d
jl 0x15815
jmp 0x15bd6
testl $0x7000, %r12d          # imm = 0x7000
jne 0x159db
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl 0x4(%r15), %ecx
movq 0x30(%r15), %rdx
orq 0x78(%r15,%rcx,8), %rdx
leaq 0xe2ee8(%rip), %rcx     # 0xf8a70
andq (%rcx,%rax,8), %rdx
jne 0x159db
leal -0x1(%rbp), %edx
movl %r13d, %r8d
notl %r8d
movl %r13d, %r9d
negl %r9d
subq $0x8, %rsp
movzbl 0x12(%rsp), %eax
leaq 0x80(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x24(%rsp), %ecx
xorl %r10d, %r10d
pushq %r10
pushq %rax
pushq %r10
callq 0x15537
addq $0x20, %rsp
negl %eax
jmp 0x159df
movl %r13d, %ebp
cmpl $0xffff3cb0, 0x24(%rsp) # imm = 0xFFFF3CB0
movl 0xc(%rsp), %ebx
jne 0x15d6e
movl (%r15), %ecx
movl 0x4(%r15), %edx
imulq $0xf0, %rcx, %rax
movl 0x3f0(%r15,%rax), %eax
shlq $0x9, %rcx
addq 0xf3a7(%rip), %rcx      # 0x24fb0
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq 0x288(%r15,%rdx), %rdi
movb $0x1, %sil
testq %rdi, (%rcx,%rax,8)
movq 0x58(%rsp), %rbx
jne 0x15cd4
leaq 0x288(%r15), %rdi
leaq 0x5f07(%rip), %rcx      # 0x1bb40
movq 0x8(%rdi,%rdx), %r8
testq %r8, (%rcx,%rax,8)
jne 0x15cd4
movq 0x80(%r15), %r8
orq 0x78(%r15), %r8
leaq 0xf5b6(%rip), %rcx      # 0x25210
leaq 0x5bdf(%rip), %r9       # 0x1b840
movq (%r9,%rax,8), %r10
andq %r8, %r10
leaq 0x59d1(%rip), %r9       # 0x1b640
imulq (%r9,%rax,8), %r10
movq (%rcx,%rax,8), %r11
leaq 0x58c1(%rip), %rcx      # 0x1b540
movb (%rcx,%rax,4), %cl
shrq %cl, %r10
movq 0x20(%rdi,%rdx), %r9
movq 0x10(%rdi,%rdx), %rcx
orq %r9, %rcx
testq %rcx, (%r11,%r10,8)
jne 0x15cd4
leaq 0x56a1(%rip), %rcx      # 0x1b340
andq (%rcx,%rax,8), %r8
leaq 0x5496(%rip), %rcx      # 0x1b140
imulq (%rcx,%rax,8), %r8
leaq 0x538a(%rip), %rcx      # 0x1b040
movb (%rcx,%rax,4), %cl
shrq %cl, %r8
leaq 0xf74d(%rip), %rcx      # 0x25410
orq 0x18(%rdi,%rdx), %r9
movq (%rcx,%rax,8), %rax
testq %r9, (%rax,%r8,8)
setne %sil
addl $0xffff8001, %ebx       # imm = 0xFFFF8001
xorl %ebp, %ebp
testb %sil, %sil
cmovnel %ebx, %ebp
jmp 0x15e1b
cmpl $0x6, %r12d
jl 0x15783
cmpq $0x0, 0x28(%r15)
jne 0x15783
testw %bx, %bx
jne 0x15783
leal (%r12,%r12,2), %edx
shrl $0x2, %edx
addl $-0x2, %edx
subq $0x8, %rsp
movl $0x1, %eax
movq %r15, %rdi
movl %r14d, %ecx
movl %r13d, %r8d
movl 0x14(%rsp), %r9d
pushq $0x0
pushq %rax
pushq %rax
callq 0x15537
addq $0x20, %rsp
movq 0x18(%r15), %rcx
leaq 0x14e8b2(%rip), %rax    # 0x1645f0
movq (%rax), %rsi
movq 0x8(%rax), %rdi
subq %rsi, %rdi
sarq $0x5, %rdi
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
shlq $0x5, %rdx
cmpq %rcx, (%rsi,%rdx)
jne 0x15783
addq %rdx, %rsi
movzwl 0x8(%rsi), %ebx
jmp 0x15783
movl 0x4c(%rsp), %r14d
cmpl %r14d, %ebp
setle %al
cmpl %ebx, %ebp
setge %cl
orb %al, %cl
movq 0x58(%rsp), %rcx
jne 0x15daa
movq 0x10(%rsp), %rax
cmpb $0x0, 0x3a(%rax)
jne 0x15daa
movq 0x18(%r15), %rdx
movzwl 0x28(%rsp), %esi
leaq 0x13f93e(%rip), %rdi    # 0x1556e0
movl %ebp, %r8d
callq 0xf8c8
xorl %eax, %eax
cmpl %ebx, %ebp
setge %al
cmpl %r14d, %ebp
movq 0x18(%r15), %rcx
movl $0x2, %esi
cmovgl %eax, %esi
leaq 0x14e829(%rip), %rax    # 0x1645f0
movq (%rax), %rdi
movq 0x8(%rax), %r8
subq %rdi, %r8
sarq $0x5, %r8
movq %rcx, %rax
xorl %edx, %edx
divq %r8
movslq %edx, %rax
shlq $0x5, %rax
movq 0x30(%rsp), %rdx
cmpl %edx, 0x10(%rdi,%rax)
jge 0x15e10
movq %rcx, (%rdi,%rax)
movq 0x28(%rsp), %rcx
movw %cx, 0x8(%rdi,%rax)
movl %esi, 0xc(%rdi,%rax)
movl %edx, 0x10(%rdi,%rax)
movl %ebp, 0x14(%rdi,%rax)
movb $0x0, 0x18(%rdi,%rax)
jmp 0x15e1b
testl %esi, %esi
je 0x15def
cmpb $0x0, 0x18(%rdi,%rax)
jne 0x15def
movq 0xdb0(%rsp), %rdi
testq %rdi, %rdi
je 0x15555
movq 0xdc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4250
jmp 0x15555
cmpl $0x4, %r12d
jl 0x15773
cmpq $0x0, 0x28(%r15)
jne 0x15773
movl (%r15), %eax
leaq (%rax,%rax,2), %rax
movdqu 0x2ec(%r15,%rax,8), %xmm0
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %eax
cmpl $0x4, %eax
jl 0x15773
movq %rbx, %rbp
leaq 0x580(%rsp), %rbx
movl $0x508, %edx            # imm = 0x508
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41c0
movq %rbx, %rdi
callq 0x186f6
movq 0x18(%rbx), %rax
movw $0x0, 0x78(%rsp)
movq %rax, 0x80(%rsp)
movq 0x1447e5(%rip), %rsi    # 0x15a6a8
cmpq 0x1447e6(%rip), %rsi    # 0x15a6b0
je 0x15ee8
movdqu 0x78(%rsp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x1447ca(%rip)   # 0x15a6a8
jmp 0x15ef9
movl %r13d, %ebp
jmp 0x15555
leaq 0x1447b1(%rip), %rdi    # 0x15a6a0
leaq 0x78(%rsp), %rdx
callq 0x14b86
leal -0x3(%r12), %edx
leal 0x1(%r14), %ecx
movl %r13d, %r8d
notl %r8d
movl %r13d, %r9d
negl %r9d
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x588(%rsp), %rdi
movq 0x18(%rsp), %rsi
pushq %rax
pushq $0x1
pushq %rax
callq 0x15537
addq $0x20, %rsp
negl %eax
movq 0x144771(%rip), %rcx    # 0x15a6a8
cmpq %rcx, 0x144762(%rip)    # 0x15a6a0
movq %rbp, %rbx
je 0x15f4e
addq $-0x10, %rcx
movq %rcx, 0x14475a(%rip)    # 0x15a6a8
cmpl 0xc(%rsp), %eax
movq 0x10(%rsp), %rsi
jl 0x15773
movl 0xc(%rsp), %ebp
jmp 0x15555
jmp 0x15f6c
jmp 0x15f6c
jmp 0x15f6c
movq %rax, %rbx
movq 0xdb0(%rsp), %rdi
testq %rdi, %rdi
je 0x15f8c
movq 0xdc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4250
movq %rbx, %rdi
callq 0x43b0