// File: /workspace/github_c_makefile_star2_O3/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, 0x28(%rsp)
testq %rdi, %rdi
je 0x584f
leaq 0x9667(%rip), %rsi      # 0xe284
callq 0x11d0
testq %rax, %rax
je 0x5854
movq %rax, %rbp
movl $0x88, %edi
callq 0x11b0
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
movq 0x28(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, (%rsp)
movq %rcx, 0x10(%rax)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x18(%rax)
movl $0xffffffff, 0x38(%rax) # imm = 0xFFFFFFFF
movdqu %xmm0, 0x5c(%rax)
movdqu %xmm0, 0x50(%rax)
movq %rax, 0x10(%rsp)
movdqu %xmm0, 0x40(%rax)
leaq 0x60(%rsp), %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %rbp, %rdx
callq 0x1150
testq %rax, %rax
je 0x4cd8
leaq 0x60(%rsp), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x4cac
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r14)
jne 0x4cd8
addq %r14, %rax
decq %rax
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x4cc2
cmpb $0x3e, 0x60(%rsp)
jne 0x5859
leaq 0xa060(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0x6d42
movq (%rsp), %rdi
callq 0x10c0
movq 0x10(%rsp), %rbx
movq %rax, 0x48(%rsp)
movl %eax, 0x8(%rbx)
movq %r15, %rdi
callq 0x10c0
movl %eax, 0x4(%rbx)
movq %rax, %rbx
movq %rbp, %rdi
callq 0x1190
movl $0x1, %r13d
testl %eax, %eax
leaq 0x60(%rsp), %r14
jne 0x4dd5
movslq %ebx, %r12
leaq 0xa060(%rsp), %r15
movq %rbp, %rdi
callq 0x1120
cmpb $0x3e, %al
jne 0x5842
movq %r14, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %rbp, %rdx
callq 0x1150
testq %rax, %rax
je 0x4da6
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x4d7a
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r14)
jne 0x4da6
addq %r14, %rax
decq %rax
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x4d90
movq %r15, %rdi
movq %rbp, %rsi
callq 0x6d42
movq %r15, %rdi
callq 0x10c0
cmpq %r12, %rax
jne 0x5806
incl %r13d
movq %rbp, %rdi
callq 0x1190
testl %eax, %eax
je 0x4d40
movq %rbx, 0x30(%rsp)
movq 0x10(%rsp), %rbx
movq %rbx, %rax
addq $0x40, %rax
movq %rax, 0x50(%rsp)
movabsq $0x3fffffffc, %r12      # imm = 0x3FFFFFFFC
movl %r13d, %r15d
movl %r13d, (%rbx)
movl %r13d, %eax
imull 0x30(%rsp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x11b0
movq %rax, 0x8(%rsp)
movq %rax, 0x20(%rbx)
movslq %r13d, %rax
movq %rax, 0x58(%rsp)
leaq (,%rax,8), %rdi
callq 0x11b0
movq %r15, %rcx
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbx)
movq 0x30(%rsp), %rbx
movq %rbx, %r13
shlq $0x2, %r13
movq %r13, %rax
andq %r12, %rax
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq %r15, 0x20(%rsp)
testl %ebx, %ebx
jle 0x4e82
movq %r12, %rdi
movabsq $0x3fffffffc, %rax      # imm = 0x3FFFFFFFC
andq %rax, %rdi
addq 0x8(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x1110
movq 0x20(%rsp), %rcx
addq %r13, %r12
decq %r15
jne 0x4e58
leaq (,%rcx,8), %rdx
xorl %r13d, %r13d
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x1110
movq %rbp, %rdi
callq 0x10e0
movl %ebx, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq (,%r15,4), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rsp), %r12
movq %rbp, 0x40(%rsp)
movq %rbp, %rdi
callq 0x1230
movq %r14, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %rbp, %rdx
callq 0x1150
testq %rax, %rax
je 0x4f28
movq %r14, %rdi
movl $0xa, %esi
callq 0x10d0
testq %rax, %rax
je 0x4efc
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
cmpb $0xd, -0x1(%rax,%r14)
jne 0x4f28
addq %r14, %rax
decq %rax
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x4f12
movq %r14, %rdi
callq 0x10c0
leaq 0x1(%rax), %rdi
callq 0x11b0
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movq %rax, %rdi
movq %r14, %rsi
callq 0x1070
leaq 0xa060(%rsp), %rdi
movq %rbp, %rsi
callq 0x6d42
testl %ebx, %ebx
movq (%rsp), %r14
movq 0x48(%rsp), %rbp
jle 0x4f8a
xorl %ebx, %ebx
movsbl 0xa060(%rsp,%rbx), %edi
movq %r14, %rsi
movl %ebp, %edx
callq 0x6e19
movl %eax, (%r12,%rbx,4)
incq %rbx
cmpq %rbx, %r15
jne 0x4f6c
incq %r13
addq 0x38(%rsp), %r12
cmpq 0x20(%rsp), %r13
movq 0x30(%rsp), %rbx
movq 0x40(%rsp), %rbp
leaq 0x60(%rsp), %r14
jne 0x4eca
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x28(%rsp), %rax
cmpq $0x0, (%rax)
je 0x5069
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x28(%rsp), %rax
movq (%rax), %r12
movq 0x18(%rsp), %rax
movq (%rax,%rbp,8), %r13
movq %r12, %rdi
callq 0x10c0
movq %r12, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x1060
testl %eax, %eax
jne 0x5004
testl %r14d, %r14d
jns 0x5010
movq 0x10(%rsp), %rax
movl %ebp, 0x38(%rax)
movl %ebp, %r14d
incq %rbp
cmpq %rbp, 0x20(%rsp)
jne 0x4fc9
jmp 0x5030
movq 0xbfe1(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leal 0x1(%rbp), %ecx
leaq 0x8304(%rip), %rsi      # 0xd328
movq %r12, %rdx
xorl %eax, %eax
callq 0x1180
jmp 0x5004
movq 0xbfc1(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq 0x28(%rsp), %rax
movq (%rax), %rdx
testl %r14d, %r14d
js 0x505b
leal 0x1(%r14), %ecx
leaq 0x830d(%rip), %rsi      # 0xd35f
xorl %eax, %eax
callq 0x1180
jmp 0x5069
leaq 0x831c(%rip), %rsi      # 0xd37e
xorl %eax, %eax
callq 0x1180
movq 0x58(%rsp), %rdi
shlq $0x2, %rdi
callq 0x11b0
movq %rax, %r12
movq 0x20(%rsp), %rbp
leaq (,%rbp,4), %rdx
xorl %r13d, %r13d
movq %rax, %rdi
xorl %esi, %esi
callq 0x1110
movq %rbp, %rcx
movl %ebx, %eax
movq 0x48(%rsp), %r11
movl %r11d, %r10d
negl %r10d
leaq (,%rax,4), %rdx
movq 0x8(%rsp), %rsi
testl %ebx, %ebx
jle 0x50da
xorl %edi, %edi
movl (%rsi,%rdi,4), %r8d
cmpl %r10d, %r8d
setl %r9b
cmpl %r11d, %r8d
setge %r8b
orb %r9b, %r8b
jne 0x50d2
incl (%r12,%r13,4)
incq %rdi
cmpq %rdi, %rax
jne 0x50b7
incq %r13
addq %rdx, %rsi
cmpq %rcx, %r13
jne 0x50b1
xorl %eax, %eax
xorl %ebp, %ebp
xorl %edx, %edx
cmpl %ebx, (%r12,%rax,4)
sete %dl
addl %edx, %ebp
incq %rax
cmpq %rax, %rcx
jne 0x50e9
movq 0xbef5(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x82a7(%rip), %rsi      # 0xd3b4
xorl %r13d, %r13d
movl %ebp, %edx
xorl %eax, %eax
callq 0x1180
movq 0x20(%rsp), %rax
subl %ebp, %eax
movq 0x10(%rsp), %rbx
movl %eax, 0x28(%rbx)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x11b0
movq 0x20(%rsp), %rsi
movq %rax, 0x30(%rbx)
movq 0x30(%rsp), %rbx
xorl %ecx, %ecx
cmpl %ebx, (%r12,%r13,4)
je 0x5153
movslq %ecx, %rdx
incl %ecx
movl %r13d, (%rax,%rdx,4)
incq %r13
cmpq %r13, %rsi
jne 0x5144
movslq %ebx, %rdi
shlq $0x2, %rdi
movq %rdi, 0x38(%rsp)
callq 0x11b0
testl %ebx, %ebx
movq %rax, 0x40(%rsp)
jle 0x52d2
leal 0x3(%rbx), %esi
andl $-0x4, %esi
decq %r15
movq %r15, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
pmovsxbq 0x803b(%rip), %xmm1     # 0xd1d0
pmovsxbq 0x8034(%rip), %xmm2     # 0xd1d2
xorl %ecx, %ecx
movdqa 0x7f08(%rip), %xmm3     # 0xd0b0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
pmovsxbq 0x801b(%rip), %xmm5     # 0xd1d4
movq 0x8(%rsp), %r13
movq (%rsp), %r9
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
pcmpgtq %xmm0, %xmm6
movd %xmm6, %edx
notl %edx
testb $0x1, %dl
je 0x51e1
movl $0x1, (%rax,%rcx,4)
pxor %xmm4, %xmm6
pextrb $0x8, %xmm6, %edx
testb $0x1, %dl
je 0x51f8
movl $0x1, 0x4(%rax,%rcx,4)
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
pcmpgtq %xmm0, %xmm6
pxor %xmm4, %xmm6
pextrb $0x0, %xmm6, %edx
testb $0x1, %dl
je 0x521c
movl $0x1, 0x8(%rax,%rcx,4)
pextrb $0x8, %xmm6, %edx
testb $0x1, %dl
je 0x522f
movl $0x1, 0xc(%rax,%rcx,4)
addq $0x4, %rcx
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
cmpq %rcx, %rsi
jne 0x51c2
testl %r14d, %r14d
js 0x5344
testl %ebx, %ebx
jle 0x52dc
movq 0xbf00(%rip), %rcx      # 0x11158
movl %r14d, %edx
imull %ebx, %edx
movl %ebx, %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
leaq (,%rdx,4), %rsi
addq %r13, %rsi
xorl %edi, %edi
cmpq %rcx, %r9
je 0x528c
movq 0x28(%rsp), %r8
cmpl $0x1, 0x18(%r8)
jne 0x52ac
leaq (%rdx,%rdi), %r8
jmp 0x529d
leaq (%rdi,%rdx), %r8
cmpl $0x0, (%rsi,%rdi,4)
jns 0x529d
movl $0x0, (%rax,%rdi,4)
cmpl $0x0, (%r13,%r8,4)
jne 0x52ac
movl $0x0, (%rax,%rdi,4)
incq %rdi
cmpq %rdi, %r10
jne 0x5275
testl %ebx, %ebx
jle 0x52dc
xorl %ecx, %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpl $0x1, (%rax,%rcx,4)
sete %sil
addl %esi, %edx
incq %rcx
cmpq %rcx, %r10
jne 0x52bc
jmp 0x52de
testl %r14d, %r14d
movq 0x8(%rsp), %r13
js 0x5344
xorl %edx, %edx
movq 0xbd13(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x80e4(%rip), %rsi      # 0xd3d3
movl %edx, (%rsp)
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1180
movl %r14d, %eax
movq 0x18(%rsp), %rcx
movq (%rcx,%rax,8), %rbx
movq %rbx, %rdi
callq 0x10c0
movq %rax, %r13
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x10c0
leaq 0x1(%rax), %r15
cmpq %r15, %r13
jbe 0x5370
movl $0x1, 0x18(%rsp)
cmpb $0x2f, (%rbx,%rax)
movl (%rsp), %eax
je 0x5759
movq 0x8(%rsp), %r13
jmp 0x5380
movq 0xbcad(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x8092(%rip), %rsi      # 0xd3e7
movl %ebx, %edx
xorl %eax, %eax
callq 0x1180
movl %ebx, %r15d
movq 0x20(%rsp), %r9
movq 0x48(%rsp), %r10
jmp 0x54e7
movl $0x1, 0x18(%rsp)
movq 0x8(%rsp), %r13
movl (%rsp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
movl %eax, %ebx
callq 0x11b0
movq 0x50(%rsp), %rcx
movq %rax, (%rcx)
testl %ebx, %ebx
movq 0x30(%rsp), %rbx
movq 0x20(%rsp), %r9
movq 0x48(%rsp), %r10
movq 0x40(%rsp), %r11
jle 0x548e
movl (%rsp), %ecx
leaq -0x1(%rcx), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
leaq 0xc(,%rcx,4), %rcx
andq $-0x10, %rcx
pmovsxbq 0x7df8(%rip), %xmm1     # 0xd1d0
pmovsxbq 0x7df1(%rip), %xmm2     # 0xd1d2
xorl %edx, %edx
movdqa 0x7cc5(%rip), %xmm3     # 0xd0b0
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
pmovsxbq 0x7dd8(%rip), %xmm5     # 0xd1d4
movdqa %xmm2, %xmm7
pxor %xmm3, %xmm7
pcmpgtq %xmm0, %xmm7
movdqa %xmm2, %xmm6
psubq %xmm4, %xmm6
movd %xmm7, %esi
notl %esi
testb $0x1, %sil
je 0x5422
movd %xmm6, (%rax,%rdx)
pxor %xmm4, %xmm7
pextrb $0x8, %xmm7, %esi
testb $0x1, %sil
je 0x543a
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 0x5465
movd %xmm6, 0x8(%rax,%rdx)
pextrb $0x8, %xmm7, %esi
testb $0x1, %sil
je 0x5479
pextrd $0x2, %xmm6, 0xc(%rax,%rdx)
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x53fc
testl %ebx, %ebx
jle 0x54be
movl %ebx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl 0x18(%rsp), %edx
xorl %esi, %esi
xorl %edi, %edi
cmpl $0x1, (%r11,%rsi,4)
jne 0x54b6
leal (%rdx,%rsi), %r8d
movslq %edi, %rdi
movl %r8d, (%rax,%rdi,4)
incl %edi
incq %rsi
cmpq %rsi, %rcx
jne 0x54a2
incl %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
xorl %edx, %edx
cmpl %ebx, (%r12,%rcx,4)
sete %dl
addl %edx, %eax
incq %rcx
cmpq %rcx, %r14
jne 0x54c8
movq 0x10(%rsp), %rcx
movl %eax, 0x38(%rcx)
movl (%rsp), %r15d
cmpl %r9d, %ebp
movq 0x38(%rsp), %r14
jl 0x54fe
cmpl %ebx, %r15d
jl 0x54fe
movl %r9d, %ebp
jmp 0x564b
movl %r15d, (%rsp)
imull %ebp, %r15d
movslq %r15d, %r13
leaq (,%r13,4), %rdi
movq %rdi, 0x18(%rsp)
callq 0x11b0
movq %rax, %rbx
movl %r15d, %eax
testl %r13d, %r13d
movq %rax, 0x28(%rsp)
jle 0x553d
leaq (,%rax,4), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1110
movq 0x30(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq 0x8(%rsp), %rdi
movq %rdi, %rdx
xorl %esi, %esi
movq 0x20(%rsp), %r10
movq 0x40(%rsp), %r11
movq 0x30(%rsp), %r8
cmpl %r8d, (%r12,%rcx,4)
jne 0x55a8
testl %r8d, %r8d
jle 0x55a6
movl %esi, %r13d
imull (%rsp), %r13d
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpl $0x1, (%r11,%r8,4)
jne 0x559e
movl (%rdx,%r8,4), %r10d
leal (%r9,%r13), %r11d
movslq %r11d, %r11
movl %r10d, (%rbx,%r11,4)
movq 0x40(%rsp), %r11
movq 0x20(%rsp), %r10
incl %r9d
incq %r8
cmpq %r8, %rax
jne 0x557b
incl %esi
incq %rcx
addq %r14, %rdx
cmpq %r10, %rcx
jne 0x555d
callq 0x1050
movq 0x10(%rsp), %r12
movl %ebp, (%r12)
movl (%rsp), %eax
movl %eax, 0x4(%r12)
movq 0x18(%rsp), %rdi
callq 0x11b0
movq %rax, %r13
movq %rax, 0x20(%r12)
testl %r15d, %r15d
jle 0x55f3
movq 0x28(%rsp), %rdx
shlq $0x2, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x1110
testl %ebp, %ebp
je 0x5748
movq %r13, 0x8(%rsp)
movl (%rsp), %eax
movl %eax, %r15d
shlq $0x2, %r15
movl %ebp, %r12d
xorl %r13d, %r13d
testl %eax, %eax
jle 0x562f
movl %r13d, %eax
leaq (%rbx,%rax,4), %rsi
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movq %r15, %rdx
callq 0x11a0
movl (%rsp), %eax
addl %eax, %r13d
decq %r12
jne 0x5610
movq %rbx, %rdi
movl %eax, %ebx
callq 0x1050
movq 0x8(%rsp), %r13
movq 0x48(%rsp), %r10
movl %ebx, %eax
movl %ebp, %ecx
leaq (,%rax,4), %rdx
xorl %esi, %esi
testl %eax, %eax
jle 0x5679
xorl %edi, %edi
movl (%r13,%rdi,4), %r8d
testl %r8d, %r8d
jns 0x5671
addl %r10d, %r8d
movl %r8d, (%r13,%rdi,4)
incq %rdi
cmpq %rdi, %rax
jne 0x565f
incq %rsi
addq %rdx, %r13
cmpq %rcx, %rsi
jne 0x5659
movb $0x1, %bl
movslq %ebp, %rdi
shlq $0x3, %rdi
callq 0x11b0
movq 0x10(%rsp), %rcx
movq %rax, 0x50(%rcx)
testb %bl, %bl
je 0x5725
movl %ebp, %edx
leal 0x1(%rbp), %ecx
andl $-0x2, %ecx
decq %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
pmovsxbq 0x7b11(%rip), %xmm1     # 0xd1d2
xorl %edx, %edx
movdqa 0x79e5(%rip), %xmm2     # 0xd0b0
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
pmovsxbq 0x7af0(%rip), %xmm4     # 0xd1d6
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
pcmpgtq %xmm0, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0x5703
movq %rsi, (%rax,%rdx,8)
pxor %xmm3, %xmm5
pextrb $0x8, %xmm5, %edi
testb $0x1, %dil
je 0x5718
movq %rsi, 0x8(%rax,%rdx,8)
addq $0x2, %rdx
paddq %xmm4, %xmm1
cmpq %rdx, %rcx
jne 0x56e6
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movq 0x10(%rsp), %rax
movsd %xmm0, 0x48(%rax)
addq $0x14068, %rsp          # imm = 0x14068
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x1050
xorl %ebx, %ebx
xorl %ebp, %ebp
jmp 0x5686
callq 0x1260
movq (%rax), %rcx
movslq %r15d, %rax
movsbq (%rbx,%rax), %rdx
testb $0x8, 0x1(%rcx,%rdx,2)
jne 0x577a
callq 0x12cc
jmp 0x5378
cmpq %rax, %r13
jbe 0x57b3
movslq %r15d, %rdx
leaq (%rdx,%rbx), %rsi
incq %rsi
xorl %eax, %eax
movsbq (%rsi,%rax), %rdi
testb $0x8, 0x1(%rcx,%rdi,2)
je 0x57a6
leaq (%rdx,%rax), %rdi
incq %rdi
incq %rax
cmpq %rdi, %r13
ja 0x578b
xorl %edx, %edx
testl %eax, %eax
movq 0x8(%rsp), %r13
jns 0x57ba
jmp 0x57e5
xorl %eax, %eax
movq 0x8(%rsp), %r13
movl %eax, %eax
movslq %r15d, %rcx
addq %rcx, %rbx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0x1, %ecx
movsbl (%rbx,%rax), %esi
addl $-0x30, %esi
imull %ecx, %esi
addl %esi, %edx
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
addq $-0x1, %rax
jb 0x57cc
incl %edx
movq 0xb80c(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
leaq 0x7bfb(%rip), %rsi      # 0xd3f1
movl %edx, 0x18(%rsp)
xorl %eax, %eax
callq 0x1180
jmp 0x537d
movq 0x10(%rsp), %rcx
movl %r13d, (%rcx)
movq 0xb7e3(%rip), %rcx      # 0x10ff8
movq (%rcx), %rdi
leaq 0x7acd(%rip), %rsi      # 0xd2ec
leaq 0x60(%rsp), %r8
leaq 0xa060(%rsp), %r9
movq %rax, %rdx
movl %ebx, %ecx
xorl %eax, %eax
callq 0x1180
movl $0x1, %edi
callq 0x1200
movl %r13d, %edi
movq 0x10(%rsp), %rsi
callq 0x12a5
callq 0x1313
callq 0x12ee
callq 0x1280