// File: nanjiangshu[P]calSOV/calSOV.cpp
// Function: CalQ3(char*, char*, int, int*, int*, double*, int)
int CalQ3(char *obsSec, char *predSec, int seqLength, int *numCorrectHSR, int *numHSR, double *q3HSR, int numState = 3)/*{{{*/
    /*=======================================================================
     * numCorrectHSR[4]
     * numHSR[4] Helix, Sheet, Coil, All
     * q3HSR[4]
     * numState = 3 by default
     *====================================================================*/
{

    int iterHSRState = 0; /*iterator for the HSR state, H, S and R*/
    char thisHSRstate = ' '; /*current HSR state*/
    int i = 0;

    for (i=0;i<=numState; i++)
    {
        numCorrectHSR[i] = 0;
        numHSR[i] = 0;
    }

    for (iterHSRState=0; iterHSRState<3; iterHSRState++)//corrsponding to H, S, R
    {
        thisHSRstate = HSRalphabet[iterHSRState];
        for(i=0; i<seqLength; i++)
        { 
            if (  obsSec[i] == thisHSRstate  )
            {
                numHSR[iterHSRState] ++;
                if (obsSec[i] == predSec[i])
                {
                    numCorrectHSR[iterHSRState] ++;
                }
            }
        } 
    }

    for (i=0; i<numState; i++)
    {   
        q3HSR[i] = numCorrectHSR[i] / double (numHSR[i]+1e-6);
        numCorrectHSR[numState]  += numCorrectHSR[i];
        numHSR[numState]  += numHSR[i];
    }
    q3HSR[numState] = numCorrectHSR[numState] / double (numHSR[numState]+1e-6); 

    return numHSR[numState];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
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, -0x34(%rbp)
movb $0x20, -0x35(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jg 0x5128
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x50f7
movl $0x0, -0x34(%rbp)
cmpl $0x3, -0x34(%rbp)
jge 0x51ca
movslq -0x34(%rbp), %rcx
leaq 0xe0b0(%rip), %rax      # 0x131f4
movb (%rax,%rcx), %al
movb %al, -0x35(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x51ba
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movsbl -0x35(%rbp), %ecx
cmpl %ecx, %eax
jne 0x51ad
movq -0x28(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x51ab
movq -0x20(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x51ad
jmp 0x51af
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5151
jmp 0x51bc
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x512f
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x524d
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movsd 0x7e0d(%rip), %xmm2     # 0xd008
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x20(%rbp), %rax
movslq 0x10(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movslq 0x10(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x51d1
movq -0x20(%rbp), %rax
movslq 0x10(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm0
movq -0x28(%rbp), %rax
movslq 0x10(%rbp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movsd 0x7d99(%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
popq %rbp
retq
nopw %cs:(%rax,%rax)