// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl $0x0, -0x15c(%rbp)
movl $0x0, -0x160(%rbp)
movl $0x40018, %edi          # imm = 0x40018
callq 0x40c50
movq %rax, -0x158(%rbp)
movq -0x158(%rbp), %rax
movq $0x0, 0x40010(%rax)
movl $0x80, %edi
callq 0x35020
movq %rax, -0x168(%rbp)
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x6, %edx
callq 0x3c920
movl %eax, -0x16c(%rbp)
cmpl $0x0, -0x16c(%rbp)
jne 0x22761
movq -0x8(%rbp), %rdi
callq 0x22c50
movl $0x0, -0x170(%rbp)
cmpl $0x0, -0x170(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x22780
jmp 0x22bd9
movq -0x40(%rbp), %rdi
leaq 0xb76b4(%rip), %rsi     # 0xd9e3f
callq 0x6170
cmpq $0x0, %rax
jne 0x227bd
cmpl $0x1, -0x16c(%rbp)
jle 0x228d7
movq -0x38(%rbp), %rdi
leaq 0xb7691(%rip), %rsi     # 0xd9e3f
callq 0x6170
cmpq $0x0, %rax
je 0x228d7
movl $0x80, %edi
callq 0x35020
movq %rax, -0x178(%rbp)
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x16c(%rbp), %eax
jge 0x22818
movq -0x178(%rbp), %rdi
movslq -0x144(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdx
leaq 0xb7811(%rip), %rsi     # 0xda011
movb $0x0, %al
callq 0x35540
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x227d8
leaq -0x178(%rbp), %rdi
callq 0x350c0
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
movl $0x23, %esi
callq 0x30070
movq -0x180(%rbp), %rdi
leaq -0x140(%rbp), %rdx
leaq 0xb75ee(%rip), %rsi     # 0xd9e3f
movl $0x20, %ecx
callq 0x2e840
movq -0x140(%rbp), %rdi
leaq 0xb5f9b(%rip), %rsi     # 0xd8804
callq 0x6a40
cmpl $0x0, %eax
je 0x228ae
movq -0x140(%rbp), %rdi
leaq 0xbdd8e(%rip), %rsi     # 0xe060f
callq 0x6a40
cmpl $0x0, %eax
je 0x228ae
movq -0x168(%rbp), %rdi
movq -0x140(%rbp), %rdx
movq -0x138(%rbp), %rcx
leaq 0xb5f5f(%rip), %rsi     # 0xd8806
movb $0x0, %al
callq 0x35540
movq -0x180(%rbp), %rdi
callq 0x40d40
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x6, %edx
callq 0x3c920
movl %eax, -0x16c(%rbp)
jmp 0x22bd4
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x41, %eax
jne 0x22907
movq -0x38(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x43, %eax
jne 0x22907
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x47, %eax
jne 0x22907
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x54, %eax
je 0x22922
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xb5ef7(%rip), %rdi     # 0xd880d
movb $0x0, %al
callq 0x35d40
jmp 0x22bd2
movl $0x0, -0x144(%rbp)
cmpl $0x4, -0x144(%rbp)
jge 0x22a20
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl $0x6, %edx
callq 0x3c920
movl %eax, -0x16c(%rbp)
cmpl $0x0, -0x16c(%rbp)
jne 0x22963
movq -0x8(%rbp), %rdi
callq 0x22c50
movl $0x0, -0x184(%rbp)
movl $0x5, %eax
cmpl -0x16c(%rbp), %eax
jne 0x22984
movl $0x1, -0x184(%rbp)
movl -0x184(%rbp), %eax
movl %eax, -0x148(%rbp)
movl -0x148(%rbp), %eax
movl -0x184(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x22a0a
movq -0x8(%rbp), %rdi
leaq -0x40(%rbp), %rsi
movl -0x148(%rbp), %edx
callq 0x3cc60
movl %eax, %edx
movq -0x158(%rbp), %rax
addq $0x8, %rax
movslq -0x144(%rbp), %rsi
leaq 0xe3cdf(%rip), %rcx     # 0x1066b0
movslq (%rcx,%rsi,4), %rcx
shlq $0xa, %rcx
addq %rcx, %rax
movl -0x148(%rbp), %ecx
subl -0x184(%rbp), %ecx
movslq %ecx, %rsi
leaq 0xe3cbe(%rip), %rcx     # 0x1066b0
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x22990
jmp 0x22a0c
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x2292c
movq -0x8(%rbp), %rdi
leaq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x3b660
cmpl $0x0, %eax
je 0x22ba6
movq -0x168(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0xb5dbd(%rip), %rsi     # 0xd8809
movb $0x0, %al
callq 0x35540
movq -0x10(%rbp), %rdi
leaq -0x140(%rbp), %rdx
leaq 0xb5dd2(%rip), %rsi     # 0xd8837
movl $0x20, %ecx
callq 0x2e840
movl %eax, -0x14c(%rbp)
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
movl -0x14c(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x22b4e
movslq -0x144(%rbp), %rax
movq -0x140(%rbp,%rax,8), %rdi
leaq 0xb5d58(%rip), %rsi     # 0xd8804
callq 0x6a40
cmpl $0x0, %eax
jne 0x22ae7
movl $0x1, -0x15c(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
cltq
movq -0x140(%rbp,%rax,8), %rdi
callq 0x6bd0
movl %eax, %ecx
movq -0x158(%rbp), %rax
movl %ecx, 0x40008(%rax)
movslq -0x144(%rbp), %rax
movq -0x140(%rbp,%rax,8), %rdi
leaq 0xbdb12(%rip), %rsi     # 0xe060f
callq 0x6a40
cmpl $0x0, %eax
jne 0x22b38
movl $0x1, -0x160(%rbp)
movl -0x144(%rbp), %eax
addl $0x1, %eax
cltq
movq -0x140(%rbp,%rax,8), %rdi
callq 0x6bd0
movl %eax, %ecx
movq -0x158(%rbp), %rax
movl %ecx, 0x4000c(%rax)
jmp 0x22b3a
movl -0x144(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x144(%rbp)
jmp 0x22a7f
cmpl $0x0, -0x15c(%rbp)
je 0x22b60
cmpl $0x0, -0x160(%rbp)
jne 0x22b76
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
leaq 0xb5ccd(%rip), %rdi     # 0xd883c
movb $0x0, %al
callq 0x35d40
movq -0x158(%rbp), %rax
cmpl $0x0, 0x40008(%rax)
jle 0x22b96
movq -0x158(%rbp), %rax
cmpl $0x0, 0x4000c(%rax)
jg 0x22ba4
leaq 0xb5cc8(%rip), %rdi     # 0xd8865
movb $0x0, %al
callq 0x35d40
jmp 0x22bc8
movq -0x158(%rbp), %rax
movl $0x190, 0x40008(%rax)   # imm = 0x190
movq -0x158(%rbp), %rax
movl $0x1e, 0x4000c(%rax)
movl $0x1, -0x170(%rbp)
jmp 0x22bd4
jmp 0x2276b
leaq -0x168(%rbp), %rdi
callq 0x350c0
movq %rax, %rcx
movq -0x158(%rbp), %rax
movq %rcx, 0x40010(%rax)
movq -0x158(%rbp), %rax
movq 0x40010(%rax), %rdi
callq 0x2da10
movsbl %al, %ecx
movl $0x2c, %eax
cmpl %ecx, %eax
jne 0x22c28
movq -0x158(%rbp), %rax
movq 0x40010(%rax), %rdi
callq 0x2da60
movq -0x158(%rbp), %rdi
callq 0x21b70
movq -0x158(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)