// File: /workspace/github_cpp_makefile_star2_O1/nanjiangshu[P]calSOV/calSOV.cpp
// Function: CalSOV_obsolete(char*, char*, int, double*, int*, double*, int)
int CalSOV_obsolete(char *obsSec, char *predSec, int seqLength, double *numCorrectHSR, int *numHSR, double *sovHSR, int numState = 3)/*{{{*/
    /*=======================================================================
     * numHSR[4] Helix, Sheet, Coil, All
     * sovHSR[4]
     * numState = 3 by default
     *====================================================================*/
{
    int Min_overlap[500] ;
    int Max_extend[500]  ;
    int LenSeg_pred[500];
    int All_HSRLen[3];
    double All_Sum[3];

    int iterHSRState = 0; /*iterator for the HSR state, H, S and R*/
    char thisHSRstate = ' '; /*current HSR state*/
    int i = 0;
    int j = 0;

    for (i=0;i<3;i++)
    {
        All_HSRLen[i] = 0;
        All_Sum[i] = 0.0; 
    }

    int Length = seqLength +1 ;  /*Here Length is 1 residue longer than seqLength*/
    for (iterHSRState=0; iterHSRState<3; iterHSRState++)//corrsponding to H, S, R
    {
        //for helix
        int HSRLen = 0;/*iterator for secondary structure elements*/
        thisHSRstate = HSRalphabet[iterHSRState];
        for(i=0; i<Length; i++)
        { 
            if (  obsSec[i] == thisHSRstate  )
            {
                HSRLen++;
            }
            else
            { 
                if (  HSRLen >= 1  )
                { 
                    int Num_Segment = 0;//the number of segments in an observed element
                    int SubLen = 0;  /*length of the sub segment*/
                    //Min_overlap[]--the length of overlapping
                    //Mam_extend[] -- the extended length of two segments to be compared
                    for (j=i-HSRLen; j<i; j++)
                    { 
                        if (  predSec[j] == thisHSRstate  )
                        { 
                            SubLen++;
                        } 
                        else
                        { 
                            if (  SubLen >= 1  )
                            {
                                Min_overlap[Num_Segment] = SubLen;
                                Num_Segment++;
                            } 
                            SubLen = 0;
                        } 
                    }
                    if (  SubLen >= 1  )
                    {
                        Min_overlap[Num_Segment] = SubLen;
                        Num_Segment++;
                    }
                    double sum = 0;
                    int beg = 0;
                    int Nextend = 0;
                    int Num_HSRLen = HSRLen;
                    if  (  Num_Segment >= 1  )
                    {
                        for (j=0; j<Num_Segment; j++)
                        {
                            Max_extend[j] = HSRLen;
                            LenSeg_pred[j] = Min_overlap[j];
                        }
                        //for first segment
                        if (  predSec[i-HSRLen] == thisHSRstate  )
                        { 
                            beg = i - HSRLen - 1;
                            Nextend = 0;
                            while (   (beg>=0) && (predSec[beg]==thisHSRstate) && (obsSec[beg]!=thisHSRstate)   )
                            {
                                Nextend++;
                                beg--;
                            }
                            Max_extend[0] = Max_extend[0] + Nextend;
                            LenSeg_pred[0] = LenSeg_pred[0] + Nextend;
                        }
                        //for last segment
                        if (  predSec[i-1] == thisHSRstate  )
                        { 
                            beg = i;
                            Nextend = 0;
                            while (   (beg<Length) && (predSec[beg]==thisHSRstate) && (obsSec[beg]!=thisHSRstate)   )
                            {
                                Nextend++;
                                beg++;
                            }
                            Max_extend[Num_Segment-1] = Max_extend[Num_Segment-1] + Nextend;
                            LenSeg_pred[Num_Segment-1] = LenSeg_pred[Num_Segment-1] + Nextend;
                        }
                        for (j=0; j<Num_Segment; j++)
                        {
                            int Nmin1 = min( (Max_extend[j]-Min_overlap[j]), Min_overlap[j]);
                            int Nmin2 = min( HSRLen/2, LenSeg_pred[j]/2);
                            int Nmin = min(Nmin1, Nmin2);
                            double score_seg =  (Min_overlap[j]+Nmin)*1.0/double(Max_extend[j]) ;
                            sum = sum + score_seg;
                        }
                        sum = sum*HSRLen;
                        Num_HSRLen = HSRLen*Num_Segment;
                    }

                    All_HSRLen[iterHSRState] = All_HSRLen[iterHSRState] + Num_HSRLen;
                    All_Sum[iterHSRState] = All_Sum[iterHSRState] + sum;
                } 
                HSRLen = 0;
            }  
        } 
    }

    double sumOverlap = 0;
    int sumAllRes = 0;
    for (i=0; i<numState; i++)
    {
        numHSR[i] = All_HSRLen[i];
        numCorrectHSR[i] = All_Sum[i];
        sovHSR[i] = All_Sum[i]/double(All_HSRLen[i]+1e-6);
        sumAllRes  += All_HSRLen[i];
        sumOverlap += All_Sum[i];
    }
    numHSR[numState] = sumAllRes;
    numCorrectHSR[numState] = sumOverlap;
    sovHSR[numState] = sumOverlap / double(sumAllRes+1e-6);

    return numHSR[numState];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1808, %rsp           # imm = 0x1808
movq %r9, 0x18(%rsp)
movq %r8, 0x8(%rsp)
movq %rcx, 0x10(%rsp)
movq %rsi, %r13
movq %rdi, %r10
xorl %esi, %esi
movq %rsi, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x70(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x50(%rsp)
incl %edx
movq %rdi, 0x20(%rsp)
movq %rdx, 0x58(%rsp)
cmpl $0x0, 0x50(%rsp)
js 0x3e7c
leaq 0x7515(%rip), %rax      # 0xb164
movb (%rsi,%rax), %bl
xorl %r14d, %r14d
movq %rdx, %r11
movq %r13, %r15
movq %r10, %rdi
xorl %r12d, %r12d
movq %rsi, 0x60(%rsp)
cmpb %bl, (%r10,%r14)
jne 0x3c74
incl %r12d
jmp 0x3e67
testl %r12d, %r12d
jle 0x3e64
movl %r12d, %eax
movq %r14, %r8
subq %rax, %r8
movl %r14d, %eax
subl %r12d, %eax
cltq
xorl %ecx, %ecx
xorl %ebp, %ebp
cmpb %bl, (%r13,%rax)
jne 0x3c9d
incl %ecx
jmp 0x3caf
testl %ecx, %ecx
jle 0x3cad
movslq %ebp, %rbp
movl %ecx, 0x1030(%rsp,%rbp,4)
incl %ebp
xorl %ecx, %ecx
incq %rax
cmpq %r14, %rax
jl 0x3c92
testl %ecx, %ecx
movq %r11, 0x38(%rsp)
movq %r15, 0x30(%rsp)
jle 0x3cd1
movslq %ebp, %rbp
movl %ecx, 0x1030(%rsp,%rbp,4)
incl %ebp
testl %ebp, %ebp
jle 0x3d68
movq %r8, 0x68(%rsp)
movq %rdi, 0x28(%rsp)
movl %ebp, %r15d
leaq (,%r15,4), %rdx
leaq 0x90(%rsp), %rdi
leaq 0x1030(%rsp), %rsi
callq 0x2130
xorl %eax, %eax
movl %r12d, 0x860(%rsp,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x3d05
movq 0x68(%rsp), %rax
cmpb %bl, (%r13,%rax)
movq 0x20(%rsp), %r10
movq 0x38(%rsp), %r11
movq 0x30(%rsp), %r15
movq 0x28(%rsp), %r8
jne 0x3d90
testq %rax, %rax
jle 0x3d80
movl %r14d, %ecx
subl %r12d, %ecx
movl %r14d, %edx
subl %r12d, %edx
leaq -0x1(%rdx), %rsi
xorl %eax, %eax
movl %esi, %edi
cmpb %bl, (%r13,%rdi)
jne 0x3d82
cmpb %bl, (%r10,%rdi)
je 0x3d82
incl %eax
decq %rsi
cmpl %eax, %edx
jne 0x3d4c
movl %ecx, %eax
jmp 0x3d82
xorpd %xmm0, %xmm0
movq 0x20(%rsp), %r10
movq 0x38(%rsp), %r11
movq 0x30(%rsp), %r15
jmp 0x3e53
xorl %eax, %eax
addl %eax, 0x860(%rsp)
addl %eax, 0x90(%rsp)
cmpb %bl, -0x1(%r13,%r14)
jne 0x3dc1
xorl %eax, %eax
cmpb %bl, (%r15,%rax)
jne 0x3db0
cmpb %bl, (%r8,%rax)
je 0x3db0
incq %rax
cmpl %eax, %r11d
jne 0x3d99
movl %r11d, %eax
leal -0x1(%rbp), %ecx
addl %eax, 0x860(%rsp,%rcx,4)
addl %eax, 0x90(%rsp,%rcx,4)
movl %r12d, %eax
shrl %eax
cmpl $0x2, %ebp
movl $0x1, %ecx
cmovgel %ebp, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movl 0x860(%rsp,%rdx,4), %edi
movl 0x1030(%rsp,%rdx,4), %esi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
subl %esi, %edi
cmpl %edi, %esi
cmovll %esi, %edi
movl 0x90(%rsp,%rdx,4), %r8d
movl %r8d, %r9d
shrl $0x1f, %r9d
addl %r8d, %r9d
sarl %r9d
cmpl %eax, %r9d
cmovgel %eax, %r9d
cmpl %edi, %r9d
cmovgel %edi, %r9d
addl %esi, %r9d
xorps %xmm2, %xmm2
cvtsi2sd %r9d, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm0
incq %rdx
cmpq %rdx, %rcx
jne 0x3dd7
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
mulsd %xmm1, %xmm0
imull %r12d, %ebp
movl %ebp, %r12d
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x28(%rsp), %rdi
addl %r12d, 0x40(%rsp,%rsi,4)
addsd 0x70(%rsp,%rsi,8), %xmm0
movsd %xmm0, 0x70(%rsp,%rsi,8)
xorl %r12d, %r12d
incq %r14
decq %r11
incq %rdi
incq %r15
cmpq %rdx, %r14
jne 0x3c66
incq %rsi
cmpq $0x3, %rsi
jne 0x3c3d
movl 0x1840(%rsp), %r10d
testl %r10d, %r10d
jle 0x3ef0
movl %r10d, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd 0x3161(%rip), %xmm1     # 0x7008
xorl %eax, %eax
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
movl 0x40(%rsp,%rdx,4), %esi
movl %esi, (%r9,%rdx,4)
movsd 0x70(%rsp,%rdx,8), %xmm2
xorps %xmm3, %xmm3
cvtsi2sd %esi, %xmm3
movsd %xmm2, (%r8,%rdx,8)
addsd %xmm1, %xmm3
addsd %xmm2, %xmm0
divsd %xmm3, %xmm2
movsd %xmm2, (%rdi,%rdx,8)
addl %esi, %eax
incq %rdx
cmpq %rdx, %rcx
jne 0x3eb8
jmp 0x3f05
xorl %eax, %eax
xorpd %xmm0, %xmm0
movq 0x18(%rsp), %rdi
movq 0x10(%rsp), %r8
movq 0x8(%rsp), %r9
movslq %r10d, %rcx
movl %eax, (%r9,%rcx,4)
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addsd 0x30ed(%rip), %xmm1     # 0x7008
movsd %xmm0, (%r8,%rcx,8)
divsd %xmm1, %xmm0
movsd %xmm0, (%rdi,%rcx,8)
addq $0x1808, %rsp           # imm = 0x1808
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq