// File: /workspace/github_c_makefile_star2_O2/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 $0x14078, %rsp          # imm = 0x14078
movq %rsi, 0x38(%rsp)
testq %rdi, %rdi
je 0x3971
leaq 0x98f9(%rip), %rsi      # 0xd1f0
callq 0x11c0
testq %rax, %rax
je 0x3989
movq %rax, %r15
movl $0x88, %edi
callq 0x11a0
andl $0x0, 0x8(%rax)
andq $0x0, (%rax)
movq 0x38(%rsp), %rcx
movq 0x8(%rcx), %rbx
movq %rbx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
orl $-0x1, 0x38(%rax)
movups %xmm0, 0x5c(%rax)
movups %xmm0, 0x50(%rax)
movq %rax, 0x8(%rsp)
movups %xmm0, 0x40(%rax)
leaq 0x70(%rsp), %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r15, %rdx
callq 0x1140
testq %rax, %rax
je 0x39b7
leaq 0x70(%rsp), %r14
pushq $0xa
popq %rsi
movq %r14, %rdi
callq 0x10d0
testq %rax, %rax
je 0x39a4
jmp 0x39a1
movq 0xc680(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x87f8(%rip), %rdi      # 0xc17a
pushq $0x2b
jmp 0x42f6
movq 0xc668(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x880c(%rip), %rdi      # 0xc1a6
pushq $0x1d
jmp 0x42f6
movb $0x0, (%rax)
movq %r14, %rdi
callq 0x10c0
addq %r14, %rax
decq %rax
cmpb $0xd, (%rax)
je 0x39a1
movq %r15, (%rsp)
cmpb $0x3e, 0x70(%rsp)
jne 0x4344
movq 0x8(%rsp), %r15
movq %r15, %rax
addq $0x40, %rax
movq %rax, 0x68(%rsp)
leaq 0xa070(%rsp), %r12
movq %r12, %rdi
movq (%rsp), %rsi
callq 0x54d8
movq %rbx, %rdi
callq 0x10c0
movq %rax, %r14
movl %r14d, 0x8(%r15)
movq %r12, %rdi
callq 0x10c0
movl %eax, 0x4(%r15)
movslq %eax, %rcx
movq %rcx, 0x60(%rsp)
pushq $-0x1
popq %rcx
movq %rcx, 0x28(%rsp)
pushq $-0x4
popq %rcx
movq %rcx, 0x58(%rsp)
pushq $0x8
popq %r13
movq %rax, 0x10(%rsp)
movl %eax, %ebp
movq (%rsp), %r12
movq %r12, %rdi
callq 0x1180
testl %eax, %eax
jne 0x3ace
movq %r12, %rdi
callq 0x1110
cmpb $0x3e, %al
jne 0x42d5
leaq 0x70(%rsp), %r15
movq %r15, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r12, %rdx
callq 0x1140
testq %rax, %rax
je 0x3a8f
movq %r15, %rdi
pushq $0xa
popq %rsi
callq 0x10d0
testq %rax, %rax
jne 0x3a8a
movq %r15, %rdi
callq 0x10c0
addq %r15, %rax
decq %rax
cmpb $0xd, (%rax)
jne 0x3a8f
movb $0x0, (%rax)
jmp 0x3a77
leaq 0xa070(%rsp), %r15
movq %r15, %rdi
movq (%rsp), %rsi
callq 0x54d8
movq %r15, %rdi
callq 0x10c0
cmpq 0x60(%rsp), %rax
jne 0x4301
decq 0x28(%rsp)
addq $-0x4, 0x58(%rsp)
addq $0x8, %r13
addl 0x10(%rsp), %ebp
jmp 0x3a2d
movq 0x28(%rsp), %r15
negq %r15
movq 0x8(%rsp), %rax
movl %r15d, (%rax)
movslq %ebp, %rdi
shlq $0x2, %rdi
callq 0x11a0
movq %rax, %r12
movq 0x8(%rsp), %rbp
movq %rax, 0x20(%rbp)
movq %r13, %rdi
movq %r15, %r13
callq 0x11a0
movq %rax, 0x18(%rsp)
movq %rax, 0x18(%rbp)
xorl %eax, %eax
movq 0x10(%rsp), %r15
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
xorl %edx, %edx
cmpl %edx, %r13d
je 0x3b42
movslq %eax, %rsi
leaq (%r12,%rsi,4), %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x3b3b
andl $0x0, (%rsi,%rdi,4)
incq %rdi
jmp 0x3b2d
incl %edx
addl %r15d, %eax
jmp 0x3b1f
xorl %eax, %eax
movq 0x18(%rsp), %rcx
cmpq %rax, %r13
je 0x3b58
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x3b49
movq %r12, 0x40(%rsp)
movq (%rsp), %rdi
callq 0x10e0
movq $0x0, 0x20(%rsp)
testl %r15d, %r15d
movl $0x0, %r12d
cmovgl %r15d, %r12d
shlq $0x2, %r15
movq %r15, 0x48(%rsp)
xorl %ecx, %ecx
movq %r13, 0x30(%rsp)
cmpq %rcx, %r13
je 0x3c7b
movq %rcx, 0x50(%rsp)
movq (%rsp), %r15
movq %r15, %rdi
callq 0x1220
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
movl $0xa000, %esi           # imm = 0xA000
movq %r15, %rdx
callq 0x1140
testq %rax, %rax
je 0x3be8
movq %rbp, %rdi
pushq $0xa
popq %rsi
callq 0x10d0
testq %rax, %rax
jne 0x3be3
movq %rbp, %rdi
callq 0x10c0
addq %rbp, %rax
decq %rax
cmpb $0xd, (%rax)
jne 0x3be8
movb $0x0, (%rax)
jmp 0x3bd0
movq 0x20(%rsp), %r13
shlq $0x1e, %r13
sarq $0x1e, %r13
addq 0x40(%rsp), %r13
movq %rbp, %rdi
callq 0x10c0
leaq 0x1(%rax), %rdi
callq 0x11a0
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
movq %rax, %rdi
movq %rbp, %rsi
callq 0x1070
leaq 0xa070(%rsp), %rdi
movq %r15, %rsi
callq 0x54d8
xorl %r15d, %r15d
cmpq %r15, %r12
je 0x3c5a
movsbl 0xa070(%rsp,%r15), %edi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x5590
movl %eax, (%r13,%r15,4)
incq %r15
jmp 0x3c37
movq 0x50(%rsp), %rcx
incq %rcx
movq 0x20(%rsp), %rax
addq 0x48(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %r13
jmp 0x3b8c
movq 0x38(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x3c94
pushq $-0x1
popq %r12
movq 0x10(%rsp), %r15
jmp 0x3d54
pushq $-0x1
popq %rax
movl %eax, %r12d
movl %eax, (%rsp)
xorl %r13d, %r13d
cmpq %r13, 0x30(%rsp)
je 0x3d11
movq 0x38(%rsp), %rax
movq (%rax), %r15
movq 0x18(%rsp), %rax
movq (%rax,%r13,8), %rbp
movq %r15, %rdi
callq 0x10c0
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
callq 0x1060
testl %eax, %eax
jne 0x3ce7
testl %r12d, %r12d
jns 0x3cec
movq 0x8(%rsp), %rax
movl %r13d, 0x38(%rax)
movl %r13d, %r12d
movl %r13d, (%rsp)
incq %r13
jmp 0x3ca0
movq 0xc305(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leal 0x1(%r13), %ecx
leaq 0x8577(%rip), %rsi      # 0xc278
movq %r15, %rdx
xorl %eax, %eax
callq 0x1170
movl %r12d, (%rsp)
jmp 0x3ce7
movq 0xc2e0(%rip), %rax      # 0xfff8
movq (%rax), %rdi
movq 0x38(%rsp), %rax
movq (%rax), %rdx
movl (%rsp), %ecx
testl %ecx, %ecx
js 0x3d3c
incl %ecx
leaq 0x857c(%rip), %rsi      # 0xc2af
xorl %eax, %eax
callq 0x1170
jmp 0x3d4a
leaq 0x858b(%rip), %rsi      # 0xc2ce
xorl %eax, %eax
callq 0x1170
movq 0x10(%rsp), %r15
movq 0x30(%rsp), %r13
movq 0x58(%rsp), %rdi
negq %rdi
callq 0x11a0
movq %rax, %rbp
xorl %eax, %eax
movq 0x40(%rsp), %r11
cmpq %rax, %r13
je 0x3d7a
andl $0x0, (%rbp,%rax,4)
incq %rax
jmp 0x3d6b
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movl %r14d, %edx
negl %edx
xorl %esi, %esi
cmpq %rsi, %r13
je 0x3dd4
movq %rax, %rdi
shlq $0x1e, %rdi
sarq $0x1e, %rdi
addq %r11, %rdi
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x3dca
movl (%rdi,%r8,4), %r9d
cmpl %edx, %r9d
setl %r10b
cmpl %r14d, %r9d
setge %r9b
orb %r10b, %r9b
jne 0x3dc5
incl (%rbp,%rsi,4)
incq %r8
jmp 0x3da5
incq %rsi
addq 0x48(%rsp), %rax
jmp 0x3d8f
xorl %eax, %eax
xorl %edx, %edx
cmpq %rax, %r13
je 0x3dee
xorl %ecx, %ecx
cmpl %r15d, (%rbp,%rax,4)
sete %cl
addl %ecx, %edx
incq %rax
jmp 0x3dd8
movl %r12d, (%rsp)
movq 0xc1ff(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x8501(%rip), %rsi      # 0xc304
xorl %r15d, %r15d
movl %r13d, %ecx
xorl %eax, %eax
movl %edx, %r12d
callq 0x1170
movq 0x28(%rsp), %rax
addl %r12d, %eax
negl %eax
movq 0x8(%rsp), %rcx
movl %eax, 0x28(%rcx)
movl %r12d, 0x20(%rsp)
movl %r12d, %eax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
negq %rdi
callq 0x11a0
movq 0x8(%rsp), %rcx
movq %rax, 0x30(%rcx)
movq 0x10(%rsp), %r12
xorl %edx, %edx
subq $0x1, %r13
jb 0x3e6e
cmpl %r12d, (%rbp,%r15,4)
je 0x3e69
movslq %edx, %rsi
incl %edx
movl %r15d, (%rax,%rsi,4)
incq %r15
jmp 0x3e53
movslq %r12d, %rdi
shlq $0x2, %rdi
callq 0x11a0
movq %rax, %r15
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %r13d
cmovgl %r12d, %r13d
movq 0x40(%rsp), %r8
cmpq %rax, %r13
je 0x3ea3
movl $0x1, (%r15,%rax,4)
incq %rax
jmp 0x3e91
movl (%rsp), %ecx
testl %ecx, %ecx
js 0x3ef9
movq 0xc29f(%rip), %rax      # 0x10150
imull %r12d, %ecx
movslq %ecx, %rcx
leaq (%r8,%rcx,4), %rdx
xorl %esi, %esi
cmpq %rsi, %r13
je 0x3f21
cmpq %rax, %rbx
je 0x3ed9
movq 0x38(%rsp), %rdi
cmpl $0x1, 0x18(%rdi)
jne 0x3ef4
leaq (%rcx,%rsi), %rdi
jmp 0x3ee8
leaq (%rsi,%rcx), %rdi
cmpl $0x0, (%rdx,%rsi,4)
jns 0x3ee8
andl $0x0, (%r15,%rsi,4)
cmpl $0x0, (%r8,%rdi,4)
jne 0x3ef4
andl $0x0, (%r15,%rsi,4)
incq %rsi
jmp 0x3ebe
movq 0xc0f8(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x842d(%rip), %rsi      # 0xc337
movl %r12d, %edx
xorl %eax, %eax
callq 0x1170
movl %r12d, %r9d
movl 0x20(%rsp), %r8d
jmp 0x4033
xorl %eax, %eax
xorl %ebx, %ebx
cmpq %rax, %r13
je 0x3f3b
xorl %ecx, %ecx
cmpl $0x1, (%r15,%rax,4)
sete %cl
addl %ecx, %ebx
incq %rax
jmp 0x3f25
movq 0xc0b6(%rip), %rax      # 0xfff8
movq (%rax), %rdi
leaq 0x83d7(%rip), %rsi      # 0xc323
movl %ebx, %edx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x1170
movl (%rsp), %ecx
movq 0x18(%rsp), %rax
movq %rcx, 0x48(%rsp)
movq (%rax,%rcx,8), %rdi
movq %rdi, 0x18(%rsp)
callq 0x10c0
movq %rax, %r12
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x10c0
leaq 0x1(%rax), %rdx
movl %ebx, %ecx
movq %r12, 0x28(%rsp)
cmpq %rdx, %r12
movq %rcx, (%rsp)
jbe 0x3fb0
movq 0x18(%rsp), %rsi
cmpb $0x2f, (%rsi,%rax)
pushq $0x1
popq %rbx
je 0x421b
movq 0x10(%rsp), %r12
jmp 0x3fb8
movq 0x10(%rsp), %r12
pushq $0x1
popq %rbx
leaq (,%rcx,4), %rdi
callq 0x11a0
movq (%rsp), %r9
movq 0x68(%rsp), %rcx
movq %rax, (%rcx)
xorl %ecx, %ecx
movl 0x20(%rsp), %r8d
cmpq %rcx, %r9
je 0x3fe9
leaq 0x1(%rcx), %rdx
movl %edx, (%rax,%rcx,4)
movq %rdx, %rcx
jmp 0x3fd8
movl %ebx, %ecx
xorl %edx, %edx
xorl %esi, %esi
cmpq %rdx, %r13
je 0x400b
cmpl $0x1, (%r15,%rdx,4)
jne 0x4006
leal (%rcx,%rdx), %edi
movslq %esi, %rsi
movl %edi, (%rax,%rsi,4)
incl %esi
incq %rdx
jmp 0x3fef
pushq $-0x1
popq %rax
xorl %ecx, %ecx
movq 0x48(%rsp), %rsi
cmpq %rsi, %rcx
ja 0x402b
xorl %edx, %edx
cmpl %r12d, (%rbp,%rcx,4)
sete %dl
addl %edx, %eax
incq %rcx
jmp 0x4015
movq 0x8(%rsp), %rcx
movl %eax, 0x38(%rcx)
cmpl 0x30(%rsp), %r8d
jb 0x404c
cmpl %r12d, %r9d
jl 0x404c
movq 0x30(%rsp), %rax
movl %eax, %r10d
jmp 0x4181
movq %r9, (%rsp)
movl %r9d, %eax
imull %r8d, %eax
movslq %eax, %rbx
leaq (,%rbx,4), %rdi
movq %rdi, 0x48(%rsp)
callq 0x11a0
movq %rbx, %rcx
movq %rax, %rbx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
movq 0x40(%rsp), %rdi
cmpq %rax, %rcx
je 0x408c
andl $0x0, (%rbx,%rax,4)
incq %rax
jmp 0x407e
movq %rcx, 0x18(%rsp)
shlq $0x2, 0x60(%rsp)
xorl %eax, %eax
movq %rdi, %rcx
xorl %edx, %edx
cmpq %rax, 0x30(%rsp)
je 0x40e7
cmpl %r12d, (%rbp,%rax,4)
jne 0x40dd
movl %edx, %esi
imull (%rsp), %esi
xorl %r11d, %r11d
xorl %r8d, %r8d
cmpq %r11, %r13
je 0x40db
cmpl $0x1, (%r15,%r11,4)
jne 0x40d6
movl (%rcx,%r11,4), %r9d
leal (%r8,%rsi), %r10d
movslq %r10d, %r10
movl %r9d, (%rbx,%r10,4)
incl %r8d
incq %r11
jmp 0x40b8
incl %edx
incq %rax
addq 0x60(%rsp), %rcx
jmp 0x409e
callq 0x1050
movq 0x8(%rsp), %r15
movl 0x20(%rsp), %eax
movl %eax, (%r15)
movq (%rsp), %rax
movl %eax, 0x4(%r15)
movq 0x48(%rsp), %rdi
callq 0x11a0
movq %rax, 0x20(%r15)
xorl %ecx, %ecx
movq 0x50(%rsp), %r11
movq 0x18(%rsp), %rdx
cmpq %rcx, %rdx
je 0x4128
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x411a
xorl %r10d, %r10d
movq (%rsp), %rdx
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
movslq %edx, %rdx
shlq $0x2, %rdx
movq %rax, %rsi
movq %rbx, %rdi
cmpq %r11, %r10
je 0x416b
xorl %r8d, %r8d
cmpq %r8, %rcx
je 0x4160
movl (%rdi,%r8,4), %r9d
movl %r9d, (%rsi,%r8,4)
incq %r8
jmp 0x414e
incq %r10
addq %rdx, %rdi
addq %rdx, %rsi
jmp 0x4146
movq %rax, 0x40(%rsp)
movq %rbx, %rdi
callq 0x1050
movq (%rsp), %r12
movl 0x20(%rsp), %r10d
xorl %eax, %eax
testl %r12d, %r12d
movl $0x0, %ecx
cmovgl %r12d, %ecx
xorl %edx, %edx
movq 0x40(%rsp), %r9
cmpl %r10d, %edx
je 0x41c5
movslq %eax, %rsi
leaq (%r9,%rsi,4), %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0x41be
movl (%rsi,%rdi,4), %r8d
testl %r8d, %r8d
jns 0x41b9
addl %r14d, %r8d
movl %r8d, (%rsi,%rdi,4)
incq %rdi
jmp 0x41a4
incl %edx
addl %r12d, %eax
jmp 0x4196
movslq %r10d, %rdi
shlq $0x3, %rdi
movl %r10d, %ebx
callq 0x11a0
movl %ebx, %edi
movq 0x8(%rsp), %rcx
movq %rax, 0x50(%rcx)
movl %ebx, %ecx
xorl %edx, %edx
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
cmpq %rdx, %rcx
je 0x41fb
movq %rsi, (%rax,%rdx,8)
incq %rdx
jmp 0x41ed
cvtsi2sd %edi, %xmm0
movq 0x8(%rsp), %rax
movsd %xmm0, 0x48(%rax)
addq $0x14078, %rsp          # imm = 0x14078
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %r12
callq 0x1250
movq 0x18(%rsp), %r8
movq (%rax), %rcx
movslq %r12d, %rax
movsbq (%r8,%rax), %rax
testb $0x8, 0x1(%rcx,%rax,2)
jne 0x425d
movq 0xbdb7(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x810b(%rip), %rdi      # 0xc356
pushq $0x29
popq %rsi
pushq $0x1
popq %rdx
callq 0x1200
movq 0x10(%rsp), %r12
jmp 0x42cc
movslq %r12d, %rdx
leaq (%r8,%rdx), %rsi
incq %rsi
xorl %eax, %eax
movq 0x28(%rsp), %r9
leaq (%rdx,%rax), %rdi
cmpq %rdi, %r9
jbe 0x4288
movsbq (%rsi,%rax), %rdi
testb $0x8, 0x1(%rcx,%rdi,2)
je 0x4288
incq %rax
jmp 0x426e
addq %rdx, %r8
pushq $0x1
popq %rcx
pushq $-0x1
popq %rbx
movq 0x10(%rsp), %r12
testq %rax, %rax
js 0x42b0
movsbl (%r8,%rax), %edx
addl $-0x30, %edx
imull %ecx, %edx
addl %edx, %ebx
imull $0xa, %ecx, %ecx
decq %rax
jmp 0x4296
movq 0xbd41(%rip), %rax      # 0xfff8
movq (%rax), %rdi
incl %ebx
leaq 0x807e(%rip), %rsi      # 0xc341
movl %ebx, %edx
xorl %eax, %eax
callq 0x1170
movq (%rsp), %rcx
jmp 0x3fb8
movq 0x28(%rsp), %rcx
negl %ecx
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movq 0xbd0e(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x7f09(%rip), %rdi      # 0xc1fd
pushq $0x3e
popq %rsi
pushq $0x1
popq %rdx
callq 0x1200
jmp 0x433c
movq 0x28(%rsp), %rdx
negl %edx
movq 0x8(%rsp), %rcx
movl %edx, (%rcx)
movq 0xbce2(%rip), %rcx      # 0xfff8
movq (%rcx), %rdi
leaq 0x7f1c(%rip), %rsi      # 0xc23c
leaq 0x70(%rsp), %r8
leaq 0xa070(%rsp), %r9
movq %rax, %rdx
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x1170
pushq $0x1
popq %rdi
callq 0x11f0
movq 0xbcad(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x7e6f(%rip), %rdi      # 0xc1c4
pushq $0x38
jmp 0x42f6