// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/lib/axt.c
// Function: axtScoreSchemeReadLf
struct axtScoreScheme *axtScoreSchemeReadLf(struct lineFile *lf )
/* Read in scoring scheme from file. Looks like
    A    C    G    T
    91 -114  -31 -123
  -114  100 -125  -31
   -31 -125  100 -114
  -123  -31 -114   91
  O = 400, E = 30

2013-12-13 - upgrading to allow reading of newer format settings file
from lastz tuning output.  This file has the matrix at the end of
the file, and other settings before that.  Will include the other settings
in the 'ss->extra' field *WITHOUT* the O= and E= which should always
be O=400 and E=30 despite what the tuning settings file says.
Example settings file:
#############################################################################
# (a LASTZ scoring set, created by "LASTZ --infer")

bad_score          = X:-1736 # used for sub[X][*] and sub[*][X]
fill_score         = -174    # used when sub[*][*] not otherwise defined

# (score parameters added by expand_scores_file)

T=2
O=565
E=43
X=790
Y=4865
K=3000
L=3000

      A     C     G     T
A    79   -84   -55  -128
C   -84   100  -174   -55
G   -55  -174   100   -84
T  -128   -55   -84    79
#############################################################################

*/
{
char *line, *row[6], *parts[32];
int i,j, partCount;
struct axtScoreScheme *ss;
boolean gotO = FALSE, gotE = FALSE;
static int trans[4] = {'a', 'c', 'g', 't'};

AllocVar(ss);
ss->extra = NULL;
struct dyString *dyExtra = newDyString(128);

int wordCount = lineFileChopNext(lf, row, ArraySize(row));
if (!wordCount)
    shortScoreScheme(lf);   // empty file
boolean done = FALSE;
while (! done)
{
    // a setting will have an '=' in either first or second word
    if (stringIn("=",row[0]) || (wordCount > 1 && stringIn("=", row[1])))
    {
        // collapse words to eliminate white space confusion
        struct dyString *dy = newDyString(128);
        for (i = 0; i < wordCount; ++i)
        {
            dyStringPrintf(dy, "%s", row[i]);
        }
        char *line=dyStringCannibalize(&dy);
        // eliminate trailing comments
        chopSuffixAt(line, '#');
        // only tag=value is left, extract those two:
        chopString(line, "=", parts, ArraySize(parts));
        if (!(sameString(parts[0],"O") || sameString(parts[0],"E")))
            dyStringPrintf(dyExtra, "%s=%s,", parts[0], parts[1]);
        freeMem(line);
        wordCount = lineFileChopNext(lf, row, ArraySize(row));
    }
    // not a setting, expecting a matrix definition
    else if (row[0][0] != 'A' || row[1][0] != 'C' || row[2][0] != 'G' 
            || row[3][0] != 'T')
        errAbort("%s doesn't seem to be a score matrix file", lf->fileName);
    else  // have reached the matrix definition at end of the file
    {
        for (i=0; i<4; ++i)
        {
            wordCount = lineFileChopNext(lf, row, ArraySize(row));
            if (!wordCount)
                shortScoreScheme(lf);   // did not find four lines
            int startColumn = 0;
            if (5 == wordCount)  // skip first column when there are 5
                startColumn = 1;
            for (j=startColumn; j<(startColumn+4); ++j)
                ss->matrix[trans[i]][trans[j-startColumn]] = lineFileNeedNum(lf, row, j);
        }
        if (lineFileNext(lf, &line, NULL))
        {
            dyStringPrintf(dyExtra, "%s,", line);
            partCount = chopString(line, " =,\t", parts, ArraySize(parts));
            for (i=0; i<partCount-1; i += 2)
            {
                if (sameString(parts[i], "O"))
                {
                    gotO = TRUE;
                    ss->gapOpen = atoi(parts[i+1]);
                }
                if (sameString(parts[i], "E"))
                {
                    gotE = TRUE;
                    ss->gapExtend = atoi(parts[i+1]);
                }
            }
            if (!gotO || !gotE)
                errAbort("Expecting O = and E = in last line of %s", lf->fileName);
            if (ss->gapOpen <= 0 || ss->gapExtend <= 0)
                errAbort("Must have positive gap scores");
        }
        else
        {
            ss->gapOpen = 400;
            ss->gapExtend = 30;
        }
        done = TRUE;
    }
}
ss->extra = dyStringCannibalize(&dyExtra);
if (',' == lastChar(ss->extra))
    trimLastChar(ss->extra);
propagateCase(ss);
return ss;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movq %rdi, %r15
movl $0x40018, %edi          # imm = 0x40018
callq 0x2dff4
movq %rax, %rbx
movq $0x0, 0x40010(%rax)
movl $0x80, %edi
callq 0x264e0
movq %rax, 0x18(%rsp)
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rsi
movq %r15, %rdi
movl $0x6, %edx
callq 0x2b359
movl %eax, %ebp
testl %eax, %eax
jne 0x1ad3c
movq 0x8(%r15), %rsi
leaq 0x73e2e(%rip), %rdi     # 0x8eb63
xorl %eax, %eax
callq 0x26e94
movq %rbx, 0x20(%rsp)
addq $0x8, %rbx
movq %rbx, 0x28(%rsp)
leaq 0x73c44(%rip), %r12     # 0x8e995
leaq 0x75501(%rip), %r13     # 0x90259
movq 0x40(%rsp), %rbx
movq %rbx, %rdi
movl $0x3d, %esi
callq 0x6270
testq %rax, %rax
jne 0x1adbf
cmpl $0x2, %ebp
jl 0x1ad88
movq 0x48(%rsp), %rdi
movl $0x3d, %esi
callq 0x6270
testq %rax, %rax
jne 0x1add4
cmpb $0x41, (%rbx)
jne 0x1adaf
movq 0x48(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x1adaf
movq 0x50(%rsp), %rax
cmpb $0x47, (%rax)
jne 0x1adaf
movq 0x58(%rsp), %rax
cmpb $0x54, (%rax)
je 0x1ae88
movq 0x8(%r15), %rsi
movq %r12, %rdi
xorl %eax, %eax
callq 0x26e94
jmp 0x1ad58
movl $0x80, %edi
callq 0x264e0
movq %rax, 0x8(%rsp)
testl %ebp, %ebp
jg 0x1ade3
jmp 0x1ae04
movl $0x80, %edi
callq 0x264e0
movq %rax, 0x8(%rsp)
movl %ebp, %ebx
xorl %r14d, %r14d
movq 0x8(%rsp), %rdi
movq 0x40(%rsp,%r14,8), %rdx
movq %r13, %rsi
xorl %eax, %eax
callq 0x26883
incq %r14
cmpq %r14, %rbx
jne 0x1ade8
leaq 0x8(%rsp), %rdi
callq 0x2653c
movq %rax, %rbp
movq %rax, %rdi
movl $0x23, %esi
callq 0x2365c
movq %rbp, %rdi
leaq 0x7525f(%rip), %rsi     # 0x90087
leaq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x22667
movq 0x70(%rsp), %rdx
movzbl (%rdx), %eax
cmpl $0x45, %eax
je 0x1ae49
cmpl $0x4f, %eax
jne 0x1ae4f
cmpb $0x0, 0x1(%rdx)
je 0x1ae67
movq 0x78(%rsp), %rcx
movq 0x18(%rsp), %rdi
leaq 0x73b2e(%rip), %rsi     # 0x8e98e
xorl %eax, %eax
callq 0x26883
movq %rbp, %rdi
callq 0x2e0a0
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
movl $0x6, %edx
callq 0x2b359
movl %eax, %ebp
jmp 0x1ad58
movq %r15, 0x10(%rsp)
leaq 0x40(%rsp), %rsi
leaq 0x73937(%rip), %r12     # 0x8e7d0
xorl %r14d, %r14d
movq 0x10(%rsp), %rbx
movq 0x10(%rsp), %rdi
movq %rsi, %rbp
movl $0x6, %edx
callq 0x2b359
movl %eax, %r15d
testl %eax, %eax
jne 0x1aed1
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x73c99(%rip), %rdi     # 0x8eb63
xorl %eax, %eax
callq 0x26e94
xorl %r13d, %r13d
cmpl $0x5, %r15d
sete %r13b
leaq 0x4(%r13), %rax
movq %rax, 0x30(%rsp)
movq 0x28(%rsp), %r15
movq %rbx, %rdi
movq %rbp, %rsi
movl %r13d, %edx
callq 0x2b605
leaq 0x738d1(%rip), %rcx     # 0x8e7d0
movslq (%rcx,%r14,4), %rcx
movslq (%r12), %rdx
shlq $0xa, %rcx
addq %r15, %rcx
movl %eax, (%rcx,%rdx,4)
incq %r13
addq $0x4, %r12
cmpq %r13, 0x30(%rsp)
jne 0x1aeea
incq %r14
cmpq $0x4, %r14
movq %rbp, %rsi
leaq 0x738a0(%rip), %r12     # 0x8e7d0
jne 0x1aea1
leaq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdi
xorl %edx, %edx
callq 0x2a7a9
testl %eax, %eax
movq 0x20(%rsp), %r13
je 0x1b039
movq 0x8(%rsp), %rdx
leaq 0x73a31(%rip), %rsi     # 0x8e991
xorl %r15d, %r15d
movq 0x18(%rsp), %rdi
xorl %eax, %eax
callq 0x26883
movq 0x8(%rsp), %rdi
leaq 0x73a44(%rip), %rsi     # 0x8e9bf
leaq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x22667
cmpl $0x2, %eax
jl 0x1affe
movl %eax, %ebx
decl %ebx
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x70(%rsp,%r12,8), %r14
movb (%r14), %al
cmpb $0x4f, %al
jne 0x1afc4
cmpb $0x0, 0x1(%r14)
jne 0x1afe6
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movl %eax, 0x40008(%r13)
movb (%r14), %al
movl $0x1, %ebp
cmpb $0x45, %al
jne 0x1afe6
cmpb $0x0, 0x1(%r14)
jne 0x1afe6
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movl %eax, 0x4000c(%r13)
movl $0x1, %r15d
addq $0x2, %r12
cmpq %rbx, %r12
jb 0x1af98
testl %ebp, %ebp
setne %al
testl %r15d, %r15d
setne %cl
testb %cl, %al
jne 0x1b015
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x739b6(%rip), %rdi     # 0x8e9c4
xorl %eax, %eax
callq 0x26e94
cmpl $0x0, 0x40008(%r13)
jle 0x1b029
cmpl $0x0, 0x4000c(%r13)
jg 0x1b04a
leaq 0x739bd(%rip), %rdi     # 0x8e9ed
xorl %eax, %eax
callq 0x26e94
jmp 0x1b04a
movabsq $0x1e00000190, %rax     # imm = 0x1E00000190
movq %rax, 0x40008(%r13)
leaq 0x38(%rsp), %rdi
callq 0x2653c
movq %rax, 0x40010(%r13)
movq %rax, %rdi
callq 0x21e90
cmpb $0x2c, %al
jne 0x1b073
movq 0x40010(%r13), %rdi
callq 0x21eb3
movq %r13, %rdi
callq 0x1a5c2
movq %r13, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq