// File: /workspace/github_cpp_makefile_star2_O1/nanjiangshu[P]calSOV/calSOV.cpp
// Function: ReadInSecPredFile(char const*, char*, char*, char*, double*, int, int)
int ReadInSecPredFile(const char *infile, char *aaSeq, char *obsSec, char *predSec, double *predConf, int typeConfidence, int fileFormat)/*{{{*/
{
    int linesize;
    int maxline = 400;
    Array1D <char> line_1darray(maxline+1);
    char *line = line_1darray.array1D;
    char aa;
    char obs_sec;
    char pred_sec;
    int status_sscanf = 0;

    int seqLength = 0;
    FILE *fp = fopen(infile, "r");
    checkfilestream(fp, infile, "r", true);

    if (fileFormat == 0) /*Res file format*//*{{{*/
    {
        int num ; 
        char shape;
        int probH;
        int probS;
        int probR;
        int predHSRstate = 0; /*predicted HSR state, 0 -- H, 1 -- S, 2 -- R*/
        int cntRes = 0;
        while((linesize=fgetline(fp, line, maxline)) != EOF)
        { 
            status_sscanf = sscanf(line,"%d %c %c %c %d %d %d" , &num,&aa,&shape, &obs_sec,&probH,&probS,&probR);
            if (status_sscanf != 7)
            {
                fprintf(stderr,"sscanf error!");
                fprintf(stderr,"File: %s\n", infile);
                fprintf(stderr,"line: %s\n", line);
                assert (status_sscanf == 7);
            }
            predHSRstate = GetHSRState(probH, probS, probR, method_HSR);

            aaSeq[cntRes] = aa;
            obsSec[cntRes] = obs_sec;
            predSec[cntRes] = HSRalphabet[predHSRstate];
            if (typeConfidence == 0) /*Raw confidence*/
            {
                predConf[cntRes] = GetRawHSRConfidence(probH, probS, probR);
            }
            else 
            {
                predConf[cntRes] = GetNormHSRConfidence(probH, probS, probR);
            }

            cntRes ++;
        } 
        seqLength = cntRes;
    }/*}}}*/
    else if (fileFormat == 1) /*AA OSEC PSEC NUM*//*{{{*/
    {
        /*AA OSEC PSEC NUM*/
        linesize=fgetline(fp,line,maxline); /*neglect the header line*/
        int cntRes = 0;
        while((linesize=fgetline(fp, line, maxline)) != EOF)
        { 
            status_sscanf = sscanf(line," %c %c %c" , &aa,&obs_sec,&pred_sec);
            if (status_sscanf != 3)
            {
                fprintf(stderr,"sscanf error!");
                fprintf(stderr,"File: %s\n", infile);
                fprintf(stderr,"line: %s\n", line);
                assert (status_sscanf == 3);
            }
            if (obs_sec == 'E' ) { obs_sec = 'S'; }
            else if (obs_sec == 'C' || obs_sec == 'L') { obs_sec = 'R'; }

            if (pred_sec == 'E' ) { pred_sec = 'S'; }
            else if (pred_sec == 'C' || pred_sec == 'L') { pred_sec = 'R'; }

            aaSeq[cntRes] = aa;
            obsSec[cntRes] = obs_sec;
            predSec[cntRes] = pred_sec;
#ifdef DEBUG
            fprintf(stdout, "line=%s\n", line);
            fprintf(stdout, "cntRes=%d\n", cntRes);
#endif
            cntRes ++;
            if (cntRes >= maxSeqLength){
                fprintf(stdout,"Number of residues in the input file exceeds the maxSeqLength (%d). Please check your input file. Exit.\n", maxSeqLength);
                assert(cntRes<maxSeqLength);
            }
        } 
        seqLength = cntRes;
    }/*}}}*/
    else if (fileFormat == 2) /*Fasta format >AA, >OSEC, >PSEC*//*{{{*/
    {
        int maxSizeAnno = 100;
        Array1D <char> anno_1darray(maxSizeAnno+1);
        Array1D <char> tmpSeq_1darray(maxSeqLength+1);
        char *tmpSeq = tmpSeq_1darray.array1D;
        char *anno = anno_1darray.array1D;
        int seqlength = 0;
        /*>AA >OSEC >PSEC*/
        int cntSeq = 0;
        while((seqlength = ReadNextSeq_FASTA(fp, tmpSeq, NULL, maxSeqLength, anno, maxSizeAnno))!= EOF)
        {
            if(strstr(anno, "AA") != NULL){
                my_strcpy(aaSeq,tmpSeq, maxSeqLength-1);
            }else if(strstr(anno, "OSEC") != NULL){
                my_strcpy(obsSec,tmpSeq, maxSeqLength-1);
            }else if(strstr(anno, "PSEC") != NULL){
                my_strcpy(predSec,tmpSeq, maxSeqLength-1);
            }
            cntSeq ++;
            if (cntSeq>3){
                fprintf(stderr, "You input file contains more than 3 sequences. Please check the format of your input file\n");
                assert(cntSeq<=3);
            }
        }
        int i = 0;
        seqlength = strlen(obsSec);
        for (i = 0; i<seqlength; i++){
            if (obsSec[i] == 'E' ) { obsSec[i] = 'S'; }
            else if (obsSec[i] == 'C' || obsSec[i] == 'L') { obsSec[i] = 'R'; }
        }

        seqlength = strlen(predSec);
        for (i = 0; i<seqlength; i++){
            if (predSec[i]  == 'E' ) { predSec[i] = 'S'; }
            else if (predSec[i]  == 'C' || predSec[i]  == 'L') { predSec[i]  = 'R'; }
        }
        seqLength = strlen(aaSeq);
    }/*}}}*/
    if (fp != NULL) { fclose(fp); }
    return seqLength;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, 0x8(%rsp)
movq %r8, 0x48(%rsp)
movq %rcx, %r13
movq %rdx, 0x10(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r15
movl 0x90(%rsp), %ebp
movl $0x191, %edi            # imm = 0x191
callq 0x2030
movq %rax, %r12
leaq 0x4c09(%rip), %rbx      # 0x7a7e
movq %r15, %rdi
movq %rbx, %rsi
callq 0x21e0
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl $0x1, %ecx
callq 0x2cf4
cmpl $0x2, %ebp
movq %r12, 0x20(%rsp)
je 0x30f2
movq %r15, 0x40(%rsp)
xorl %r15d, %r15d
cmpl $0x1, %ebp
je 0x2fd8
testl %ebp, %ebp
jne 0x32fd
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c50
xorl %r15d, %r15d
cmpl $-0x1, %eax
je 0x32fd
subq $0x8, %rsp
movq %r12, %rdi
leaq 0x494b(%rip), %rsi      # 0x7832
leaq 0x5c(%rsp), %rdx
leaq 0xf(%rsp), %rcx
leaq 0x27(%rsp), %r8
leaq 0xd(%rsp), %r9
xorl %eax, %eax
leaq 0x3c(%rsp), %r10
pushq %r10
leaq 0x48(%rsp), %r10
pushq %r10
leaq 0x54(%rsp), %r10
pushq %r10
callq 0x2150
addq $0x20, %rsp
cmpl $0x7, %eax
jne 0x3324
movl 0x3c(%rsp), %r12d
movl 0x38(%rsp), %ebx
movl 0x34(%rsp), %ebp
movl 0x8229(%rip), %ecx      # 0xb160
movl %r12d, %edi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2dba
movb 0x7(%rsp), %cl
movq 0x28(%rsp), %rdx
movb %cl, (%rdx,%r15)
movb 0x5(%rsp), %cl
movq 0x10(%rsp), %rdx
movb %cl, (%rdx,%r15)
movl %eax, %eax
leaq 0x81fe(%rip), %rcx      # 0xb164
movb (%rax,%rcx), %al
movb %al, (%r13,%r15)
cmpl $0x0, 0x8(%rsp)
je 0x2f87
movl %r12d, %edi
movl %ebx, %esi
movl %ebp, %edx
callq 0x2d3b
cvtss2sd %xmm0, %xmm0
jmp 0x2fb0
leal (%rbx,%r12), %eax
addl %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
cmpl %ebx, %r12d
cmovgl %r12d, %ebx
cmpl %ebp, %ebx
cmovlel %ebp, %ebx
addsd 0x4060(%rip), %xmm1     # 0x7008
cvtsi2sd %ebx, %xmm0
divsd %xmm1, %xmm0
movq 0x48(%rsp), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
movq %r14, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c50
jmp 0x2ed0
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c50
movq %r14, %rdi
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c50
cmpl $-0x1, %eax
je 0x32fd
leaq 0x5(%rsp), %rbx
leaq 0x6(%rsp), %rbp
xorl %r15d, %r15d
movq %r12, %rdi
leaq 0x48b4(%rip), %rsi      # 0x78cc
leaq 0x7(%rsp), %rdx
movq %rbx, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x2150
cmpl $0x3, %eax
jne 0x3333
movzbl 0x5(%rsp), %eax
cmpl $0x43, %eax
je 0x304e
cmpl $0x4c, %eax
je 0x304e
cmpl $0x45, %eax
jne 0x3053
movb $0x53, 0x5(%rsp)
jmp 0x3053
movb $0x52, 0x5(%rsp)
movzbl 0x6(%rsp), %eax
cmpl $0x43, %eax
je 0x306e
cmpl $0x4c, %eax
je 0x306e
cmpl $0x45, %eax
jne 0x3073
movb $0x53, 0x6(%rsp)
jmp 0x3073
movb $0x52, 0x6(%rsp)
movb 0x7(%rsp), %al
movq 0x28(%rsp), %rcx
movb %al, (%rcx,%r15)
movb 0x5(%rsp), %al
movq 0x10(%rsp), %rcx
movb %al, (%rcx,%r15)
movb 0x6(%rsp), %al
movb %al, (%r13,%r15)
movl 0x80dc(%rip), %edx      # 0xb178
leal 0x1(%r15), %eax
cmpl %eax, %edx
jg 0x30cc
movq 0x7f15(%rip), %rax      # 0xafc0
movq (%rax), %rdi
leaq 0x4834(%rip), %rsi      # 0x78e9
xorl %eax, %eax
callq 0x2240
leal 0x1(%r15), %eax
cmpl %eax, 0x80b2(%rip)      # 0xb178
jle 0x3342
movq %r14, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rsi
movl $0x190, %edx            # imm = 0x190
callq 0x2c50
incq %r15
cmpl $-0x1, %eax
jne 0x300e
jmp 0x32fd
movl $0x65, %edi
callq 0x2030
movq %rax, %rbp
movl 0x8073(%rip), %edi      # 0xb178
incl %edi
callq 0x2030
movq %rax, 0x8(%rsp)
movl $0x4, %r12d
movl 0x805b(%rip), %ecx      # 0xb178
movq %r14, %rdi
movq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %rbp, %r8
movl $0x64, %r9d
callq 0x2ab8
cmpl $-0x1, %eax
je 0x325b
movq %rbp, %rdi
leaq 0x481e(%rip), %rsi      # 0x7966
callq 0x20a0
testq %rax, %rax
je 0x3182
movq %r13, %rbx
movq %r14, %r13
movslq 0x8019(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x31c0
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x31d5
movq %rbp, %rdi
leaq 0x47dd(%rip), %rsi      # 0x7969
callq 0x20a0
testq %rax, %rax
je 0x31e0
movslq 0x7fdb(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x3219
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x322e
movl %r15d, %edx
movq 0x28(%rsp), %r14
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq 0x2130
movq %r14, %rax
movq %r13, %r14
movq %rbx, %r13
jmp 0x3246
movq %rbp, %rdi
leaq 0x4784(%rip), %rsi      # 0x796e
callq 0x20a0
testq %rax, %rax
je 0x324d
movslq 0x7f7d(%rip), %rax      # 0xb178
leaq -0x1(%rax), %r15
cmpq $0xc8, %rax
jg 0x3233
movq %r13, %rdi
movq 0x8(%rsp), %rsi
movq %r15, %rdx
callq 0x20f0
jmp 0x3243
movl %r15d, %edx
movq 0x10(%rsp), %rbx
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x2130
movq %rbx, %rax
jmp 0x3246
movl %r15d, %edx
movq %r13, %rdi
movq 0x8(%rsp), %rsi
callq 0x2130
movq %r13, %rax
movslq %r15d, %rcx
movb $0x0, (%rax,%rcx)
decl %r12d
jne 0x3117
callq 0x22f7
movq 0x10(%rsp), %rdi
callq 0x20e0
testl %eax, %eax
movq 0x20(%rsp), %r12
jle 0x32a3
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movq 0x10(%rsp), %rsi
movq 0x10(%rsp), %rdx
movzbl (%rdx,%rcx), %edx
cmpl $0x4c, %edx
je 0x3292
cmpl $0x45, %edx
je 0x3296
cmpl $0x43, %edx
jne 0x329b
movb $0x52, %dl
jmp 0x3298
movb $0x53, %dl
movb %dl, (%rsi,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x327a
movq %r13, %rdi
callq 0x20e0
testl %eax, %eax
jle 0x32de
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %ecx, %ecx
movzbl (%r13,%rcx), %edx
cmpl $0x4c, %edx
je 0x32cb
cmpl $0x45, %edx
je 0x32cf
cmpl $0x43, %edx
jne 0x32d6
movb $0x52, %dl
jmp 0x32d1
movb $0x53, %dl
movb %dl, (%r13,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x32b6
movq 0x28(%rsp), %rdi
callq 0x20e0
movq %rax, %r15
movq 0x8(%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
testq %r14, %r14
je 0x330a
movq %r14, %rdi
callq 0x2160
movq %r12, %rdi
callq 0x2220
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x23a1
movq 0x40(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x2333
leaq 0x4609(%rip), %rdi      # 0x7952
leaq 0x4499(%rip), %rsi      # 0x77e9
leaq 0x4525(%rip), %rcx      # 0x787c
movl $0x22b, %edx            # imm = 0x22B
callq 0x2110
movq %rax, %r14
jmp 0x3378
movq %rax, %r14
jmp 0x3380
movq %rax, %r14
movq 0x8(%rsp), %rdi
callq 0x2220
movq %rbp, %rdi
callq 0x2220
movq 0x20(%rsp), %rdi
callq 0x2220
movq %r14, %rdi
callq 0x2270