// File: VanAndelInstitute[P]intent/src/edlib.cpp
// Function: obtainAlignmentHirschberg(unsigned char const*, unsigned char const*, int, unsigned char const*, unsigned char const*, int, EqualityDefinition const&, int, int, unsigned char**, int*)
static int obtainAlignmentHirschberg(
        const unsigned char* const query, const unsigned char* const rQuery, const int queryLength,
        const unsigned char* const target, const unsigned char* const rTarget, const int targetLength,
        const EqualityDefinition& equalityDefinition, const int alphabetLength, const int bestScore,
        unsigned char** const alignment, int* const alignmentLength) {

    const int maxNumBlocks = ceilDiv(queryLength, WORD_SIZE);
    const int W = maxNumBlocks * WORD_SIZE - queryLength;

    Word* Peq = buildPeq(alphabetLength, query, queryLength, equalityDefinition);
    Word* rPeq = buildPeq(alphabetLength, rQuery, queryLength, equalityDefinition);

    // Used only to call functions.
    int score_, endLocation_;

    // Divide dynamic matrix into two halfs, left and right.
    const int leftHalfWidth = targetLength / 2;
    const int rightHalfWidth = targetLength - leftHalfWidth;

    // Calculate left half.
    AlignmentData* alignDataLeftHalf = NULL;
    int leftHalfCalcStatus = myersCalcEditDistanceNW(
            Peq, W, maxNumBlocks, queryLength, target, targetLength, bestScore,
            &score_, &endLocation_, false, &alignDataLeftHalf, leftHalfWidth - 1);

    // Calculate right half.
    AlignmentData* alignDataRightHalf = NULL;
    int rightHalfCalcStatus = myersCalcEditDistanceNW(
            rPeq, W, maxNumBlocks, queryLength, rTarget, targetLength, bestScore,
            &score_, &endLocation_, false, &alignDataRightHalf, rightHalfWidth - 1);

    delete[] Peq;
    delete[] rPeq;

    if (leftHalfCalcStatus == EDLIB_STATUS_ERROR || rightHalfCalcStatus == EDLIB_STATUS_ERROR) {
        if (alignDataLeftHalf) delete alignDataLeftHalf;
        if (alignDataRightHalf) delete alignDataRightHalf;
        return EDLIB_STATUS_ERROR;
    }

    // Unwrap the left half.
    int firstBlockIdxLeft = alignDataLeftHalf->firstBlocks[0];
    int lastBlockIdxLeft = alignDataLeftHalf->lastBlocks[0];
    // TODO: avoid this allocation by using some shared array?
    // scoresLeft contains scores from left column, starting with scoresLeftStartIdx row (query index)
    // and ending with scoresLeftEndIdx row (0-indexed).
    int scoresLeftLength = (lastBlockIdxLeft - firstBlockIdxLeft + 1) * WORD_SIZE;
    int* scoresLeft = new int[scoresLeftLength];
    for (int blockIdx = firstBlockIdxLeft; blockIdx <= lastBlockIdxLeft; blockIdx++) {
        Block block(alignDataLeftHalf->Ps[blockIdx], alignDataLeftHalf->Ms[blockIdx],
                    alignDataLeftHalf->scores[blockIdx]);
        readBlock(block, scoresLeft + (blockIdx - firstBlockIdxLeft) * WORD_SIZE);
    }
    int scoresLeftStartIdx = firstBlockIdxLeft * WORD_SIZE;
    // If last block contains padding, shorten the length of scores for the length of padding.
    if (lastBlockIdxLeft == maxNumBlocks - 1) {
        scoresLeftLength -= W;
    }

    // Unwrap the right half (I also reverse it while unwraping).
    int firstBlockIdxRight = alignDataRightHalf->firstBlocks[0];
    int lastBlockIdxRight = alignDataRightHalf->lastBlocks[0];
    int scoresRightLength = (lastBlockIdxRight - firstBlockIdxRight + 1) * WORD_SIZE;
    int* scoresRight = new int[scoresRightLength];
    int* scoresRightOriginalStart = scoresRight;
    for (int blockIdx = firstBlockIdxRight; blockIdx <= lastBlockIdxRight; blockIdx++) {
        Block block(alignDataRightHalf->Ps[blockIdx], alignDataRightHalf->Ms[blockIdx],
                    alignDataRightHalf->scores[blockIdx]);
        readBlockReverse(block, scoresRight + (lastBlockIdxRight - blockIdx) * WORD_SIZE);
    }
    int scoresRightStartIdx = queryLength - (lastBlockIdxRight + 1) * WORD_SIZE;
    // If there is padding at the beginning of scoresRight (that can happen because of reversing that we do),
    // move pointer forward to remove the padding (that is why we remember originalStart).
    if (scoresRightStartIdx < 0) {
        //assert(scoresRightStartIdx == -1 * W);
        scoresRight += W;
        scoresRightStartIdx += W;
        scoresRightLength -= W;
    }

    delete alignDataLeftHalf;
    delete alignDataRightHalf;

    //--------------------- Find the best move ----------------//
    // Find the query/row index of cell in left column which together with its lower right neighbour
    // from right column gives the best score (when summed). We also have to consider boundary cells
    // (those cells at -1 indexes).
    //  x|
    //  -+-
    //   |x
    int queryIdxLeftStart = max(scoresLeftStartIdx, scoresRightStartIdx - 1);
    int queryIdxLeftEnd = min(scoresLeftStartIdx + scoresLeftLength - 1,
                          scoresRightStartIdx + scoresRightLength - 2);
    int leftScore = -1, rightScore = -1;
    int queryIdxLeftAlignment = -1;  // Query/row index of cell in left column where alignment is passing through.
    bool queryIdxLeftAlignmentFound = false;
    for (int queryIdx = queryIdxLeftStart; queryIdx <= queryIdxLeftEnd; queryIdx++) {
        leftScore = scoresLeft[queryIdx - scoresLeftStartIdx];
        rightScore = scoresRight[queryIdx + 1 - scoresRightStartIdx];
        if (leftScore + rightScore == bestScore) {
            queryIdxLeftAlignment = queryIdx;
            queryIdxLeftAlignmentFound = true;
            break;
        }
    }
    // Check boundary cells.
    if (!queryIdxLeftAlignmentFound && scoresLeftStartIdx == 0 && scoresRightStartIdx == 0) {
        leftScore = leftHalfWidth;
        rightScore = scoresRight[0];
        if (leftScore + rightScore == bestScore) {
            queryIdxLeftAlignment = -1;
            queryIdxLeftAlignmentFound = true;
        }
    }
    if (!queryIdxLeftAlignmentFound && scoresLeftStartIdx + scoresLeftLength == queryLength
        && scoresRightStartIdx + scoresRightLength == queryLength) {
        leftScore = scoresLeft[scoresLeftLength - 1];
        rightScore = rightHalfWidth;
        if (leftScore + rightScore == bestScore) {
            queryIdxLeftAlignment = queryLength - 1;
            queryIdxLeftAlignmentFound = true;
        }
    }

    delete[] scoresLeft;
    delete[] scoresRightOriginalStart;

    if (queryIdxLeftAlignmentFound == false) {
        // If there was no move that is part of optimal alignment, then there is no such alignment
        // or given bestScore is not correct!
        return EDLIB_STATUS_ERROR;
    }
    //----------------------------------------------------------//

    // Calculate alignments for upper half of left half (upper left - ul)
    // and lower half of right half (lower right - lr).
    const int ulHeight = queryIdxLeftAlignment + 1;
    const int lrHeight = queryLength - ulHeight;
    const int ulWidth = leftHalfWidth;
    const int lrWidth = rightHalfWidth;
    unsigned char* ulAlignment = NULL; int ulAlignmentLength;
    int ulStatusCode = obtainAlignment(query, rQuery + lrHeight, ulHeight,
                                       target, rTarget + lrWidth, ulWidth,
                                       equalityDefinition, alphabetLength, leftScore,
                                       &ulAlignment, &ulAlignmentLength);
    unsigned char* lrAlignment = NULL; int lrAlignmentLength;
    int lrStatusCode = obtainAlignment(query + ulHeight, rQuery, lrHeight,
                                       target + ulWidth, rTarget, lrWidth,
                                       equalityDefinition, alphabetLength, rightScore,
                                       &lrAlignment, &lrAlignmentLength);
    if (ulStatusCode == EDLIB_STATUS_ERROR || lrStatusCode == EDLIB_STATUS_ERROR) {
        if (ulAlignment) free(ulAlignment);
        if (lrAlignment) free(lrAlignment);
        return EDLIB_STATUS_ERROR;
    }

    // Build alignment by concatenating upper left alignment with lower right alignment.
    *alignmentLength = ulAlignmentLength + lrAlignmentLength;
    *alignment = static_cast<unsigned char*>(malloc((*alignmentLength) * sizeof(unsigned char)));
    memcpy(*alignment, ulAlignment, ulAlignmentLength);
    memcpy(*alignment + ulAlignmentLength, lrAlignment, lrAlignmentLength);

    free(ulAlignment);
    free(lrAlignment);
    return EDLIB_STATUS_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x1e0, %rsp            # imm = 0x1E0
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x20(%rbp)
movq %rsi, -0x28(%rbp)
movl %edx, -0x2c(%rbp)
movq %rcx, -0x38(%rbp)
movq %r8, -0x40(%rbp)
movl %r9d, -0x44(%rbp)
movl -0x2c(%rbp), %edi
movl $0x40, %esi
callq 0x655f0
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
shll $0x6, %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl 0x18(%rbp), %edi
movq -0x20(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq 0x10(%rbp), %rcx
callq 0x65630
movq %rax, -0x58(%rbp)
movl 0x18(%rbp), %edi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq 0x10(%rbp), %rcx
callq 0x65630
movq %rax, -0x60(%rbp)
movl -0x44(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x6c(%rbp)
movl -0x44(%rbp), %eax
subl -0x6c(%rbp), %eax
movl %eax, -0x70(%rbp)
movq $0x0, -0x78(%rbp)
movq -0x58(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x38(%rbp), %r8
movl -0x44(%rbp), %r9d
movl 0x20(%rbp), %r14d
movl -0x6c(%rbp), %eax
subl $0x1, %eax
leaq -0x64(%rbp), %rbx
leaq -0x68(%rbp), %r11
xorl %r10d, %r10d
leaq -0x78(%rbp), %r10
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl %eax, 0x28(%rsp)
callq 0x66170
movl %eax, -0x7c(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x60(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl -0x48(%rbp), %edx
movl -0x2c(%rbp), %ecx
movq -0x40(%rbp), %r8
movl -0x44(%rbp), %r9d
movl 0x20(%rbp), %r14d
movl -0x70(%rbp), %eax
subl $0x1, %eax
leaq -0x64(%rbp), %rbx
leaq -0x68(%rbp), %r11
xorl %r10d, %r10d
leaq -0x88(%rbp), %r10
movl %r14d, (%rsp)
movq %rbx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movq %r10, 0x20(%rsp)
movl %eax, 0x28(%rsp)
callq 0x66170
movl %eax, -0x8c(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x188(%rbp)
cmpq $0x0, %rax
je 0x68308
movq -0x188(%rbp), %rdi
callq 0x8710
movq -0x60(%rbp), %rax
movq %rax, -0x190(%rbp)
cmpq $0x0, %rax
je 0x68325
movq -0x190(%rbp), %rdi
callq 0x8710
cmpl $0x1, -0x7c(%rbp)
je 0x68338
cmpl $0x1, -0x8c(%rbp)
jne 0x683b8
cmpq $0x0, -0x78(%rbp)
je 0x6836f
movq -0x78(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, %rax
je 0x6836d
movq -0x198(%rbp), %rdi
callq 0x68e60
movq -0x198(%rbp), %rdi
movl $0x28, %esi
callq 0x8560
jmp 0x6836f
cmpq $0x0, -0x88(%rbp)
je 0x683ac
movq -0x88(%rbp), %rax
movq %rax, -0x1a0(%rbp)
cmpq $0x0, %rax
je 0x683aa
movq -0x1a0(%rbp), %rdi
callq 0x68e60
movq -0x1a0(%rbp), %rdi
movl $0x28, %esi
callq 0x8560
jmp 0x683ac
movl $0x1, -0x14(%rbp)
jmp 0x68b72
movq -0x78(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0x90(%rbp)
movq -0x78(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
movl -0x94(%rbp), %eax
subl -0x90(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
movl %eax, -0x98(%rbp)
movslq -0x98(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, -0xa0(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
cmpl -0x94(%rbp), %eax
jg 0x68502
movq -0x78(%rbp), %rax
movq (%rax), %rax
movslq -0xa4(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xa4(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x78(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xa4(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq -0xc0(%rbp), %rdi
callq 0x6a160
movq -0xc0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xa0(%rbp), %rdi
movl -0xa4(%rbp), %eax
subl -0x90(%rbp), %eax
shll $0x6, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
leaq -0xd8(%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 0x68b90
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x6842b
movl -0x90(%rbp), %eax
shll $0x6, %eax
movl %eax, -0xdc(%rbp)
movl -0x94(%rbp), %eax
movl -0x48(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x68532
movl -0x4c(%rbp), %ecx
movl -0x98(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x98(%rbp)
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %eax
movl %eax, -0xe0(%rbp)
movq -0x88(%rbp), %rax
movq 0x20(%rax), %rax
movl (%rax), %eax
movl %eax, -0xe4(%rbp)
movl -0xe4(%rbp), %eax
subl -0xe0(%rbp), %eax
addl $0x1, %eax
shll $0x6, %eax
movl %eax, -0xe8(%rbp)
movslq -0xe8(%rbp), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x8040
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xf8(%rbp)
movl -0xe0(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0xfc(%rbp), %eax
cmpl -0xe4(%rbp), %eax
jg 0x68699
movq -0x88(%rbp), %rax
movq (%rax), %rax
movslq -0xfc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xfc(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xfc(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
leaq -0x118(%rbp), %rdi
callq 0x6a160
movq -0x118(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0xf0(%rbp), %rdi
movl -0xe4(%rbp), %eax
subl -0xfc(%rbp), %eax
shll $0x6, %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
leaq -0x130(%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 0x68c30
movl -0xfc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xfc(%rbp)
jmp 0x685b9
movl -0x2c(%rbp), %eax
movl -0xe4(%rbp), %ecx
addl $0x1, %ecx
shll $0x6, %ecx
subl %ecx, %eax
movl %eax, -0x134(%rbp)
cmpl $0x0, -0x134(%rbp)
jge 0x686f4
movl -0x4c(%rbp), %ecx
movq -0xf0(%rbp), %rax
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
movl -0x4c(%rbp), %eax
addl -0x134(%rbp), %eax
movl %eax, -0x134(%rbp)
movl -0x4c(%rbp), %ecx
movl -0xe8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xe8(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x1a8(%rbp)
cmpq $0x0, %rax
je 0x68722
movq -0x1a8(%rbp), %rdi
callq 0x68e60
movq -0x1a8(%rbp), %rdi
movl $0x28, %esi
callq 0x8560
movq -0x88(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, %rax
je 0x68753
movq -0x1b0(%rbp), %rdi
callq 0x68e60
movq -0x1b0(%rbp), %rdi
movl $0x28, %esi
callq 0x8560
movl -0xdc(%rbp), %edi
movl -0x134(%rbp), %esi
subl $0x1, %esi
callq 0x677d0
movl %eax, -0x138(%rbp)
movl -0xdc(%rbp), %edi
addl -0x98(%rbp), %edi
subl $0x1, %edi
movl -0x134(%rbp), %esi
addl -0xe8(%rbp), %esi
subl $0x2, %esi
callq 0x67490
movl %eax, -0x13c(%rbp)
movl $0xffffffff, -0x140(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x144(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x148(%rbp) # imm = 0xFFFFFFFF
movb $0x0, -0x149(%rbp)
movl -0x138(%rbp), %eax
movl %eax, -0x150(%rbp)
movl -0x150(%rbp), %eax
cmpl -0x13c(%rbp), %eax
jg 0x68852
movq -0xa0(%rbp), %rax
movl -0x150(%rbp), %ecx
subl -0xdc(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x140(%rbp)
movq -0xf0(%rbp), %rax
movl -0x150(%rbp), %ecx
addl $0x1, %ecx
subl -0x134(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x144(%rbp)
movl -0x140(%rbp), %eax
addl -0x144(%rbp), %eax
cmpl 0x20(%rbp), %eax
jne 0x6883c
movl -0x150(%rbp), %eax
movl %eax, -0x148(%rbp)
movb $0x1, -0x149(%rbp)
jmp 0x68852
jmp 0x6883e
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x687c7
testb $0x1, -0x149(%rbp)
jne 0x688a9
cmpl $0x0, -0xdc(%rbp)
jne 0x688a9
cmpl $0x0, -0x134(%rbp)
jne 0x688a9
movl -0x6c(%rbp), %eax
movl %eax, -0x140(%rbp)
movq -0xf0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x144(%rbp)
movl -0x140(%rbp), %eax
addl -0x144(%rbp), %eax
cmpl 0x20(%rbp), %eax
jne 0x688a7
movl $0xffffffff, -0x148(%rbp) # imm = 0xFFFFFFFF
movb $0x1, -0x149(%rbp)
jmp 0x688a9
testb $0x1, -0x149(%rbp)
jne 0x6891f
movl -0xdc(%rbp), %eax
addl -0x98(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x6891f
movl -0x134(%rbp), %eax
addl -0xe8(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x6891f
movq -0xa0(%rbp), %rax
movl -0x98(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x140(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x144(%rbp)
movl -0x140(%rbp), %eax
addl -0x144(%rbp), %eax
cmpl 0x20(%rbp), %eax
jne 0x6891d
movl -0x2c(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x148(%rbp)
movb $0x1, -0x149(%rbp)
jmp 0x6891f
movq -0xa0(%rbp), %rax
movq %rax, -0x1b8(%rbp)
cmpq $0x0, %rax
je 0x6893f
movq -0x1b8(%rbp), %rdi
callq 0x8710
movq -0xf8(%rbp), %rax
movq %rax, -0x1c0(%rbp)
cmpq $0x0, %rax
je 0x6895f
movq -0x1c0(%rbp), %rdi
callq 0x8710
movb -0x149(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x6897b
movl $0x1, -0x14(%rbp)
jmp 0x68b72
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x154(%rbp)
movl -0x2c(%rbp), %eax
subl -0x154(%rbp), %eax
movl %eax, -0x158(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, -0x15c(%rbp)
movl -0x70(%rbp), %eax
movl %eax, -0x160(%rbp)
movq $0x0, -0x168(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
movslq -0x158(%rbp), %rax
addq %rax, %rsi
movl -0x154(%rbp), %edx
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
movslq -0x160(%rbp), %rax
addq %rax, %r8
movl -0x15c(%rbp), %r9d
movq 0x10(%rbp), %r14
movl 0x18(%rbp), %ebx
movl -0x140(%rbp), %r11d
leaq -0x168(%rbp), %r10
leaq -0x16c(%rbp), %rax
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x66f00
movl %eax, -0x170(%rbp)
movq $0x0, -0x178(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x154(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movl -0x158(%rbp), %edx
movq -0x38(%rbp), %rcx
movslq -0x15c(%rbp), %rax
addq %rax, %rcx
movq -0x40(%rbp), %r8
movl -0x160(%rbp), %r9d
movq 0x10(%rbp), %r14
movl 0x18(%rbp), %ebx
movl -0x144(%rbp), %r11d
leaq -0x178(%rbp), %r10
leaq -0x17c(%rbp), %rax
movq %r14, (%rsp)
movl %ebx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
callq 0x66f00
movl %eax, -0x180(%rbp)
cmpl $0x1, -0x170(%rbp)
je 0x68ab1
cmpl $0x1, -0x180(%rbp)
jne 0x68ae9
cmpq $0x0, -0x168(%rbp)
je 0x68ac7
movq -0x168(%rbp), %rdi
callq 0x86a0
cmpq $0x0, -0x178(%rbp)
je 0x68add
movq -0x178(%rbp), %rdi
callq 0x86a0
movl $0x1, -0x14(%rbp)
jmp 0x68b72
movl -0x16c(%rbp), %ecx
addl -0x17c(%rbp), %ecx
movq 0x30(%rbp), %rax
movl %ecx, (%rax)
movq 0x30(%rbp), %rax
movslq (%rax), %rdi
shlq $0x0, %rdi
callq 0x8770
movq %rax, %rcx
movq 0x28(%rbp), %rax
movq %rcx, (%rax)
movq 0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x168(%rbp), %rsi
movslq -0x16c(%rbp), %rdx
callq 0x8480
movq 0x28(%rbp), %rax
movq (%rax), %rdi
movslq -0x16c(%rbp), %rax
addq %rax, %rdi
movq -0x178(%rbp), %rsi
movslq -0x17c(%rbp), %rdx
callq 0x8480
movq -0x168(%rbp), %rdi
callq 0x86a0
movq -0x178(%rbp), %rdi
callq 0x86a0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)