// File: /workspace/github_c_makefile_star2_O1/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, %r14
movl $0x40018, %edi          # imm = 0x40018
callq 0x2dc95
movq %rax, %rbx
movq $0x0, 0x40010(%rax)
movl $0x80, %edi
callq 0x261d0
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
movl $0x6, %edx
callq 0x2b03f
movl %eax, %r13d
testl %eax, %eax
jne 0x1aab5
movq 0x8(%r14), %rsi
leaq 0x74017(%rip), %rdi     # 0x8eac5
xorl %eax, %eax
callq 0x26b6f
movq %rbx, 0x8(%rsp)
addq $0x8, %rbx
movq %rbx, 0x38(%rsp)
leaq 0x40(%rsp), %rbx
leaq 0x756ca(%rip), %r12     # 0x90199
movl $0x0, 0x4(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
movq 0x40(%rsp), %rbp
movq %rbp, %rdi
movl $0x3d, %esi
callq 0x6270
testq %rax, %rax
je 0x1abdc
movl $0x80, %edi
callq 0x261d0
movq %rax, 0x28(%rsp)
testl %r13d, %r13d
jle 0x1ab38
movl %r13d, %ebx
xorl %r15d, %r15d
movq 0x28(%rsp), %rdi
movq 0x40(%rsp,%r15,8), %rdx
movq %r12, %rsi
xorl %eax, %eax
callq 0x2656a
incq %r15
cmpq %r15, %rbx
jne 0x1ab1c
movq %r12, %r15
leaq 0x28(%rsp), %rdi
callq 0x2622c
movq %rax, %r12
movq %rax, %rdi
movl $0x23, %esi
callq 0x2333e
movq %r12, %rdi
leaq 0x75468(%rip), %rsi     # 0x8ffc7
leaq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x22314
movq 0x70(%rsp), %rbp
movq %rbp, %rdi
leaq 0x73d71(%rip), %rsi     # 0x8e8ee
callq 0x6a50
testl %eax, %eax
je 0x1abb4
movq %rbp, %rdi
leaq 0x7baf2(%rip), %rsi     # 0x96682
callq 0x6a50
testl %eax, %eax
je 0x1abb4
movq 0x20(%rsp), %rdi
movq 0x78(%rsp), %rcx
leaq 0x73d46(%rip), %rsi     # 0x8e8f0
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2656a
movq %r12, %rdi
callq 0x2dd41
movq %r14, %rdi
leaq 0x40(%rsp), %rbx
movq %rbx, %rsi
movl $0x6, %edx
callq 0x2b03f
movl %eax, %r13d
movq %r15, %r12
jmp 0x1ae01
cmpl $0x2, %r13d
jl 0x1abfa
movq 0x48(%rsp), %rdi
movl $0x3d, %esi
callq 0x6270
testq %rax, %rax
jne 0x1ab02
cmpb $0x41, (%rbp)
jne 0x1adef
movq 0x48(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x1adef
movq 0x50(%rsp), %rax
cmpb $0x47, (%rax)
jne 0x1adef
movq 0x58(%rsp), %rax
cmpb $0x54, (%rax)
jne 0x1adef
xorl %r12d, %r12d
movq %r14, %rdi
movq %rbx, %rsi
movl $0x6, %edx
callq 0x2b03f
movl %eax, %ebx
testl %eax, %eax
jne 0x1ac59
movq 0x8(%r14), %rsi
leaq 0x73e73(%rip), %rdi     # 0x8eac5
xorl %eax, %eax
callq 0x26b6f
xorl %ebp, %ebp
movl %ebx, 0x1c(%rsp)
cmpl $0x5, %ebx
sete %bpl
leaq 0x4(%rbp), %rbx
leaq 0x73e7f(%rip), %r15     # 0x8eaf0
movq %r14, %r13
movq 0x38(%rsp), %r14
movq %r13, %rdi
leaq 0x40(%rsp), %rsi
movl %ebp, %edx
callq 0x2b2eb
leaq 0x73e61(%rip), %rcx     # 0x8eaf0
movslq (%rcx,%r12,4), %rcx
movslq (%r15), %rdx
shlq $0xa, %rcx
addq %r14, %rcx
movl %eax, (%rcx,%rdx,4)
incq %rbp
addq $0x4, %r15
cmpq %rbp, %rbx
jne 0x1ac79
incq %r12
cmpq $0x4, %r12
leaq 0x40(%rsp), %rbx
movq %r13, %r14
jne 0x1ac31
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
xorl %edx, %edx
callq 0x2a455
testl %eax, %eax
je 0x1ae0e
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rdx
leaq 0x73c0a(%rip), %rsi     # 0x8e8f3
xorl %eax, %eax
callq 0x2656a
movq 0x30(%rsp), %rdi
leaq 0x73c25(%rip), %rsi     # 0x8e921
leaq 0x70(%rsp), %rdx
movl $0x20, %ecx
callq 0x22314
cmpl $0x2, %eax
movl 0x1c(%rsp), %r13d
jl 0x1ad8b
decl %eax
movslq %eax, %r15
xorl %r12d, %r12d
movq 0x70(%rsp,%r12,8), %rbp
movq %rbp, %rdi
leaq 0x73bc2(%rip), %rsi     # 0x8e8ee
callq 0x6a50
testl %eax, %eax
jne 0x1ad52
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movq 0x8(%rsp), %rcx
movl %eax, 0x40008(%rcx)
movl $0x1, 0x14(%rsp)
movq %rbp, %rdi
leaq 0x7b926(%rip), %rsi     # 0x96682
callq 0x6a50
testl %eax, %eax
jne 0x1ad82
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movq 0x8(%rsp), %rcx
movl %eax, 0x4000c(%rcx)
movl $0x1, 0x18(%rsp)
addq $0x2, %r12
cmpq %r15, %r12
jl 0x1ad1d
cmpl $0x0, 0x14(%rsp)
setne %al
cmpl $0x0, 0x18(%rsp)
setne %cl
testb %cl, %al
leaq 0x753f5(%rip), %r12     # 0x90199
jne 0x1adb8
movq 0x8(%r14), %rsi
leaq 0x73b75(%rip), %rdi     # 0x8e926
xorl %eax, %eax
callq 0x26b6f
movq 0x8(%rsp), %rax
cmpl $0x0, 0x40008(%rax)
jle 0x1add7
movl $0x1, 0x4(%rsp)
cmpl $0x0, 0x4000c(%rax)
jg 0x1ae01
leaq 0x73b71(%rip), %rdi     # 0x8e94f
xorl %eax, %eax
callq 0x26b6f
movl $0x1, 0x4(%rsp)
jmp 0x1ae01
movq 0x8(%r14), %rsi
leaq 0x73afd(%rip), %rdi     # 0x8e8f7
xorl %eax, %eax
callq 0x26b6f
cmpl $0x0, 0x4(%rsp)
je 0x1aae7
jmp 0x1ae3a
movq 0x8(%rsp), %rax
movabsq $0x1e00000190, %rcx     # imm = 0x1E00000190
movq %rcx, 0x40008(%rax)
movl $0x1, 0x4(%rsp)
leaq 0x75366(%rip), %r12     # 0x90199
movl 0x1c(%rsp), %r13d
jmp 0x1ae01
leaq 0x20(%rsp), %rdi
callq 0x2622c
movq 0x8(%rsp), %rbx
movq %rax, 0x40010(%rbx)
movq %rax, %rdi
callq 0x21b31
cmpb $0x2c, %al
jne 0x1ae68
movq 0x40010(%rbx), %rdi
callq 0x21b54
movq %rbx, %rdi
callq 0x1a366
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq