// File: /workspace/github_cpp_makefile_star2_O3/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
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 0x3f1b
leaq 0x7551(%rip), %rax      # 0xb164
movb (%rsi,%rax), %bl
xorl %r14d, %r14d
movq %rdx, %r10
movq %r13, %r11
movq %rdi, %r8
xorl %r12d, %r12d
movq %rsi, 0x60(%rsp)
cmpb %bl, (%rdi,%r14)
jne 0x3c38
incl %r12d
jmp 0x3f06
testl %r12d, %r12d
jle 0x3f03
movl %r12d, %eax
movq %r14, %rcx
subq %rax, %rcx
movq %rcx, 0x68(%rsp)
movl %r14d, %eax
subl %r12d, %eax
cltq
xorl %ecx, %ecx
xorl %ebp, %ebp
cmpb %bl, (%r13,%rax)
jne 0x3c66
incl %ecx
jmp 0x3c78
testl %ecx, %ecx
jle 0x3c76
movslq %ebp, %rbp
movl %ecx, 0x1030(%rsp,%rbp,4)
incl %ebp
xorl %ecx, %ecx
incq %rax
cmpq %r14, %rax
jl 0x3c5b
testl %ecx, %ecx
movq %r10, 0x38(%rsp)
movq %r11, 0x30(%rsp)
jle 0x3c9a
movslq %ebp, %rbp
movl %ecx, 0x1030(%rsp,%rbp,4)
incl %ebp
testl %ebp, %ebp
jle 0x3e12
movq %r8, 0x28(%rsp)
movl %ebp, %r15d
leaq (,%r15,4), %rdx
leaq 0x860(%rsp), %rdi
leaq 0x1030(%rsp), %rsi
callq 0x2130
movdqa 0x3390(%rip), %xmm8     # 0x7060
pcmpeqd %xmm7, %xmm7
movdqa 0x3374(%rip), %xmm6     # 0x7050
leal 0x3(%rbp), %eax
leaq -0x1(%r15), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl $0x2, %eax
shlq $0x4, %rax
pxor %xmm6, %xmm0
xorl %ecx, %ecx
movdqa 0x333e(%rip), %xmm1     # 0x7040
movdqa 0x3326(%rip), %xmm2     # 0x7030
movq 0x20(%rsp), %rdi
movdqa %xmm1, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
movd %xmm3, %edx
notl %edx
testb $0x1, %dl
je 0x3d48
movl %r12d, 0x90(%rsp,%rcx)
pxor %xmm7, %xmm3
pextrw $0x4, %xmm3, %edx
testb $0x1, %dl
je 0x3d5e
movl %r12d, 0x94(%rsp,%rcx)
movdqa %xmm2, %xmm3
pxor %xmm6, %xmm3
movdqa %xmm3, %xmm4
pcmpgtd %xmm0, %xmm4
pcmpeqd %xmm0, %xmm3
pshufd $0xf5, %xmm3, %xmm5     # xmm5 = xmm3[1,1,3,3]
pand %xmm4, %xmm5
pshufd $0xf5, %xmm4, %xmm3     # xmm3 = xmm4[1,1,3,3]
por %xmm5, %xmm3
pxor %xmm7, %xmm3
pextrw $0x0, %xmm3, %edx
testb $0x1, %dl
je 0x3d9a
movl %r12d, 0x98(%rsp,%rcx)
pextrw $0x4, %xmm3, %edx
testb $0x1, %dl
je 0x3dac
movl %r12d, 0x9c(%rsp,%rcx)
paddq %xmm8, %xmm1
paddq %xmm8, %xmm2
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x3d0f
movq 0x68(%rsp), %rax
cmpb %bl, (%r13,%rax)
movq 0x38(%rsp), %r10
movq 0x30(%rsp), %r11
movq 0x28(%rsp), %r9
jne 0x3e3a
testq %rax, %rax
jle 0x3e2a
movl %r14d, %ecx
subl %r12d, %ecx
movl %r14d, %edx
subl %r12d, %edx
leaq -0x1(%rdx), %rsi
xorl %eax, %eax
movl %esi, %r8d
cmpb %bl, (%r13,%r8)
jne 0x3e2c
cmpb %bl, (%rdi,%r8)
je 0x3e2c
incl %eax
decq %rsi
cmpl %eax, %edx
jne 0x3df5
movl %ecx, %eax
jmp 0x3e2c
xorpd %xmm0, %xmm0
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %r10
movq 0x30(%rsp), %r11
jmp 0x3ef2
xorl %eax, %eax
addl %eax, 0x90(%rsp)
addl %eax, 0x860(%rsp)
cmpb %bl, -0x1(%r13,%r14)
jne 0x3e6b
xorl %eax, %eax
cmpb %bl, (%r11,%rax)
jne 0x3e5a
cmpb %bl, (%r9,%rax)
je 0x3e5a
incq %rax
cmpl %eax, %r10d
jne 0x3e43
movl %r10d, %eax
leal -0x1(%rbp), %ecx
addl %eax, 0x90(%rsp,%rcx,4)
addl %eax, 0x860(%rsp,%rcx,4)
movl %r12d, %eax
shrl %eax
pxor %xmm0, %xmm0
xorl %ecx, %ecx
movl 0x90(%rsp,%rcx,4), %esi
movl 0x1030(%rsp,%rcx,4), %edx
xorps %xmm1, %xmm1
cvtsi2sd %esi, %xmm1
subl %edx, %esi
cmpl %esi, %edx
cmovll %edx, %esi
movl 0x860(%rsp,%rcx,4), %r9d
movl %r9d, %r8d
shrl $0x1f, %r8d
addl %r9d, %r8d
sarl %r8d
cmpl %eax, %r8d
cmovgel %eax, %r8d
cmpl %esi, %r8d
cmovgel %esi, %r8d
addl %edx, %r8d
xorps %xmm2, %xmm2
cvtsi2sd %r8d, %xmm2
divsd %xmm1, %xmm2
addsd %xmm2, %xmm0
incq %rcx
cmpq %rcx, %r15
jne 0x3e76
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), %r8
addl %r12d, 0x40(%rsp,%rsi,4)
addsd 0x70(%rsp,%rsi,8), %xmm0
movsd %xmm0, 0x70(%rsp,%rsi,8)
xorl %r12d, %r12d
incq %r14
decq %r10
incq %r8
incq %r11
cmpq %rdx, %r14
jne 0x3c2a
incq %rsi
cmpq $0x3, %rsi
jne 0x3c01
movl 0x1840(%rsp), %r10d
testl %r10d, %r10d
jle 0x3f8f
movl %r10d, %ecx
xorpd %xmm0, %xmm0
xorl %edx, %edx
movsd 0x30c2(%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 0x3f57
jmp 0x3fa4
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 0x304e(%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