// File: VanAndelInstitute[P]intent/src/edlib.cpp
// Function: myersCalcEditDistanceNW(unsigned long const*, int, int, int, unsigned char const*, int, int, int*, int*, bool, AlignmentData**, int)
static int myersCalcEditDistanceNW(const Word* const Peq, const int W, const int maxNumBlocks,
                                   const int queryLength,
                                   const unsigned char* const target, const int targetLength,
                                   int k, int* const bestScore_,
                                   int* const position_, const bool findAlignment,
                                   AlignmentData** const alignData, const int targetStopPosition) {
    if (targetStopPosition > -1 && findAlignment) {
        // They can not be both set at the same time!
        return EDLIB_STATUS_ERROR;
    }

    // Each STRONG_REDUCE_NUM column is reduced in more expensive way.
    const int STRONG_REDUCE_NUM = 2048; // TODO: Choose this number dinamically (based on query and target lengths?), so it does not affect speed of computation

    if (k < abs(targetLength - queryLength)) {
        *bestScore_ = *position_ = -1;
        return EDLIB_STATUS_OK;
    }

    k = min(k, max(queryLength, targetLength));  // Upper bound for k

    // firstBlock is 0-based index of first block in Ukkonen band.
    // lastBlock is 0-based index of last block in Ukkonen band.
    int firstBlock = 0;
    // This is optimal now, by my formula.
    int lastBlock = min(maxNumBlocks, ceilDiv(min(k, (k + queryLength - targetLength) / 2) + 1, WORD_SIZE)) - 1;
    Block* bl; // Current block

    Block* blocks = new Block[maxNumBlocks];

    // Initialize P, M and score
    bl = blocks;
    for (int b = 0; b <= lastBlock; b++) {
        bl->score = (b + 1) * WORD_SIZE;
        bl->P = static_cast<Word>(-1); // All 1s
        bl->M = static_cast<Word>(0);
        bl++;
    }

    // If we want to find alignment, we have to store needed data.
    if (findAlignment)
        *alignData = new AlignmentData(maxNumBlocks, targetLength);
    else if (targetStopPosition > -1)
        *alignData = new AlignmentData(maxNumBlocks, 1);
    else
        *alignData = NULL;

    const unsigned char* targetChar = target;
    for (int c = 0; c < targetLength; c++) { // for each column
        const Word* Peq_c = Peq + *targetChar * maxNumBlocks;

        //----------------------- Calculate column -------------------------//
        int hout = 1;
        bl = blocks + firstBlock;
        for (int b = firstBlock; b <= lastBlock; b++) {
            hout = calculateBlock(bl->P, bl->M, Peq_c[b], hout, bl->P, bl->M);
            bl->score += hout;
            bl++;
        }
        bl--;
        //------------------------------------------------------------------//
        // bl now points to last block

        // Update k. I do it only on end of column because it would slow calculation too much otherwise.
        // NOTICE: I add W when in last block because it is actually result from W cells to the left and W cells up.
        k = min(k, bl->score
                + max(targetLength - c - 1, queryLength - ((1 + lastBlock) * WORD_SIZE - 1) - 1)
                + (lastBlock == maxNumBlocks - 1 ? W : 0));

        //---------- Adjust number of blocks according to Ukkonen ----------//
        //--- Adjust last block ---//
        // If block is not beneath band, calculate next block. Only next because others are certainly beneath band.
        if (lastBlock + 1 < maxNumBlocks
            && !(//score[lastBlock] >= k + WORD_SIZE ||  // NOTICE: this condition could be satisfied if above block also!
                 ((lastBlock + 1) * WORD_SIZE - 1
                  > k - bl->score + 2 * WORD_SIZE - 2 - targetLength + c + queryLength))) {
            lastBlock++; bl++;
            bl->P = static_cast<Word>(-1); // All 1s
            bl->M = static_cast<Word>(0);
            int newHout = calculateBlock(bl->P, bl->M, Peq_c[lastBlock], hout, bl->P, bl->M);
            bl->score = (bl - 1)->score - hout + WORD_SIZE + newHout;
            hout = newHout;
        }

        // While block is out of band, move one block up.
        // NOTE: Condition used here is more loose than the one from the article, since I simplified the max() part of it.
        // I could consider adding that max part, for optimal performance.
        while (lastBlock >= firstBlock
               && (bl->score >= k + WORD_SIZE
                   || ((lastBlock + 1) * WORD_SIZE - 1 >
                       // TODO: Does not work if do not put +1! Why???
                       k - bl->score + 2 * WORD_SIZE - 2 - targetLength + c + queryLength + 1))) {
            lastBlock--; bl--;
        }
        //-------------------------//

        //--- Adjust first block ---//
        // While outside of band, advance block
        while (firstBlock <= lastBlock
               && (blocks[firstBlock].score >= k + WORD_SIZE
                   || ((firstBlock + 1) * WORD_SIZE - 1 <
                       blocks[firstBlock].score - k - targetLength + queryLength + c))) {
            firstBlock++;
        }
        //--------------------------/


        // TODO: consider if this part is useful, it does not seem to help much
        if (c % STRONG_REDUCE_NUM == 0) { // Every some columns do more expensive but more efficient reduction
            while (lastBlock >= firstBlock) {
                // If all cells outside of band, remove block
                vector<int> scores = getBlockCellValues(*bl);
                int numCells = lastBlock == maxNumBlocks - 1 ? WORD_SIZE - W : WORD_SIZE;
                int r = lastBlock * WORD_SIZE + numCells - 1;
                bool reduce = true;
                for (int i = WORD_SIZE - numCells; i < WORD_SIZE; i++) {
                    // TODO: Does not work if do not put +1! Why???
                    if (scores[i] <= k && r <= k - scores[i] - targetLength + c + queryLength + 1) {
                        reduce = false;
                        break;
                    }
                    r--;
                }
                if (!reduce) break;
                lastBlock--; bl--;
            }

            while (firstBlock <= lastBlock) {
                // If all cells outside of band, remove block
                vector<int> scores = getBlockCellValues(blocks[firstBlock]);
                int numCells = firstBlock == maxNumBlocks - 1 ? WORD_SIZE - W : WORD_SIZE;
                int r = firstBlock * WORD_SIZE + numCells - 1;
                bool reduce = true;
                for (int i = WORD_SIZE - numCells; i < WORD_SIZE; i++) {
                    if (scores[i] <= k && r >= scores[i] - k - targetLength + c + queryLength) {
                        reduce = false;
                        break;
                    }
                    r--;
                }
                if (!reduce) break;
                firstBlock++;
            }
        }


        // If band stops to exist finish
        if (lastBlock < firstBlock) {
            *bestScore_ = *position_ = -1;
            delete[] blocks;
            return EDLIB_STATUS_OK;
        }
        //------------------------------------------------------------------//


        //---- Save column so it can be used for reconstruction ----//
        if (findAlignment && c < targetLength) {
            bl = blocks + firstBlock;
            for (int b = firstBlock; b <= lastBlock; b++) {
                (*alignData)->Ps[maxNumBlocks * c + b] = bl->P;
                (*alignData)->Ms[maxNumBlocks * c + b] = bl->M;
                (*alignData)->scores[maxNumBlocks * c + b] = bl->score;
                (*alignData)->firstBlocks[c] = firstBlock;
                (*alignData)->lastBlocks[c] = lastBlock;
                bl++;
            }
        }
        //----------------------------------------------------------//
        //---- If this is stop column, save it and finish ----//
        if (c == targetStopPosition) {
            for (int b = firstBlock; b <= lastBlock; b++) {
                (*alignData)->Ps[b] = (blocks + b)->P;
                (*alignData)->Ms[b] = (blocks + b)->M;
                (*alignData)->scores[b] = (blocks + b)->score;
                (*alignData)->firstBlocks[0] = firstBlock;
                (*alignData)->lastBlocks[0] = lastBlock;
            }
            *bestScore_ = -1;
            *position_ = targetStopPosition;
            delete[] blocks;
            return EDLIB_STATUS_OK;
        }
        //----------------------------------------------------//

        targetChar++;
    }

    if (lastBlock == maxNumBlocks - 1) { // If last block of last column was calculated
        // Obtain best score from block -> it is complicated because query is padded with W cells
        int bestScore = getBlockCellValues(blocks[lastBlock])[W];
        if (bestScore <= k) {
            *bestScore_ = bestScore;
            *position_ = targetLength - 1;
            delete[] blocks;
            return EDLIB_STATUS_OK;
        }
    }

    *bestScore_ = *position_ = -1;
    delete[] blocks;
    return EDLIB_STATUS_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movb 0x28(%rbp), %al
movq 0x20(%rbp), %r10
movq 0x18(%rbp), %r10
movl 0x10(%rbp), %r10d
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
andb $0x1, %al
movb %al, -0x2d(%rbp)
cmpl $-0x1, 0x38(%rbp)
jle 0x661c3
testb $0x1, -0x2d(%rbp)
je 0x661c3
movl $0x1, -0x4(%rbp)
jmp 0x66e85
movl $0x800, -0x34(%rbp)     # imm = 0x800
movl 0x10(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl -0x1c(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cmpl %ecx, %eax
jge 0x661fe
movq 0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x66e85
movl 0x10(%rbp), %eax
movl %eax, -0x170(%rbp)
movl -0x1c(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x677d0
movl -0x170(%rbp), %edi
movl %eax, %esi
callq 0x67490
movl %eax, 0x10(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x16c(%rbp)
movl 0x10(%rbp), %edi
movl 0x10(%rbp), %eax
addl -0x1c(%rbp), %eax
subl -0x2c(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %esi
callq 0x67490
movl %eax, %edi
addl $0x1, %edi
movl $0x40, %esi
callq 0x655f0
movl -0x16c(%rbp), %edi
movl %eax, %esi
callq 0x67490
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
movslq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, -0x168(%rbp)
callq 0x8040
movq %rax, %rcx
movq -0x160(%rbp), %rax
movq %rcx, -0x158(%rbp)
cmpq $0x0, %rax
je 0x66312
movq -0x158(%rbp), %rax
movq -0x160(%rbp), %rcx
imulq $0x18, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x180(%rbp)
movq %rax, -0x178(%rbp)
movq -0x178(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x69000
jmp 0x662f4
movq -0x180(%rbp), %rcx
movq -0x188(%rbp), %rax
addq $0x18, %rax
cmpq %rcx, %rax
movq %rax, -0x178(%rbp)
jne 0x662df
movq -0x158(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x66396
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
shll $0x6, %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
movq $-0x1, (%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6632c
movq -0x168(%rbp), %rsi
movq -0x158(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
callq 0x8a20
jmp 0x66e91
testb $0x1, -0x2d(%rbp)
je 0x663f5
movl $0x28, %edi
callq 0x8550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x190(%rbp)
movl -0x18(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x69f30
jmp 0x663c0
movq -0x190(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x66460
movq -0x190(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x28, %esi
callq 0x8560
jmp 0x66e91
cmpl $-0x1, 0x38(%rbp)
jle 0x66453
movl $0x28, %edi
callq 0x8550
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x198(%rbp)
movl -0x18(%rbp), %esi
movl $0x1, %edx
callq 0x69f30
jmp 0x66421
movq -0x198(%rbp), %rcx
movq 0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x6645e
movq -0x198(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
movl $0x28, %esi
callq 0x8560
jmp 0x66e91
movq 0x30(%rbp), %rax
movq $0x0, (%rax)
jmp 0x66460
movq -0x28(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x66d66
movq -0x10(%rbp), %rax
movq -0x68(%rbp), %rcx
movzbl (%rcx), %ecx
imull -0x18(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x1, -0x7c(%rbp)
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x66516
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x78(%rbp), %rax
movslq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl -0x7c(%rbp), %ecx
movq -0x48(%rbp), %r8
movq -0x48(%rbp), %r9
addq $0x8, %r9
callq 0x674c0
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %ecx
movq -0x48(%rbp), %rax
addl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x664b8
movq -0x48(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x48(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x1a4(%rbp)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x1a0(%rbp)
movl -0x2c(%rbp), %edi
subl -0x6c(%rbp), %edi
subl $0x1, %edi
movl -0x1c(%rbp), %esi
movl -0x3c(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
subl $0x1, %eax
subl %eax, %esi
subl $0x1, %esi
callq 0x677d0
movl %eax, %ecx
movl -0x1a0(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x19c(%rbp)
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x66582
movl -0x14(%rbp), %eax
movl %eax, -0x1a8(%rbp)
jmp 0x6658c
xorl %eax, %eax
movl %eax, -0x1a8(%rbp)
jmp 0x6658c
movl -0x1a4(%rbp), %edi
movl -0x19c(%rbp), %esi
movl -0x1a8(%rbp), %eax
addl %eax, %esi
callq 0x67490
movl %eax, 0x10(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
cmpl -0x18(%rbp), %eax
jge 0x6666b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
subl $0x1, %eax
movl 0x10(%rbp), %ecx
movq -0x48(%rbp), %rdx
subl 0x10(%rdx), %ecx
addl $0x80, %ecx
subl $0x2, %ecx
subl -0x2c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
addl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jg 0x6666b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq $-0x1, (%rax)
movq -0x48(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x78(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl -0x7c(%rbp), %ecx
movq -0x48(%rbp), %r8
movq -0x48(%rbp), %r9
addq $0x8, %r9
callq 0x674c0
movl %eax, -0x84(%rbp)
movq -0x48(%rbp), %rax
movl -0x8(%rax), %ecx
subl -0x7c(%rbp), %ecx
addl $0x40, %ecx
addl -0x84(%rbp), %ecx
movq -0x48(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x84(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x6666d
movl -0x3c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x38(%rbp), %ecx
movb %al, -0x1a9(%rbp)
jl 0x666d8
movq -0x48(%rbp), %rax
movl 0x10(%rax), %ecx
movl 0x10(%rbp), %edx
addl $0x40, %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x1aa(%rbp)
jge 0x666cc
movl -0x3c(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
subl $0x1, %eax
movl 0x10(%rbp), %ecx
movq -0x48(%rbp), %rdx
subl 0x10(%rdx), %ecx
addl $0x80, %ecx
subl $0x2, %ecx
subl -0x2c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
addl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
setg %al
movb %al, -0x1aa(%rbp)
movb -0x1aa(%rbp), %al
movb %al, -0x1a9(%rbp)
movb -0x1a9(%rbp), %al
testb $0x1, %al
jne 0x666e4
jmp 0x666fe
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x48(%rbp)
jmp 0x6666d
jmp 0x66700
movl -0x38(%rbp), %ecx
xorl %eax, %eax
cmpl -0x3c(%rbp), %ecx
movb %al, -0x1ab(%rbp)
jg 0x66775
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %ecx
movl 0x10(%rbp), %edx
addl $0x40, %edx
movb $0x1, %al
cmpl %edx, %ecx
movb %al, -0x1ac(%rbp)
jge 0x66769
movl -0x38(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
subl $0x1, %eax
movq -0x50(%rbp), %rcx
movslq -0x38(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x10(%rcx), %ecx
subl 0x10(%rbp), %ecx
subl -0x2c(%rbp), %ecx
addl -0x1c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x1ac(%rbp)
movb -0x1ac(%rbp), %al
movb %al, -0x1ab(%rbp)
movb -0x1ab(%rbp), %al
testb $0x1, %al
jne 0x66781
jmp 0x6678f
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x66700
movl -0x6c(%rbp), %eax
movl $0x800, %ecx            # imm = 0x800
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x66af5
jmp 0x667a5
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jl 0x66953
movq -0x48(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0xb8(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xb0(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb8(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x67690
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x6681e
movl $0x40, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x1b0(%rbp)
jmp 0x6682b
movl $0x40, %eax
movl %eax, -0x1b0(%rbp)
jmp 0x6682b
movl -0x1b0(%rbp), %eax
movl %eax, -0xbc(%rbp)
movl -0x3c(%rbp), %eax
shll $0x6, %eax
addl -0xbc(%rbp), %eax
subl $0x1, %eax
movl %eax, -0xc0(%rbp)
movb $0x1, -0xc1(%rbp)
movl $0x40, %eax
subl -0xbc(%rbp), %eax
movl %eax, -0xc8(%rbp)
cmpl $0x40, -0xc8(%rbp)
jge 0x66900
movslq -0xc8(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x69140
movl (%rax), %eax
cmpl 0x10(%rbp), %eax
jg 0x668dd
movl -0xc0(%rbp), %eax
movl %eax, -0x1b4(%rbp)
movl 0x10(%rbp), %eax
movl %eax, -0x1b8(%rbp)
movslq -0xc8(%rbp), %rsi
leaq -0xa0(%rbp), %rdi
callq 0x69140
movl -0x1b8(%rbp), %ecx
movq %rax, %rdx
movl -0x1b4(%rbp), %eax
subl (%rdx), %ecx
subl -0x2c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
addl -0x1c(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x668dd
movb $0x0, -0xc1(%rbp)
jmp 0x66900
movl -0xc0(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc0(%rbp)
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x66864
testb $0x1, -0xc1(%rbp)
jne 0x66915
movl $0x10, -0xcc(%rbp)
jmp 0x66934
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rax
addq $-0x18, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0xcc(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x36b20
movl -0xcc(%rbp), %eax
testl %eax, %eax
je 0x6694e
jmp 0x6694c
jmp 0x66953
jmp 0x667a5
jmp 0x66955
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x66af3
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x100(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0xf8(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0xf0(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x67690
movl -0x38(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x669d9
movl $0x40, %eax
subl -0x14(%rbp), %eax
movl %eax, -0x1bc(%rbp)
jmp 0x669e6
movl $0x40, %eax
movl %eax, -0x1bc(%rbp)
jmp 0x669e6
movl -0x1bc(%rbp), %eax
movl %eax, -0x104(%rbp)
movl -0x38(%rbp), %eax
shll $0x6, %eax
addl -0x104(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x108(%rbp)
movb $0x1, -0x109(%rbp)
movl $0x40, %eax
subl -0x104(%rbp), %eax
movl %eax, -0x110(%rbp)
cmpl $0x40, -0x110(%rbp)
jge 0x66aac
movslq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x69140
movl (%rax), %eax
cmpl 0x10(%rbp), %eax
jg 0x66a89
movl -0x108(%rbp), %eax
movl %eax, -0x1c0(%rbp)
movslq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x69140
movq %rax, %rcx
movl -0x1c0(%rbp), %eax
movl (%rcx), %ecx
subl 0x10(%rbp), %ecx
subl -0x2c(%rbp), %ecx
addl -0x6c(%rbp), %ecx
addl -0x1c(%rbp), %ecx
cmpl %ecx, %eax
jl 0x66a89
movb $0x0, -0x109(%rbp)
jmp 0x66aac
movl -0x108(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x108(%rbp)
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x110(%rbp)
jmp 0x66a1f
testb $0x1, -0x109(%rbp)
jne 0x66ac1
movl $0x15, -0xcc(%rbp)
jmp 0x66ad4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0xcc(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x36b20
movl -0xcc(%rbp), %eax
testl %eax, %eax
je 0x66aee
jmp 0x66aec
jmp 0x66af3
jmp 0x66955
jmp 0x66af5
movl -0x3c(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x66b3a
movq 0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rax
movq %rax, -0x1c8(%rbp)
cmpq $0x0, %rax
je 0x66b2e
movq -0x1c8(%rbp), %rdi
callq 0x8710
movl $0x0, -0x4(%rbp)
jmp 0x66e85
testb $0x1, -0x2d(%rbp)
je 0x66c38
movl -0x6c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x66c38
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x114(%rbp)
movl -0x114(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x66c36
movq -0x48(%rbp), %rax
movq (%rax), %rdx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movl -0x18(%rbp), %ecx
imull -0x6c(%rbp), %ecx
addl -0x114(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rdx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movl -0x18(%rbp), %ecx
imull -0x6c(%rbp), %ecx
addl -0x114(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %edx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movl -0x18(%rbp), %ecx
imull -0x6c(%rbp), %ecx
addl -0x114(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movslq -0x6c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x48(%rbp)
movl -0x114(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x114(%rbp)
jmp 0x66b6c
jmp 0x66c38
movl -0x6c(%rbp), %eax
cmpl 0x38(%rbp), %eax
jne 0x66d4c
movl -0x38(%rbp), %eax
movl %eax, -0x118(%rbp)
movl -0x118(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jg 0x66d10
movq -0x50(%rbp), %rax
movslq -0x118(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movslq -0x118(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
movslq -0x118(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rdx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movslq -0x118(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x50(%rbp), %rax
movslq -0x118(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %edx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
movslq -0x118(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %ecx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq 0x30(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movl %ecx, (%rax)
movl -0x118(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x118(%rbp)
jmp 0x66c4d
movq 0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl 0x38(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x1d0(%rbp)
cmpq $0x0, %rax
je 0x66d40
movq -0x1d0(%rbp), %rdi
callq 0x8710
movl $0x0, -0x4(%rbp)
jmp 0x66e85
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6646f
movl -0x3c(%rbp), %eax
movl -0x18(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x66e4d
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x150(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x148(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x150(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x67690
movslq -0x14(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x69140
movl (%rax), %eax
movl %eax, -0x1d4(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x36b20
movl -0x1d4(%rbp), %eax
movl %eax, -0x11c(%rbp)
movl -0x11c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jg 0x66e4b
movl -0x11c(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x1e0(%rbp)
cmpq $0x0, %rax
je 0x66e42
movq -0x1e0(%rbp), %rdi
callq 0x8710
movl $0x0, -0x4(%rbp)
jmp 0x66e85
jmp 0x66e4d
movq 0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x18(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x50(%rbp), %rax
movq %rax, -0x1e8(%rbp)
cmpq $0x0, %rax
je 0x66e7e
movq -0x1e8(%rbp), %rdi
callq 0x8710
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x8970
nopw (%rax,%rax)