// File: /workspace/github_cpp_makefile_star2_O3/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 $0xde8, %rsp            # imm = 0xDE8
movl %r9d, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
xorl %ebp, %ebp
cmpb $0x0, 0x3a(%rsi)
je 0x1544b
movl %ebp, %eax
addq $0xde8, %rsp            # imm = 0xDE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %ecx, %r14d
movl %edx, %r13d
movq %rdi, %r15
movb 0xe30(%rsp), %bl
movb 0xe28(%rsp), %al
movb %al, 0x18(%rsp)
movb 0xe20(%rsp), %al
movb %al, 0xf(%rsp)
movl 0x1c(%rsi), %eax
movq %rsi, 0x28(%rsp)
imull $0xb7a32847, %eax, %ecx # imm = 0xB7A32847
addl $0x576198, %ecx         # imm = 0x576198
rorl $0x3, %ecx
cmpl $0x15d866, %ecx         # imm = 0x15D866
movq 0x28(%rsp), %r12
ja 0x154a6
movq %r12, %rdi
callq 0x14f74
testb %al, %al
jne 0x15437
movl 0x1c(%r12), %eax
incl %eax
movl %eax, 0x1c(%r12)
testl %r13d, %r13d
je 0x1554f
testb %bl, %bl
jne 0x15513
movq 0x1451e7(%rip), %rax    # 0x15a6a8
movq 0x1451d8(%rip), %rcx    # 0x15a6a0
movq %rax, %rdx
subq %rcx, %rdx
cmpq $0x41, %rdx
jb 0x154f8
shlq $0x1c, %rdx
movabsq $-0x500000000, %rsi     # imm = 0xFFFFFFFB00000000
addq %rdx, %rsi
sarq $0x1c, %rsi
movq 0x8(%rcx,%rsi), %rcx
cmpq -0x8(%rax), %rcx
je 0x15437
movq %r15, %rdi
callq 0x186de
testb %al, %al
jne 0x15437
cmpl $0x63, 0x8(%r15)
jg 0x15437
movq 0x18(%r15), %rcx
leaq 0x14f0d2(%rip), %rax    # 0x1645f0
movq (%rax), %rsi
movq 0x8(%rax), %rdi
subq %rsi, %rdi
sarq $0x5, %rdi
xorl %r12d, %r12d
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
shlq $0x5, %rdx
cmpq %rcx, (%rsi,%rdx)
jne 0x155a4
addq %rdx, %rsi
cmpl %r13d, 0x10(%rsi)
jge 0x15577
xorl %r12d, %r12d
jmp 0x155a4
movq %r15, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl 0x14(%rsp), %ecx
movl 0x10(%rsp), %r8d
addq $0xde8, %rsp            # imm = 0xDE8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1513d
movl 0xc(%rsi), %eax
movl 0x14(%rsi), %ebp
testl %eax, %eax
je 0x15437
cmpl $0x1, %eax
jne 0x15595
cmpl 0x10(%rsp), %ebp
jl 0x1559f
jmp 0x15e77
cmpl 0x14(%rsp), %ebp
jle 0x15dac
movzwl 0x8(%rsi), %r12d
leaq 0x140135(%rip), %rdi    # 0x1556e0
movl %r14d, %esi
callq 0xf8ec
cmpq 0x18(%r15), %rax
jne 0x155cb
leaq 0x140120(%rip), %rdi    # 0x1556e0
movl %r14d, %esi
callq 0xf8fa
movl %eax, %r12d
cmpb $0x0, 0xf(%rsp)
je 0x15682
movq $0x0, 0x30(%rsp)
movb 0x18(%rsp), %bl
testb %bl, %bl
jne 0x156ae
cmpl $0x6, %r13d
jl 0x156ae
cmpq $0x0, 0x28(%r15)
jne 0x156ae
testw %r12w, %r12w
jne 0x156ae
leal (%r13,%r13,2), %edx
shrl $0x2, %edx
addl $-0x2, %edx
subq $0x8, %rsp
movl $0x1, %eax
movq %r15, %rdi
movq 0x30(%rsp), %rsi
movl %r14d, %ecx
movl 0x1c(%rsp), %r8d
movl 0x18(%rsp), %r9d
pushq $0x0
pushq %rax
pushq %rax
callq 0x15414
addq $0x20, %rsp
movq 0x18(%r15), %rcx
leaq 0x14efa5(%rip), %rax    # 0x1645f0
movq (%rax), %rsi
movq 0x8(%rax), %rdi
subq %rsi, %rdi
sarq $0x5, %rdi
movq $0x0, 0x30(%rsp)
movq %rcx, %rax
xorl %edx, %edx
divq %rdi
shlq $0x5, %rdx
cmpq %rcx, (%rsi,%rdx)
jne 0x15da4
addq %rdx, %rsi
movzwl 0x8(%rsi), %r12d
jmp 0x156ae
leaq 0x590(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0xdff4
movq %rbx, %rdi
callq 0xeeae
movq %rax, 0x30(%rsp)
movb 0x18(%rsp), %bl
testb %bl, %bl
je 0x15c18
movq %r12, 0x38(%rsp)
movzwl %r12w, %edx
leaq 0x144fe2(%rip), %rcx    # 0x15a6a0
leaq 0x590(%rsp), %rdi
movq %r15, %rsi
movl %r14d, %r8d
xorl %r9d, %r9d
callq 0xfcfa
movq %r14, %rax
leaq 0x2e8(%r15), %r14
movl $0x7fffffce, %edx       # imm = 0x7FFFFFCE
movl %r13d, %ecx
shll %cl, %edx
movl %edx, 0x64(%rsp)
movq 0x30(%rsp), %rcx
addl $0x12c, %ecx            # imm = 0x12C
movq %rcx, 0x30(%rsp)
leal -0x1(%r13), %ecx
movl %ecx, 0x60(%rsp)
movq %r13, 0x18(%rsp)
leal -0x2(%r13), %ecx
movl %ecx, 0x5c(%rsp)
movq %rax, 0x68(%rsp)
incl %eax
movl %eax, 0x24(%rsp)
movl 0x10(%rsp), %eax
negl %eax
movl %eax, 0x40(%rsp)
movb $0x1, %al
movl %eax, 0x48(%rsp)
movl $0xffff3cb0, %edi       # imm = 0xFFFF3CB0
movzbl %bl, %eax
movq %rax, 0x50(%rsp)
movzbl 0xf(%rsp), %eax
movq %rax, 0x70(%rsp)
movl 0x14(%rsp), %ebp
movl $0x0, 0x44(%rsp)
movl %edi, 0x4c(%rsp)
cmpl $0xffff8034, %edi       # imm = 0xFFFF8034
setl %r13b
orb 0xf(%rsp), %r13b
leaq 0x590(%rsp), %rdi
callq 0xffc4
movl %eax, %r12d
testw %ax, %ax
je 0x15aa8
cmpq $0x0, 0x28(%r15)
setne %al
orb %r13b, %al
movzwl %r12w, %ebx
jne 0x15816
movq %r15, %rdi
movl %ebx, %esi
callq 0x17326
testb %al, %al
jne 0x15816
movl (%r15), %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%r14,%rax,8), %ecx
addl 0x4(%r14,%rax,8), %ecx
addl 0xc(%r14,%rax,8), %ecx
addl 0x10(%r14,%rax,8), %ecx
je 0x15816
movq 0x18(%rsp), %rax
cmpl $0x1, %eax
jne 0x157fd
testl $0x7000, %r12d          # imm = 0x7000
jne 0x15802
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl 0x4(%r15), %ecx
movq 0x30(%r15), %rdx
orq 0x78(%r15,%rcx,8), %rdx
leaq 0xe3285(%rip), %rcx     # 0xf8a70
andq (%rcx,%rax,8), %rdx
jne 0x15802
cmpl %ebp, 0x30(%rsp)
jl 0x15762
jmp 0x15802
cmpl $0x2, %eax
jg 0x15816
movq %r15, %rdi
movl %ebx, %esi
callq 0x17672
cmpl 0x64(%rsp), %eax
jl 0x15762
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x1637c
leaq 0x88(%rsp), %rdi
movl %ebx, %esi
callq 0x17a3a
movq 0xa0(%rsp), %rax
movw %r12w, 0x78(%rsp)
movq %rax, 0x80(%rsp)
movq 0x144e56(%rip), %rsi    # 0x15a6a8
cmpq 0x144e57(%rip), %rsi    # 0x15a6b0
je 0x15874
movdqu 0x78(%rsp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x144e3b(%rip)   # 0x15a6a8
movq 0x18(%rsp), %rcx
jmp 0x1588a
leaq 0x144e25(%rip), %rdi    # 0x15a6a0
leaq 0x78(%rsp), %rdx
callq 0x14a78
movq 0x18(%rsp), %rcx
movq 0xb0(%rsp), %rax
testq %rax, %rax
movl 0x60(%rsp), %edx
movl %edx, %ebx
movl $0x1, %esi
cmovnel %esi, %ebx
cmpl $0x1, %ecx
cmovnel %edx, %ebx
testb $0x1, 0x48(%rsp)
je 0x158f7
movl %ebp, %r9d
negl %r9d
subq $0x8, %rsp
leaq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl %ebx, %edx
movl 0x2c(%rsp), %ecx
movl 0x48(%rsp), %r8d
pushq $0x0
pushq 0x60(%rsp)
pushq 0x88(%rsp)
callq 0x15414
addq $0x20, %rsp
negl %eax
movl %r12d, %ecx
movq %rcx, 0x38(%rsp)
jmp 0x1599b
testq %rax, %rax
setne %al
cmpl $0x3, %ecx
setl %cl
cmpl $0x3, 0x44(%rsp)
setb %dl
orb %cl, %dl
orb 0xf(%rsp), %dl
cmpq $0x0, 0x28(%r15)
setne %cl
orb %dl, %cl
orb %al, %cl
movl %ebp, %r13d
notl %r13d
je 0x15a32
movl %ebp, %r9d
negl %r9d
subq $0x8, %rsp
leaq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl %ebx, %edx
movl 0x2c(%rsp), %ecx
movl %r13d, %r8d
xorl %eax, %eax
pushq %rax
pushq 0x60(%rsp)
pushq %rax
callq 0x15414
addq $0x20, %rsp
negl %eax
cmpl %eax, %ebp
jge 0x1599b
cmpl 0x10(%rsp), %eax
jge 0x1599b
movl %ebp, %r9d
negl %r9d
subq $0x8, %rsp
leaq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl %ebx, %edx
movl 0x2c(%rsp), %ecx
movl 0x48(%rsp), %r8d
pushq $0x0
pushq 0x60(%rsp)
pushq $0x1
callq 0x15414
addq $0x20, %rsp
negl %eax
movq 0x144d06(%rip), %rcx    # 0x15a6a8
cmpq %rcx, 0x144cf7(%rip)    # 0x15a6a0
movl 0x4c(%rsp), %edi
je 0x159ba
addq $-0x10, %rcx
movq %rcx, 0x144cee(%rip)    # 0x15a6a8
cmpl %edi, %eax
cmovgl %eax, %edi
movq 0x38(%rsp), %rax
cmovgl %r12d, %eax
movq %rax, 0x38(%rsp)
cmpl %edi, %ebp
cmovlel %edi, %ebp
movl %r12d, %eax
shrl $0x6, %eax
movl 0x4(%r15), %edx
movq 0x30(%r15), %rcx
orq 0x78(%r15,%rdx,8), %rcx
andl $0x3f, %eax
leaq 0xe3081(%rip), %rdx     # 0xf8a70
andq (%rdx,%rax,8), %rcx
cmpl 0x10(%rsp), %ebp
movq 0x18(%rsp), %rbx
jge 0x15d5a
testq %rcx, %rcx
jne 0x15a21
andl $0x3f, %r12d
shll $0x8, %r12d
leaq 0x144c8a(%rip), %rcx    # 0x15a6a0
addq %rcx, %r12
addl %ebx, 0xe0(%r12,%rax,4)
incl 0x44(%rsp)
movl $0x0, 0x48(%rsp)
jmp 0x1574f
testl $0x7000, %r12d          # imm = 0x7000
jne 0x15929
movl %r12d, %eax
shrl $0x6, %eax
andl $0x3f, %eax
movl 0x4(%r15), %ecx
movq 0x30(%r15), %rdx
orq 0x78(%r15,%rcx,8), %rdx
leaq 0xe3014(%rip), %rcx     # 0xf8a70
andq (%rcx,%rax,8), %rdx
jne 0x15929
movl %ebp, %r9d
negl %r9d
subq $0x8, %rsp
leaq 0x90(%rsp), %rdi
movq 0x30(%rsp), %rsi
movl 0x64(%rsp), %edx
movl 0x2c(%rsp), %ecx
movl %r13d, %r8d
xorl %eax, %eax
pushq %rax
pushq 0x60(%rsp)
pushq %rax
callq 0x15414
addq $0x20, %rsp
negl %eax
cmpl %eax, %ebp
jl 0x15929
jmp 0x1595c
movq 0x68(%rsp), %r11
movq 0x18(%rsp), %rbx
movl 0x4c(%rsp), %edi
cmpl $0xffff3cb0, %edi       # imm = 0xFFFF3CB0
jne 0x15b75
movl (%r15), %ecx
movl 0x4(%r15), %edx
imulq $0xf0, %rcx, %rax
movl 0x3f0(%r15,%rax), %eax
shlq $0x9, %rcx
addq 0xf4cd(%rip), %rcx      # 0x24fb0
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movq 0x288(%r15,%rdx), %rsi
testq %rsi, (%rcx,%rax,8)
jne 0x15b66
leaq 0x288(%r15), %rsi
leaq 0x5f39(%rip), %rcx      # 0x1ba40
movq 0x8(%rsi,%rdx), %rdi
testq %rdi, (%rcx,%rax,8)
jne 0x15b66
movq 0x80(%r15), %rdi
orq 0x78(%r15), %rdi
leaq 0xf6ec(%rip), %rcx      # 0x25210
leaq 0x5d15(%rip), %r8       # 0x1b840
movq (%r8,%rax,8), %r9
andq %rdi, %r9
leaq 0x5b07(%rip), %r8       # 0x1b640
imulq (%r8,%rax,8), %r9
movq (%rcx,%rax,8), %r10
leaq 0x59f7(%rip), %rcx      # 0x1b540
movb (%rcx,%rax,4), %cl
shrq %cl, %r9
movq 0x20(%rsi,%rdx), %r8
movq 0x10(%rsi,%rdx), %rcx
orq %r8, %rcx
testq %rcx, (%r10,%r9,8)
je 0x15db5
addl $0xffff8001, %r11d      # imm = 0xFFFF8001
movl %r11d, %ebp
jmp 0x15ced
cmpl 0x14(%rsp), %ebp
setle %al
cmpl 0x10(%rsp), %ebp
setge %cl
orb %al, %cl
jne 0x15bad
movq 0x28(%rsp), %rax
cmpb $0x0, 0x3a(%rax)
jne 0x15bad
movq 0x18(%r15), %rdx
movzwl 0x38(%rsp), %esi
leaq 0x13fb3e(%rip), %rdi    # 0x1556e0
movl %r11d, %ecx
movl %ebp, %r8d
callq 0xf858
xorl %eax, %eax
cmpl 0x10(%rsp), %ebp
setge %al
cmpl 0x14(%rsp), %ebp
movq 0x18(%r15), %rcx
movl $0x2, %esi
cmovgl %eax, %esi
leaq 0x14ea23(%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
cmpl %ebx, 0x10(%rdi,%rax)
jge 0x15cda
movq %rcx, (%rdi,%rax)
movq 0x38(%rsp), %rcx
movw %cx, 0x8(%rdi,%rax)
movl %esi, 0xc(%rdi,%rax)
movl %ebx, 0x10(%rdi,%rax)
movl %ebp, 0x14(%rdi,%rax)
movb $0x0, 0x18(%rdi,%rax)
jmp 0x15ced
movq 0x28(%r15), %rax
testq %rax, %rax
setne %cl
cmpl $0x3, %r13d
setge %dl
orb %cl, %dl
je 0x15d13
testq %rax, %rax
setne %al
cmpl $0x4, %r13d
setl %cl
orb %al, %cl
jne 0x156ae
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 0x156ae
leaq 0x590(%rsp), %rbx
movl $0x508, %edx            # imm = 0x508
movq %rbx, %rdi
movq %r15, %rsi
callq 0x41c0
movq %rbx, %rdi
callq 0x185e0
movq 0x18(%rbx), %rax
movw $0x0, 0x88(%rsp)
movq %rax, 0x90(%rsp)
movq 0x1449f5(%rip), %rsi    # 0x15a6a8
cmpq 0x1449f6(%rip), %rsi    # 0x15a6b0
je 0x15e02
movdqu 0x88(%rsp), %xmm0
movdqu %xmm0, (%rsi)
addq $0x10, 0x1449d3(%rip)   # 0x15a6a8
jmp 0x15e16
testl %esi, %esi
je 0x15bf4
cmpb $0x0, 0x18(%rdi,%rax)
jne 0x15bf4
movq 0xdc0(%rsp), %rdi
testq %rdi, %rdi
je 0x15437
movq 0xdd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4250
jmp 0x15437
movl (%r15), %eax
leaq (%rax,%rax,2), %rax
movl 0x2f0(%r15,%rax,8), %ecx
addl 0x2ec(%r15,%rax,8), %ecx
addl 0x2f4(%r15,%rax,8), %ecx
addl 0x2f8(%r15,%rax,8), %ecx
je 0x156ae
imull $-0x64, %r13d, %eax
movq 0x30(%rsp), %rcx
addl %eax, %ecx
cmpl 0x10(%rsp), %ecx
jl 0x156ae
jmp 0x15e77
testq %rcx, %rcx
movq 0x68(%rsp), %r11
jne 0x15d9b
movslq %r11d, %rcx
leaq 0x144932(%rip), %rsi    # 0x15a6a0
movzwl 0x18(%rsi,%rcx,4), %edx
cmpw %r12w, %dx
je 0x15d84
movw %dx, 0x1a(%rsi,%rcx,4)
movw %r12w, 0x18(%rsi,%rcx,4)
movl %ebx, %ecx
imull %ebx, %ecx
andl $0x3f, %r12d
shll $0x8, %r12d
addq %r12, %rsi
addl %ecx, 0x40e0(%rsi,%rax,4)
movl 0x10(%rsp), %ebp
jmp 0x15ab6
xorl %r12d, %r12d
jmp 0x156ae
movl 0x14(%rsp), %ebp
jmp 0x15437
leaq 0x5584(%rip), %rcx      # 0x1b340
andq (%rcx,%rax,8), %rdi
leaq 0x5379(%rip), %rcx      # 0x1b140
imulq (%rcx,%rax,8), %rdi
leaq 0x526d(%rip), %rcx      # 0x1b040
movb (%rcx,%rax,4), %cl
shrq %cl, %rdi
leaq 0xf630(%rip), %rcx      # 0x25410
orq 0x18(%rsi,%rdx), %r8
movq (%rcx,%rax,8), %rax
andq (%rax,%rdi,8), %r8
addl $0xffff8001, %r11d      # imm = 0xFFFF8001
xorl %ebp, %ebp
testq %r8, %r8
cmovnel %r11d, %ebp
jmp 0x15ced
leaq 0x144897(%rip), %rdi    # 0x15a6a0
leaq 0x88(%rsp), %rdx
callq 0x14a78
leal -0x3(%r13), %edx
leal 0x1(%r14), %ecx
movl 0x14(%rsp), %r9d
movl %r9d, %r8d
notl %r8d
negl %r9d
subq $0x8, %rsp
xorl %eax, %eax
leaq 0x598(%rsp), %rdi
movq 0x30(%rsp), %rsi
pushq %rax
pushq $0x1
pushq %rax
callq 0x15414
addq $0x20, %rsp
negl %eax
movq 0x144853(%rip), %rcx    # 0x15a6a8
cmpq %rcx, 0x144844(%rip)    # 0x15a6a0
movb 0x18(%rsp), %bl
je 0x15e6d
addq $-0x10, %rcx
movq %rcx, 0x14483b(%rip)    # 0x15a6a8
cmpl 0x10(%rsp), %eax
jl 0x156ae
movl 0x10(%rsp), %ebp
jmp 0x15437
jmp 0x15e86
jmp 0x15e86
jmp 0x15e86
movq %rax, %rbx
movq 0xdc0(%rsp), %rdi
testq %rdi, %rdi
je 0x15ea6
movq 0xdd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4250
movq %rbx, %rdi
callq 0x43b0