// File: 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
movq %rsp, %rbp
subq $0x1840, %rsp           # imm = 0x1840
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movl $0x0, -0x17d4(%rbp)
movb $0x20, -0x17d5(%rbp)
movl $0x0, -0x17dc(%rbp)
movl $0x0, -0x17e0(%rbp)
movl $0x0, -0x17dc(%rbp)
cmpl $0x3, -0x17dc(%rbp)
jge 0x4973
movslq -0x17dc(%rbp), %rax
movl $0x0, -0x17ac(%rbp,%rax,4)
movslq -0x17dc(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, -0x17d0(%rbp,%rax,8)
movl -0x17dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17dc(%rbp)
jmp 0x4934
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17e4(%rbp)
movl $0x0, -0x17d4(%rbp)
cmpl $0x3, -0x17d4(%rbp)
jge 0x4f5c
movl $0x0, -0x17e8(%rbp)
movslq -0x17d4(%rbp), %rcx
leaq 0xe846(%rip), %rax      # 0x131f4
movb (%rax,%rcx), %al
movb %al, -0x17d5(%rbp)
movl $0x0, -0x17dc(%rbp)
movl -0x17dc(%rbp), %eax
cmpl -0x17e4(%rbp), %eax
jge 0x4f46
movq -0x8(%rbp), %rax
movslq -0x17dc(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4a01
movl -0x17e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17e8(%rbp)
jmp 0x4f30
cmpl $0x1, -0x17e8(%rbp)
jl 0x4f26
movl $0x0, -0x17ec(%rbp)
movl $0x0, -0x17f0(%rbp)
movl -0x17dc(%rbp), %eax
subl -0x17e8(%rbp), %eax
movl %eax, -0x17e0(%rbp)
movl -0x17e0(%rbp), %eax
cmpl -0x17dc(%rbp), %eax
jge 0x4ab9
movq -0x10(%rbp), %rax
movslq -0x17e0(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4a6d
movl -0x17f0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17f0(%rbp)
jmp 0x4aa3
cmpl $0x1, -0x17f0(%rbp)
jl 0x4a99
movl -0x17f0(%rbp), %ecx
movslq -0x17ec(%rbp), %rax
movl %ecx, -0x800(%rbp,%rax,4)
movl -0x17ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17ec(%rbp)
movl $0x0, -0x17f0(%rbp)
jmp 0x4aa5
movl -0x17e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17e0(%rbp)
jmp 0x4a34
cmpl $0x1, -0x17f0(%rbp)
jl 0x4ae5
movl -0x17f0(%rbp), %ecx
movslq -0x17ec(%rbp), %rax
movl %ecx, -0x800(%rbp,%rax,4)
movl -0x17ec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17ec(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x17f8(%rbp)
movl $0x0, -0x17fc(%rbp)
movl $0x0, -0x1800(%rbp)
movl -0x17e8(%rbp), %eax
movl %eax, -0x1804(%rbp)
cmpl $0x1, -0x17ec(%rbp)
jl 0x4edc
movl $0x0, -0x17e0(%rbp)
movl -0x17e0(%rbp), %eax
cmpl -0x17ec(%rbp), %eax
jge 0x4b76
movl -0x17e8(%rbp), %ecx
movslq -0x17e0(%rbp), %rax
movl %ecx, -0xfd0(%rbp,%rax,4)
movslq -0x17e0(%rbp), %rax
movl -0x800(%rbp,%rax,4), %ecx
movslq -0x17e0(%rbp), %rax
movl %ecx, -0x17a0(%rbp,%rax,4)
movl -0x17e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17e0(%rbp)
jmp 0x4b27
movq -0x10(%rbp), %rax
movl -0x17dc(%rbp), %ecx
subl -0x17e8(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4c5f
movl -0x17dc(%rbp), %eax
subl -0x17e8(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x17fc(%rbp)
movl $0x0, -0x1800(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x17fc(%rbp)
movb %al, -0x1835(%rbp)
jl 0x4c0f
movq -0x10(%rbp), %rax
movslq -0x17fc(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movsbl -0x17d5(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x1835(%rbp)
jne 0x4c0f
movq -0x8(%rbp), %rax
movslq -0x17fc(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x1835(%rbp)
movb -0x1835(%rbp), %al
testb $0x1, %al
jne 0x4c1b
jmp 0x4c3b
movl -0x1800(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1800(%rbp)
movl -0x17fc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x17fc(%rbp)
jmp 0x4bbb
movl -0xfd0(%rbp), %eax
addl -0x1800(%rbp), %eax
movl %eax, -0xfd0(%rbp)
movl -0x17a0(%rbp), %eax
addl -0x1800(%rbp), %eax
movl %eax, -0x17a0(%rbp)
movq -0x10(%rbp), %rax
movl -0x17dc(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
jne 0x4d74
movl -0x17dc(%rbp), %eax
movl %eax, -0x17fc(%rbp)
movl $0x0, -0x1800(%rbp)
movl -0x17fc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x17e4(%rbp), %ecx
movb %al, -0x1836(%rbp)
jge 0x4cf1
movq -0x10(%rbp), %rax
movslq -0x17fc(%rbp), %rcx
movsbl (%rax,%rcx), %ecx
movsbl -0x17d5(%rbp), %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x1836(%rbp)
jne 0x4cf1
movq -0x8(%rbp), %rax
movslq -0x17fc(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x17d5(%rbp), %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x1836(%rbp)
movb -0x1836(%rbp), %al
testb $0x1, %al
jne 0x4cfd
jmp 0x4d20
movl -0x1800(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1800(%rbp)
movl -0x17fc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17fc(%rbp)
jmp 0x4c98
movl -0x17ec(%rbp), %eax
subl $0x1, %eax
cltq
movl -0xfd0(%rbp,%rax,4), %ecx
addl -0x1800(%rbp), %ecx
movl -0x17ec(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0xfd0(%rbp,%rax,4)
movl -0x17ec(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x17a0(%rbp,%rax,4), %ecx
addl -0x1800(%rbp), %ecx
movl -0x17ec(%rbp), %eax
subl $0x1, %eax
cltq
movl %ecx, -0x17a0(%rbp,%rax,4)
movl $0x0, -0x17e0(%rbp)
movl -0x17e0(%rbp), %eax
cmpl -0x17ec(%rbp), %eax
jge 0x4ead
movslq -0x17e0(%rbp), %rax
movl -0xfd0(%rbp,%rax,4), %eax
movslq -0x17e0(%rbp), %rcx
subl -0x800(%rbp,%rcx,4), %eax
movl %eax, -0x180c(%rbp)
movslq -0x17e0(%rbp), %rax
leaq -0x800(%rbp), %rsi
shlq $0x2, %rax
addq %rax, %rsi
leaq -0x180c(%rbp), %rdi
callq 0x7da0
movl (%rax), %eax
movl %eax, -0x1808(%rbp)
movl -0x17e8(%rbp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x1814(%rbp)
movslq -0x17e0(%rbp), %rax
movl -0x17a0(%rbp,%rax,4), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x1818(%rbp)
leaq -0x1814(%rbp), %rdi
leaq -0x1818(%rbp), %rsi
callq 0x7da0
movl (%rax), %eax
movl %eax, -0x1810(%rbp)
leaq -0x1808(%rbp), %rdi
leaq -0x1810(%rbp), %rsi
callq 0x7da0
movl (%rax), %eax
movl %eax, -0x181c(%rbp)
movslq -0x17e0(%rbp), %rax
movl -0x800(%rbp,%rax,4), %eax
addl -0x181c(%rbp), %eax
cvtsi2sd %eax, %xmm0
movsd 0x81b7(%rip), %xmm1     # 0xd018
mulsd %xmm1, %xmm0
movslq -0x17e0(%rbp), %rax
cvtsi2sdl -0xfd0(%rbp,%rax,4), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x1828(%rbp)
movsd -0x17f8(%rbp), %xmm0
addsd -0x1828(%rbp), %xmm0
movsd %xmm0, -0x17f8(%rbp)
movl -0x17e0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17e0(%rbp)
jmp 0x4d7e
movsd -0x17f8(%rbp), %xmm0
cvtsi2sdl -0x17e8(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x17f8(%rbp)
movl -0x17e8(%rbp), %eax
imull -0x17ec(%rbp), %eax
movl %eax, -0x1804(%rbp)
movslq -0x17d4(%rbp), %rax
movl -0x17ac(%rbp,%rax,4), %ecx
addl -0x1804(%rbp), %ecx
movslq -0x17d4(%rbp), %rax
movl %ecx, -0x17ac(%rbp,%rax,4)
movslq -0x17d4(%rbp), %rax
movsd -0x17d0(%rbp,%rax,8), %xmm0
addsd -0x17f8(%rbp), %xmm0
movslq -0x17d4(%rbp), %rax
movsd %xmm0, -0x17d0(%rbp,%rax,8)
movl $0x0, -0x17e8(%rbp)
jmp 0x4f32
movl -0x17dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17dc(%rbp)
jmp 0x49c1
jmp 0x4f48
movl -0x17d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17d4(%rbp)
jmp 0x4989
xorps %xmm0, %xmm0
movsd %xmm0, -0x1830(%rbp)
movl $0x0, -0x1834(%rbp)
movl $0x0, -0x17dc(%rbp)
movl -0x17dc(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x5054
movslq -0x17dc(%rbp), %rax
movl -0x17ac(%rbp,%rax,4), %edx
movq -0x28(%rbp), %rax
movslq -0x17dc(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x17dc(%rbp), %rax
movsd -0x17d0(%rbp,%rax,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x17dc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq -0x17dc(%rbp), %rax
movsd -0x17d0(%rbp,%rax,8), %xmm0
movslq -0x17dc(%rbp), %rax
cvtsi2sdl -0x17ac(%rbp,%rax,4), %xmm1
movsd 0x801a(%rip), %xmm2     # 0xd008
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0x17dc(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movslq -0x17dc(%rbp), %rax
movl -0x17ac(%rbp,%rax,4), %eax
addl -0x1834(%rbp), %eax
movl %eax, -0x1834(%rbp)
movslq -0x17dc(%rbp), %rax
movsd -0x17d0(%rbp,%rax,8), %xmm0
addsd -0x1830(%rbp), %xmm0
movsd %xmm0, -0x1830(%rbp)
movl -0x17dc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17dc(%rbp)
jmp 0x4f7b
movl -0x1834(%rbp), %edx
movq -0x28(%rbp), %rax
movslq 0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movsd -0x1830(%rbp), %xmm0
movq -0x20(%rbp), %rax
movslq 0x10(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd -0x1830(%rbp), %xmm0
cvtsi2sdl -0x1834(%rbp), %xmm1
movsd 0x7f76(%rip), %xmm2     # 0xd008
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq 0x10(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq 0x10(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addq $0x1840, %rsp           # imm = 0x1840
popq %rbp
retq
nopl (%rax,%rax)