// File: /workspace/github_c_makefile_star2_O1/debbiemarkslab[P]plmc/src/plm.c
// Function: MSARead
alignment_t *MSARead(char *alignFile, options_t *options) {
    /* Read FASTA-formatted alignment */
    FILE *fpAli = NULL;
    if (alignFile != NULL) {
        fpAli = fopen(alignFile, "r");
    } else {
        fprintf(stderr, "Must specify alignment file: -a ALIGN_FILE\n");
        exit(1);
    }
    if (fpAli == NULL) {
        fprintf(stderr, "Error opening alignment file\n");
        exit(1);
    }

    /* Allocate alignment */
    alignment_t *ali = (alignment_t *) malloc(sizeof(alignment_t));
    ali->nSeqs = ali->nSites = ali->nCodes = 0;
    ali->alphabet = options->alphabet;
    ali->names = NULL;
    ali->sequences = NULL;
    ali->target = -1;
    ali->offsets = NULL;
    ali->nEff = 0;
    ali->weights = ali->fi = ali->fij = NULL;
    ali->nParams = 0;

    /* Verify alignment dimensions and structure (first pass through file) */
    char name[BUFFER_SIZE];
    char seq[BUFFER_SIZE];
    /* Read first line as name */
    fgetstr(name, fpAli);
    if (*name == '>') {
        MSAReadSeq(seq, fpAli);
    } else {
        fprintf(stderr, "Error reading alignment:"
                        " First line should start with >\n");
        exit(1);
    }
    ali->nCodes = strlen(ali->alphabet);
    ali->nSites = strlen(seq);
    ali->nSeqs = 1;
    while (!feof(fpAli)) {
        char c = fgetc(fpAli);
        if (c == '>') {
            /* Read name and sequence pair */
            fgetstr(name, fpAli);
            MSAReadSeq(seq, fpAli);
        } else {
            fprintf(stderr, "Error reading alignment:"
                            " sequence records should start with >\n");
            exit(1);
        }

        /* Validate sequence length */
        if (strlen(seq) != ali->nSites) {
            fprintf(stderr,
                "Incompatible sequence length (%lu should be %d) for %s:\n%s\n",
                strlen(seq), ali->nSites, name, seq);
            exit(1);
        }
        ali->nSeqs++;
    }

    /* Encode full alignment block (second pass through file) */
    ali->sequences = (letter_t *)
        malloc(ali->nSites * ali->nSeqs * sizeof(letter_t));
    ali->names = (char **) malloc(ali->nSeqs * sizeof(char *));
    for (int s = 0; s < ali->nSeqs; s++)
        for (int i = 0; i < ali->nSites; i++) seq(s, i) = 0;
    for (int s = 0; s < ali->nSeqs; s++) ali->names[s] = NULL;
    rewind(fpAli);
    for (int s = 0; s < ali->nSeqs; s++) {
        /* >Name */
        getc(fpAli);
        fgetstr(name, fpAli);
        ali->names[s] = (char *) malloc((strlen(name) + 1) * sizeof(char));
        strcpy(ali->names[s], name);

        /* Sequence */
        MSAReadSeq(seq, fpAli);
        for (int i = 0; i < ali->nSites; i++)
            seq(s, i) = MSAReadCode(seq[i], ali->alphabet, ali->nCodes);
    }

    /* --------------------------------_DEBUG_--------------------------------*/
    /* Alignment to stderr */
    // for (int s = 0; s < 10; s++) {
    // for (int s = 0; s < ali->nSeqs; s++) {
    //     for (int i = 0; i < ali->nSites; i++)
    //         if (seq(s, i) >= 0 && seq(s, i) < ali->nCodes) {
    //             fprintf(stderr, "%c", ali->alphabet[seq(s, i)]);
    //         } else if (seq(s, i) >= -ali->nCodes && seq(s, i) < 0) {
    //             fprintf(stderr, "%c",
    //                 tolower(ali->alphabet[seq(s, i) + ali->nCodes]));
    //         } else {
    //             fprintf(stderr, "*%d*", seq(s, i));
    //         }
    //     fprintf(stderr, "\n");
    // }
    // exit(0);
    /* --------------------------------^DEBUG^--------------------------------*/

    /* Focus mode: If a focus sequence (target) is provided, locate it */
    if (options->target != NULL) {
        for (int s = 0; s < ali->nSeqs; s++)
            if (strncmp(options->target, ali->names[s],
                strlen(options->target)) == 0) {
                if (ali->target >= 0) {
                    fprintf(stderr,
                        "Multiple sequences start with %s, picking sequence %d\n",
                        options->target, s + 1);
                } else {
                    ali->target = s;
                }
            }
        if (ali->target >= 0) {
            fprintf(stderr, "Found focus %s as sequence %d\n", options->target,
                ali->target + 1);
        } else {
            fprintf(stderr,
                "Could not find %s, proceeding without focus sequence\n",
                options->target);
        }
    }

    /* Always discard any sequences (rows) with out-of-alphabet characters */
    int* seqValid = (int *) malloc(ali->nSeqs * sizeof(int));
    for (int s = 0; s < ali->nSeqs; s++) seqValid[s] = 0;
    for (int s = 0; s < ali->nSeqs; s++)
        for (int i = 0; i < ali->nSites; i++)
            if ((seq(s, i) >= -ali->nCodes) && (seq(s, i) < ali->nCodes))
                seqValid[s]++;
    int nValidSeqs = 0;
    for (int s = 0; s < ali->nSeqs; s++)
        if (seqValid[s] == ali->nSites) nValidSeqs++;
    fprintf(stderr, "%d valid sequences out of %d \n", nValidSeqs, ali->nSeqs);
    
    /* Record indices of skipped sequences */
    ali->nSkippedSeqs = ali->nSeqs - nValidSeqs;
    ali->skippedSeqs = (int *) malloc(ali->nSkippedSeqs * sizeof(int));
    for (int s = 0, skipIndex = 0; s < ali->nSeqs; s++)
        if (seqValid[s] != ali->nSites) ali->skippedSeqs[skipIndex++] = s;

    /* Focus mode: select only focus columns (criteria below) */
    int nValidSites = ali->nSites;
    int* siteValid = (int *) malloc(ali->nSites * sizeof(int));
    for (int i = 0; i < ali->nSites; i++) siteValid[i] = 1;
    if (ali->target >= 0) {
        for (int i = 0; i < ali->nSites; i++) {
            /* For proteins, remove lower case and gap columns */
            if ((ali->alphabet == codesAA) 
                && (seq(ali->target, i) < 0))
                siteValid[i] = 0;
            /* Discard gaps */
            if ((ali->alphabet == codesAA)
                || (options->estimatorMAP == INFER_MAP_PLM_GAPREDUCE))
                if (seq(ali->target, i) == 0) siteValid[i] = 0;
        }
        nValidSites = 0;
        for (int i = 0; i < ali->nSites; i++)
            if (siteValid[i] == 1) nValidSites++;
        fprintf(stderr,
            "%d sites out of %d\n", nValidSites, ali->nSites);
    } else {
        fprintf(stderr,
            "%d sites\n", ali->nSites);
    }

    /* Focus mode: parse region (NAME/START_IX-END_IX) and map offsets */
    int leftOffset = 0;
    if (ali->target >= 0) {
        char *focusName = ali->names[ali->target];
        /* Name should be immediately followed by '/' */
        if (strlen(focusName) > strlen(options->target) + 1
            && focusName[strlen(options->target)] == '/') {
            /* Attempt to read integer region start */
            int regLeft = strlen(options->target) + 1;
            int ix = 0;
            if (isdigit(focusName[regLeft])) {
                while (regLeft + ix < strlen(focusName)
                       && isdigit(focusName[regLeft + ix + 1])) ix++;
                int tens = 1;
                leftOffset = -1;
                for (int i = ix; i >= 0; i--) {
                    leftOffset += tens * (focusName[regLeft + i] - '0');
                    tens *= 10;
                }
                fprintf(stderr, "Region starts at %d\n", leftOffset + 1);
            } else {
                fprintf(stderr, "Error parsing region, assuming start at 1");
            }
        }

        /* Map the offsets */
        ali->offsets = (int *) malloc(nValidSites * sizeof(int));
        for (int i = 0; i < nValidSites; i++) ali->offsets[i] = i + 1;
        int ix = 0;
        for (int i = 0; i < ali->nSites; i++)
            if (siteValid[i] == 1) {
                ali->offsets[ix] = i + 1 + leftOffset;
                ix++;
            }

        /* Reposition the target for reduced alignment */
        int targetShift = -1;
        for (int i = 0; i <= ali->target; i++)
            if (seqValid[i] == ali->nSites) targetShift++;
        ali->target = targetShift;
    }

    /* Copy only selected rows and columns */
    if (nValidSeqs < ali->nSeqs || nValidSites < ali->nSites) {
        letter_t *seqsReduced = (letter_t *)
            malloc(nValidSites * nValidSeqs * sizeof(letter_t));
        for (int i = 0; i < nValidSites * nValidSeqs; i++) seqsReduced[i] = 0;
        int sx = 0;
        for (int s = 0; s < ali->nSeqs; s++)
            if (seqValid[s] == ali->nSites) {
                int ix = 0;
                for (int i = 0; i < ali->nSites; i++) {
                    if (siteValid[i] == 1) {
                        seqsReduced[ix + sx * nValidSites] = seq(s, i);
                        ix++;
                    }
                }
                sx++;
            }

        /* Reallocate alignment with reduced dimensions */
        free(ali->sequences);
        ali->nSeqs = nValidSeqs;
        ali->nSites = nValidSites;
        ali->sequences = (letter_t *)
            malloc(nValidSites * nValidSeqs * sizeof(letter_t));
        for (int i = 0; i < nValidSites * nValidSeqs; i++)
            ali->sequences[i] = 0;
        for (int s = 0; s < nValidSeqs; s++)
            for (int i = 0; i < nValidSites; i++)
                seq(s, i) = seqsReduced[i + s * nValidSites];
        free(seqsReduced);
    }

    /* Shift any lowercase codes back to uppercase */
    for (int s = 0; s < ali->nSeqs; s++)
        for (int i = 0; i < ali->nSites; i++)
            if (seq(s, i) < 0) seq(s, i) += ali->nCodes;

    /* Intialize weights to 1.0 */
    ali->weights = (numeric_t *) malloc(ali->nSeqs * sizeof(numeric_t));
    for (int s = 0; s < ali->nSeqs; s++) ali->weights[s] = 1.0;
    ali->nEff = (numeric_t) ali->nSeqs;

    /* --------------------------------_DEBUG_--------------------------------*/
    /* Display offset map */
    // for (int i = 0; i < ali->nSites; i++) {
    //     fprintf(stderr, "%d : %d : %c\n", i + 1, ali->offsets[i],
    //             ali->alphabet[seq(ali->target, i)]);
    // }
    // exit(0);
    /* Display target */
    // for (int i = 0; i < ali->nSites; i++) {
    //     fprintf(stderr, "%c", ali->alphabet[seq(ali->target, i)]);
    // }
    // fprintf(stderr, "\n");
    // exit(0);
    /* --------------------------------^DEBUG^--------------------------------*/

    /* --------------------------------_DEBUG_--------------------------------*/
    // for (int s = 0; s < ali->nSeqs; s++) {
    //     fprintf(stderr, ">%s\n", ali->names[s]);
    //     for (int i = 0; i < ali->nSites; i++)
    //         fprintf(stderr, "%c", ali->alphabet[seq(s, i)]);
    //     fprintf(stderr, "\n");
    // }
    /* --------------------------------^DEBUG^--------------------------------*/
    return ali;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x14068, %rsp          # imm = 0x14068
movq %rsi, 0x8(%rsp)
testq %rdi, %rdi
je 0x63df
leaq 0x9ae2(%rip), %rsi      # 0xf2a7
callq 0x11c0
testq %rax, %rax
je 0x63e4
movq %rax, %r15
movl $0x88, %edi
callq 0x11a0
movq %rax, %rbx
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x18(%rbx)
movl $0xffffffff, 0x38(%rbx) # imm = 0xFFFFFFFF
movdqu %xmm0, 0x5c(%rbx)
movdqu %xmm0, 0x50(%rbx)
movdqu %xmm0, 0x40(%rbx)
leaq 0xa060(%rsp), %r14
movq %r14, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r15, %rdx
callq 0x1150
testq %rax, %rax
je 0x5883
leaq 0xa060(%rsp), %r13
movq %r13, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x5857
movb $0x0, (%rax)
movq %r13, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r13)
jne 0x5883
addq %r13, %rax
decq %rax
movb $0x0, (%rax)
movq %r13, %rdi
callq 0x10c0
addq %r13, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x586d
cmpb $0x3e, 0xa060(%rsp)
jne 0x63e9
leaq 0x60(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x79e5
movq 0x10(%rbx), %rdi
callq 0x10c0
movq %rax, 0x58(%rsp)
movl %eax, 0x8(%rbx)
movq %r12, %rdi
callq 0x10c0
movl %eax, 0x4(%rbx)
movq %r15, %rdi
callq 0x1180
movl $0x1, %ebp
testl %eax, %eax
jne 0x596f
leaq 0x60(%rsp), %r13
movq %r15, %rdi
callq 0x1120
cmpb $0x3e, %al
jne 0x63d5
movq %r14, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r15, %rdx
callq 0x1150
testq %rax, %rax
je 0x593d
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x5911
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r14)
jne 0x593d
addq %r14, %rax
decq %rax
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x5927
movq %r13, %rdi
movq %r15, %rsi
callq 0x79e5
movq %r13, %rdi
callq 0x10c0
movslq 0x4(%rbx), %rcx
cmpq %rcx, %rax
jne 0x63a1
incl %ebp
movq %r15, %rdi
callq 0x1180
testl %eax, %eax
je 0x58d7
movl %ebp, (%rbx)
movslq 0x4(%rbx), %rdi
movslq %ebp, %r12
imulq %r12, %rdi
shlq $0x2, %rdi
callq 0x11a0
movq %rax, 0x38(%rsp)
movq %rax, 0x20(%rbx)
shlq $0x3, %r12
movq %r12, %rdi
callq 0x11a0
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbx)
movq %rbx, 0x20(%rsp)
movslq (%rbx), %r13
testq %r13, %r13
jle 0x59e7
movq 0x20(%rsp), %rax
movl 0x4(%rax), %r14d
movq %r14, %rbp
shlq $0x2, %rbp
xorl %ebx, %ebx
movq %r13, %r12
testl %r14d, %r14d
jle 0x59df
movl %ebx, %eax
movq 0x38(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x1110
addl %r14d, %ebx
decq %r12
jne 0x59c5
testl %r13d, %r13d
movq 0x20(%rsp), %rbx
jle 0x5a06
leaq 0x18(%rbx), %rax
movq (%rax), %rdi
shlq $0x3, %r13
xorl %esi, %esi
movq %r13, %rdx
callq 0x1110
movq %r15, %rdi
callq 0x10e0
movslq (%rbx), %rcx
movq %rcx, 0x28(%rsp)
testq %rcx, %rcx
jle 0x5b31
movq $0x0, 0x10(%rsp)
xorl %r12d, %r12d
movq %r15, 0x30(%rsp)
movq %r15, %rdi
callq 0x1220
leaq 0xa060(%rsp), %r14
movq %r14, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r15, %rdx
callq 0x1150
testq %rax, %rax
je 0x5a96
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x5a6a
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r14)
jne 0x5a96
addq %r14, %rax
decq %rax
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x5a80
movq %r14, %rdi
callq 0x10c0
leaq 0x1(%rax), %rdi
callq 0x11a0
movq 0x18(%rbx), %rcx
movq %r12, 0x40(%rsp)
movq %rax, (%rcx,%r12,8)
movq %rax, %rdi
movq %r14, %rsi
callq 0x1070
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x79e5
movq %rbx, %r15
movslq 0x4(%rbx), %rbx
testq %rbx, %rbx
jle 0x5b10
movq 0x10(%r15), %rbp
movl 0x8(%r15), %r12d
movq 0x10(%rsp), %r13
imulq %rbx, %r13
xorl %r14d, %r14d
movsbl 0x60(%rsp,%r14), %edi
movq %rbp, %rsi
movl %r12d, %edx
callq 0x7abc
movq 0x20(%r15), %rcx
addq %r13, %rcx
movl %eax, (%rcx,%r14,4)
incq %r14
cmpq %r14, %rbx
jne 0x5aec
movq 0x40(%rsp), %r12
incq %r12
addq $0x4, 0x10(%rsp)
cmpq 0x28(%rsp), %r12
movq %r15, %rbx
movq 0x30(%rsp), %r15
jne 0x5a30
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
je 0x5be6
cmpl $0x0, 0x28(%rsp)
jle 0x5bad
movq 0xc4aa(%rip), %r13      # 0x11ff8
leaq 0x87e3(%rip), %r14      # 0xe338
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
movq (%rax), %r15
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %r12
movq %r15, %rdi
callq 0x10c0
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x1060
testl %eax, %eax
jne 0x5b8b
cmpl $0x0, 0x38(%rbx)
jns 0x5b97
movl %ebp, 0x38(%rbx)
incq %rbp
cmpq %rbp, 0x28(%rsp)
jne 0x5b57
jmp 0x5bad
movq (%r13), %rdi
leal 0x1(%rbp), %ecx
movq %r14, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x1170
jmp 0x5b8b
movl 0x38(%rbx), %ecx
movq 0xc441(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
movq 0x8(%rsp), %rax
movq (%rax), %rdx
testl %ecx, %ecx
js 0x5bd8
incl %ecx
leaq 0x87a0(%rip), %rsi      # 0xe36f
xorl %eax, %eax
callq 0x1170
jmp 0x5be6
leaq 0x87af(%rip), %rsi      # 0xe38e
xorl %eax, %eax
callq 0x1170
movslq (%rbx), %r14
leaq (,%r14,4), %r15
movq %r15, %rdi
callq 0x11a0
movq %rax, %r13
testq %r14, %r14
jle 0x5c0e
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x1110
testl %r14d, %r14d
jle 0x5c72
movq 0x20(%rsp), %rax
movl 0x4(%rax), %eax
leaq (,%rax,4), %rcx
xorl %edx, %edx
xorl %esi, %esi
testl %eax, %eax
jle 0x5c67
movq 0x20(%rsp), %r9
movl 0x8(%r9), %edi
movl %edi, %r8d
negl %r8d
movq 0x20(%r9), %r9
addq %rdx, %r9
xorl %r10d, %r10d
movl (%r9,%r10,4), %r11d
cmpl %r8d, %r11d
setl %bl
cmpl %edi, %r11d
setge %r11b
orb %bl, %r11b
jne 0x5c5f
incl (%r13,%rsi,4)
incq %r10
cmpq %r10, %rax
jne 0x5c44
incq %rsi
addq %rcx, %rdx
cmpq %r14, %rsi
jne 0x5c27
xorl %ebp, %ebp
testl %r14d, %r14d
movq 0x20(%rsp), %rbx
jle 0x5c99
movl 0x4(%rbx), %eax
xorl %ecx, %ecx
xorl %ebp, %ebp
xorl %edx, %edx
cmpl %eax, (%r13,%rcx,4)
sete %dl
addl %edx, %ebp
incq %rcx
cmpq %rcx, %r14
jne 0x5c85
movq 0xc358(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x871a(%rip), %rsi      # 0xe3c4
xorl %r15d, %r15d
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x1170
movslq (%rbx), %rdi
movslq %ebp, %rax
subq %rax, %rdi
movl %edi, 0x28(%rbx)
shlq $0x2, %rdi
callq 0x11a0
movq %rax, 0x30(%rbx)
movslq (%rbx), %rdi
testq %rdi, %rdi
jle 0x5cf7
movl 0x4(%rbx), %ecx
xorl %edx, %edx
cmpl %ecx, (%r13,%rdx,4)
je 0x5cef
movslq %r15d, %rsi
incl %r15d
movl %edx, (%rax,%rsi,4)
incq %rdx
cmpq %rdx, %rdi
jne 0x5cdf
movq %rdi, 0x28(%rsp)
movslq 0x4(%rbx), %r14
leaq (,%r14,4), %rdi
movq %rdi, 0x40(%rsp)
callq 0x11a0
movq %r14, %rsi
movq %rax, %r15
movl %esi, %r12d
testq %r14, %r14
jle 0x5df2
leal 0x3(%r12), %eax
leaq -0x1(%r12), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %eax
shlq $0x4, %rax
pmovsxbq 0x8498(%rip), %xmm1     # 0xe1e0
pmovsxbq 0x8491(%rip), %xmm2     # 0xe1e2
xorl %ecx, %ecx
movdqa 0x8355(%rip), %xmm3     # 0xe0b0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
pmovsxbq 0x8478(%rip), %xmm5     # 0xe1e4
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
pcmpgtq %xmm0, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0x5d8c
movl $0x1, (%r15,%rcx)
pxor %xmm4, %xmm6
pextrb $0x8, %xmm6, %edx
testb $0x1, %dl
je 0x5da4
movl $0x1, 0x4(%r15,%rcx)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
pcmpgtq %xmm0, %xmm6
pxor %xmm4, %xmm6
pextrb $0x0, %xmm6, %edx
testb $0x1, %dl
je 0x5dc9
movl $0x1, 0x8(%r15,%rcx)
pextrb $0x8, %xmm6, %edx
testb $0x1, %dl
je 0x5ddd
movl $0x1, 0xc(%r15,%rcx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x5d6c
movl 0x38(%rbx), %edx
testl %edx, %edx
movq %rsi, 0x10(%rsp)
movq %rdx, 0x30(%rsp)
js 0x5eac
testl %esi, %esi
jle 0x5e61
movq 0x10(%rbx), %rax
movq 0xc33a(%rip), %rcx      # 0x12150
imull 0x10(%rsp), %edx
xorl %esi, %esi
cmpq %rcx, %rax
jne 0x5e39
movq 0x20(%rbx), %rdi
cmpl $0x0, (%rdi,%rdx,4)
jns 0x5e34
movl $0x0, (%r15,%rsi,4)
cmpq %rcx, %rax
je 0x5e44
movq 0x8(%rsp), %rdi
cmpl $0x1, 0x18(%rdi)
jne 0x5e56
movq 0x20(%rbx), %rdi
cmpl $0x0, (%rdi,%rdx,4)
jne 0x5e56
movl $0x0, (%r15,%rsi,4)
incq %rsi
incq %rdx
cmpq %rsi, %r12
jne 0x5e1d
xorl %r14d, %r14d
cmpl $0x0, 0x10(%rsp)
jle 0x5e85
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpl $0x1, (%r15,%rax,4)
sete %cl
addl %ecx, %r14d
incq %rax
cmpq %rax, %r12
jne 0x5e70
movq 0xc16c(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x854d(%rip), %rsi      # 0xe3e3
movl %r14d, %edx
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x1170
movq 0x10(%rsp), %rsi
jmp 0x5ed1
movq 0xc145(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
leaq 0x853a(%rip), %rsi      # 0xe3f7
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x1170
movq 0x10(%rsp), %rsi
movl %esi, %r14d
movq 0x30(%rsp), %rcx
testl %ecx, %ecx
movq 0x28(%rsp), %r8
js 0x608b
addq $0x40, %rbx
movq 0x18(%rsp), %rax
movq (%rax,%rcx,8), %rdi
movq %rdi, 0x48(%rsp)
callq 0x10c0
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
callq 0x10c0
leaq 0x1(%rax), %rcx
cmpq %rcx, 0x18(%rsp)
movq %rbx, 0x50(%rsp)
jbe 0x5f2b
movq 0x48(%rsp), %rdx
cmpb $0x2f, (%rdx,%rax)
je 0x62dd
movl $0x1, 0x8(%rsp)
movslq %r14d, %rbx
leaq (,%rbx,4), %rdi
callq 0x11a0
movq 0x50(%rsp), %rcx
movq %rax, (%rcx)
testl %ebx, %ebx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
jle 0x6037
movl %r14d, %edx
leal 0x3(%r14), %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %ecx
shlq $0x4, %rcx
pmovsxbq 0x825f(%rip), %xmm1     # 0xe1e0
pmovsxbq 0x8258(%rip), %xmm2     # 0xe1e2
xorl %edx, %edx
movdqa 0x811c(%rip), %xmm3     # 0xe0b0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
pmovsxbq 0x823f(%rip), %xmm5     # 0xe1e4
movdqa %xmm2, %xmm7
pxor %xmm3, %xmm7
pcmpgtq %xmm0, %xmm7
movdqa %xmm2, %xmm6
psubq %xmm4, %xmm6
movd %xmm7, %esi
notl %esi
testb $0x1, %sil
je 0x5fcb
movd %xmm6, (%rax,%rdx)
pxor %xmm4, %xmm7
pextrb $0x8, %xmm7, %esi
testb $0x1, %sil
je 0x5fe3
pextrd $0x2, %xmm6, 0x4(%rax,%rdx)
movdqa %xmm1, %xmm6
psubq %xmm4, %xmm6
movdqa %xmm1, %xmm7
pxor %xmm3, %xmm7
pcmpgtq %xmm0, %xmm7
pxor %xmm4, %xmm7
pextrb $0x0, %xmm7, %esi
testb $0x1, %sil
je 0x600e
movd %xmm6, 0x8(%rax,%rdx)
pextrb $0x8, %xmm7, %esi
testb $0x1, %sil
je 0x6022
pextrd $0x2, %xmm6, 0xc(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x5fa5
cmpl $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rbx
jle 0x6065
movl 0x8(%rsp), %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%r15,%rdx,4)
jne 0x605d
leal (%rcx,%rdx), %edi
movslq %esi, %rsi
movl %edi, (%rax,%rsi,4)
incl %esi
incq %rdx
cmpq %rdx, %r12
jne 0x604b
incq %r9
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
movq 0x10(%rsp), %rsi
xorl %edx, %edx
cmpl %esi, (%r13,%rcx,4)
sete %dl
addl %edx, %eax
incq %rcx
cmpq %rcx, %r9
jne 0x6074
movl %eax, 0x38(%rbx)
cmpl %r8d, %ebp
jl 0x6099
cmpl %esi, %r14d
jge 0x61cf
movl %r14d, %ebx
imull %ebp, %ebx
movslq %ebx, %rax
movq %rax, 0x18(%rsp)
leaq (,%rax,4), %rdi
movq %rdi, 0x8(%rsp)
callq 0x11a0
movl %ebx, 0x30(%rsp)
movl %ebx, %ebx
cmpl $0x0, 0x18(%rsp)
jle 0x60e2
leaq (,%rbx,4), %rdx
movq %rax, %rdi
xorl %esi, %esi
movq %rax, 0x18(%rsp)
callq 0x1110
movq 0x18(%rsp), %rax
movq %rbx, 0x18(%rsp)
movq %rax, %rbx
movq 0x28(%rsp), %r11
testl %r11d, %r11d
movq 0x10(%rsp), %rsi
jle 0x614d
xorl %eax, %eax
movq 0x38(%rsp), %rcx
xorl %edx, %edx
cmpl %esi, (%r13,%rax,4)
jne 0x6140
testl %esi, %esi
jle 0x6139
movl %edx, %esi
imull %r14d, %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x1, (%r15,%rdi,4)
jne 0x6131
movl (%rcx,%rdi,4), %r9d
leal (%r8,%rsi), %r10d
movslq %r10d, %r10
movl %r9d, (%rbx,%r10,4)
incl %r8d
incq %rdi
cmpq %rdi, %r12
jne 0x6118
incl %edx
movq 0x10(%rsp), %rsi
incq %rax
addq 0x40(%rsp), %rcx
cmpq %r11, %rax
jne 0x6102
movq 0x38(%rsp), %rdi
callq 0x1050
movq 0x20(%rsp), %r12
movl %ebp, (%r12)
movl %r14d, 0x4(%r12)
movq 0x8(%rsp), %rdi
callq 0x11a0
movq %rax, %r15
movq %rax, 0x20(%r12)
cmpl $0x0, 0x30(%rsp)
jle 0x6191
movq 0x18(%rsp), %rdx
shlq $0x2, %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x1110
testl %ebp, %ebp
movq %rbx, %r12
jle 0x61c2
movl %r14d, %r13d
shlq $0x2, %r13
movl %ebp, %ebx
xorl %ebp, %ebp
testl %r14d, %r14d
jle 0x61ba
movl %ebp, %eax
leaq (%r12,%rax,4), %rsi
leaq (%r15,%rax,4), %rdi
movq %r13, %rdx
callq 0x1190
addl %r14d, %ebp
decq %rbx
jne 0x61a3
movq %r12, %rdi
callq 0x1050
movq 0x20(%rsp), %rbx
movslq (%rbx), %r14
testq %r14, %r14
movq 0x58(%rsp), %r10
jle 0x621c
movl 0x4(%rbx), %eax
leaq (,%rax,4), %rcx
xorl %edx, %edx
xorl %esi, %esi
testl %eax, %eax
jle 0x6211
movq 0x20(%rbx), %rdi
addq %rdx, %rdi
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
testl %r9d, %r9d
jns 0x6209
addl %r10d, %r9d
movl %r9d, (%rdi,%r8,4)
incq %r8
cmpq %r8, %rax
jne 0x61f9
incq %rsi
addq %rcx, %rdx
cmpq %r14, %rsi
jne 0x61eb
leaq (,%r14,8), %rdi
callq 0x11a0
movq %rax, 0x50(%rbx)
testl %r14d, %r14d
jle 0x62bb
leal 0x1(%r14), %ecx
leaq -0x1(%r14), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %ecx
shlq $0x4, %rcx
pmovsxbq 0x7f8b(%rip), %xmm1     # 0xe1e2
xorl %edx, %edx
movdqa 0x7e4f(%rip), %xmm2     # 0xe0b0
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
pmovsxbq 0x7f6a(%rip), %xmm4     # 0xe1e6
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
pcmpgtq %xmm0, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x6299
movq %rsi, (%rax,%rdx)
pxor %xmm3, %xmm5
pextrb $0x8, %xmm5, %edi
testb $0x1, %dil
je 0x62ae
movq %rsi, 0x8(%rax,%rdx)
paddq %xmm4, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x627c
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x48(%rbx)
movq %rbx, %rax
addq $0x14068, %rsp          # imm = 0x14068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, 0x8(%rsp)
callq 0x1250
movq 0x8(%rsp), %r10
movq 0x48(%rsp), %r8
movq (%rax), %rcx
movslq %r10d, %rax
movsbq (%r8,%rax), %rax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x6315
movl $0x1, 0x8(%rsp)
callq 0x12bc
jmp 0x5f33
movslq %r10d, %rdx
xorl %eax, %eax
cmpq %rdx, 0x18(%rsp)
jbe 0x634d
movslq %r10d, %rdx
leaq (%rdx,%r8), %rsi
incq %rsi
xorl %eax, %eax
movq 0x18(%rsp), %r11
movsbq (%rsi,%rax), %rdi
testb $0x8, 0x1(%rcx,%rdi,2)
je 0x634d
leaq (%rdx,%rax), %rdi
incq %rdi
incq %rax
cmpq %rdi, %r11
ja 0x6332
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x637e
movl %eax, %eax
movslq %r10d, %rcx
addq %rcx, %r8
incq %rax
movl $0x1, %ecx
movsbl -0x1(%r8,%rax), %esi
addl $-0x30, %esi
imull %ecx, %esi
addl %esi, %edx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
decq %rax
jg 0x6366
movq 0xbc73(%rip), %rax      # 0x11ff8
movq (%rax), %rdi
incl %edx
leaq 0x8070(%rip), %rsi      # 0xe401
movl %edx, 0x8(%rsp)
xorl %eax, %eax
callq 0x1170
jmp 0x5f33
movl %ebp, (%rbx)
movq 0xbc4e(%rip), %rdx      # 0x11ff8
movq (%rdx), %rdi
leaq 0x7f48(%rip), %rsi      # 0xe2fc
leaq 0xa060(%rsp), %r8
leaq 0x60(%rsp), %r9
movq %rax, %rdx
xorl %eax, %eax
callq 0x1170
movl $0x1, %edi
callq 0x11f0
movl %ebp, %edi
movq %rbx, %rsi
callq 0x1295
callq 0x1303
callq 0x12de
callq 0x1270