// File: /workspace/github_c_makefile_star2_O2/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 0x28bb0
movq %rax, %rbp
andq $0x0, 0x40010(%rax)
movl $0x80, %edi
callq 0x21bcc
movq %rax, 0x18(%rsp)
movq %rax, 0x38(%rsp)
leaq 0x40(%rsp), %rsi
pushq $0x6
popq %rdx
movq %r14, %rdi
callq 0x2619f
movl %eax, %r13d
testl %eax, %eax
jne 0x177dd
movq %r14, %rdi
callq 0x17b32
movq %rbp, 0x8(%rsp)
addq $0x8, %rbp
movb $0x1, %r15b
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
testb $0x1, %r15b
je 0x17ae7
pushq $0x3d
popq %rbx
leaq 0x660e0(%rip), %r15     # 0x7d8ed
movq 0x40(%rsp), %r12
movq %r12, %rdi
movl %ebx, %esi
callq 0x6270
testq %rax, %rax
jne 0x17871
cmpl $0x2, %r13d
jl 0x17838
movq 0x48(%rsp), %rdi
movl %ebx, %esi
callq 0x6270
testq %rax, %rax
jne 0x17871
cmpb $0x41, (%r12)
jne 0x17861
movq 0x48(%rsp), %rax
cmpb $0x43, (%rax)
jne 0x17861
movq 0x50(%rsp), %rax
cmpb $0x47, (%rax)
jne 0x17861
movq 0x58(%rsp), %rax
cmpb $0x54, (%rax)
je 0x17935
movq 0x8(%r14), %rsi
movq %r15, %rdi
xorl %eax, %eax
callq 0x223fb
jmp 0x1780d
movl $0x80, %edi
callq 0x21bcc
movq %rax, 0x20(%rsp)
testl %r13d, %r13d
movl $0x0, %eax
cmovlel %eax, %r13d
xorl %ebx, %ebx
leaq 0x678f4(%rip), %r15     # 0x7f189
cmpq %rbx, %r13
je 0x178b3
movq 0x20(%rsp), %rdi
movq 0x40(%rsp,%rbx,8), %rdx
movq %r15, %rsi
xorl %eax, %eax
callq 0x21ec7
incq %rbx
jmp 0x17895
leaq 0x20(%rsp), %rdi
callq 0x21c26
movq %rax, %r13
movq %rax, %rdi
pushq $0x23
popq %rsi
callq 0x1f248
movq %r13, %rdi
leaq 0x676e2(%rip), %rsi     # 0x7efb7
leaq 0x70(%rsp), %rdx
pushq $0x20
popq %rcx
callq 0x1e51d
movq 0x70(%rsp), %rdx
movzbl (%rdx), %eax
cmpl $0x45, %eax
je 0x178f4
cmpl $0x4f, %eax
jne 0x178fa
cmpb $0x0, 0x1(%rdx)
je 0x17912
movq 0x78(%rsp), %rcx
movq 0x18(%rsp), %rdi
leaq 0x65fdb(%rip), %rsi     # 0x7d8e6
xorl %eax, %eax
callq 0x21ec7
movq %r13, %rdi
callq 0x28c2d
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
pushq $0x6
popq %rdx
callq 0x2619f
movl %eax, %r13d
movb $0x1, %r15b
jmp 0x177f9
xorl %r15d, %r15d
movq %r14, %rdi
cmpq $0x4, %r15
je 0x179b8
leaq 0x40(%rsp), %rsi
pushq $0x6
popq %rdx
callq 0x2619f
movl %eax, %ebx
testl %eax, %eax
jne 0x1795c
movq %r14, %rdi
callq 0x17b32
xorl %r12d, %r12d
movq %rbx, 0x30(%rsp)
cmpl $0x5, %ebx
sete %r12b
leaq 0x4(%r12), %rbx
leaq 0x66169(%rip), %r13     # 0x7dae0
cmpq %r12, %rbx
je 0x179ae
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
movl %r12d, %edx
callq 0x263ca
leaq 0x6614d(%rip), %rcx     # 0x7dae0
movslq (%rcx,%r15,4), %rcx
movslq (%r13), %rdx
shlq $0xa, %rcx
addq %rbp, %rcx
movl %eax, (%rcx,%rdx,4)
incq %r12
addq $0x4, %r13
jmp 0x17977
incq %r15
movq 0x30(%rsp), %r13
jmp 0x17938
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x256a7
testl %eax, %eax
jne 0x179e6
movq 0x8(%rsp), %rax
movabsq $0x1e00000190, %rcx     # imm = 0x1E00000190
movq %rcx, 0x40008(%rax)
xorl %r15d, %r15d
jmp 0x177f9
movq 0x28(%rsp), %rdx
movq 0x18(%rsp), %rdi
leaq 0x65ef2(%rip), %rsi     # 0x7d8e9
xorl %eax, %eax
callq 0x21ec7
movq 0x28(%rsp), %rdi
leaq 0x65f0d(%rip), %rsi     # 0x7d917
leaq 0x70(%rsp), %rdx
pushq $0x20
popq %rcx
callq 0x1e51d
decl %eax
movslq %eax, %rcx
xorl %r12d, %r12d
movq %rcx, %r15
cmpq %rcx, %r12
jge 0x17a88
movq 0x70(%rsp,%r12,8), %rbx
movb (%rbx), %al
cmpb $0x4f, %al
jne 0x17a59
cmpb $0x0, 0x1(%rbx)
jne 0x17a82
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movq 0x8(%rsp), %rcx
movl %eax, 0x40008(%rcx)
movb (%rbx), %al
pushq $0x1
popq %rcx
movl %ecx, 0x14(%rsp)
movq %r15, %rcx
cmpb $0x45, %al
jne 0x17a82
cmpb $0x0, 0x1(%rbx)
jne 0x17a82
movq 0x78(%rsp,%r12,8), %rdi
callq 0x6bd0
movq %r15, %rcx
movq 0x8(%rsp), %rdx
movl %eax, 0x4000c(%rdx)
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
addq $0x2, %r12
jmp 0x17a22
cmpl $0x0, 0x14(%rsp)
setne %al
cmpl $0x0, 0x10(%rsp)
setne %cl
testb %cl, %al
jne 0x17aae
movq 0x8(%r14), %rsi
leaq 0x65e75(%rip), %rdi     # 0x7d91c
xorl %eax, %eax
callq 0x223fb
movq 0x8(%rsp), %rax
cmpl $0x0, 0x40008(%rax)
jle 0x17ad1
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
cmpl $0x0, 0x4000c(%rax)
jg 0x177f9
xorl %r15d, %r15d
leaq 0x65e6a(%rip), %rdi     # 0x7d945
xorl %eax, %eax
callq 0x223fb
jmp 0x177f9
leaq 0x38(%rsp), %rdi
callq 0x21c26
movq 0x8(%rsp), %rbx
movq %rax, 0x40010(%rbx)
movq %rax, %rdi
callq 0x1de53
cmpb $0x2c, %al
jne 0x17b15
movq 0x40010(%rbx), %rdi
callq 0x1de76
movq %rbx, %rdi
callq 0x170db
movq %rbx, %rax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq