// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/libmisc.c
// Function: find_mse_and_sse
void find_mse_and_sse(char* inname, char* outname1, char* outname2)
{
 /*!Last Changed 18.12.2004*/
 FILE* infile;
 FILE* outfile1, *outfile2;
 char buffer[450000];
 char number[10];
 double numbers[5000], meansum, msesum, ssesum;
 int read, i, j, k, count, totalread, first = 1;
 infile = fopen(inname, "r");
 if (!infile)
   return;
 outfile1 = fopen(outname1, "w");
 if (!outfile1)
   return;
 outfile2 = fopen(outname2, "w");
 if (!outfile2)
   return;
 read = fread(buffer, 1, 450000, infile);
 i = 0;
 j = 0;
 totalread = -1;
 while (i < read)
  {
   if (buffer[i] != 10)
    {
     number[j] = buffer[i];
     j++;
    }
   else
    {
     number[j] = 0;
     j = 0;
     if (totalread == -1)
      {
       count = atoi(number);
       totalread = 0;
       meansum = 0;
       msesum = 0;
      }
     else
      {
       numbers[totalread] = (double) atof(number);
       meansum += numbers[totalread];
       msesum += numbers[totalread] * numbers[totalread];
       totalread++;
       if (totalread == count)
        {
         if (first)
           fprintf(outfile2, "%d\n", count);
         fprintf(outfile1, "%5.4f\n", msesum / count);
         ssesum = 0;
         meansum /= count;
         for (k = 0; k < count; k++)
           ssesum += (numbers[k] - meansum) * (numbers[k] - meansum);
         fprintf(outfile2, "%5.4f\n", ssesum / (count - 1));
         totalread = -1;
         first = 0;
        }
      }   
    }
   i++;
  }
 fclose(infile);
 fclose(outfile1);
 fclose(outfile2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x77a58, %rsp          # imm = 0x77A58
movq %rdx, %r15
movq %rsi, %r14
leaq 0x65e7a(%rip), %rsi     # 0x9b87f
callq 0x40f0
testq %rax, %rax
je 0x35bcc
movq %rax, %rbx
leaq 0x65e74(%rip), %rsi     # 0x9b891
movq %r14, %rdi
callq 0x40f0
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x35bcc
leaq 0x65e57(%rip), %rsi     # 0x9b891
movq %r15, %rdi
callq 0x40f0
testq %rax, %rax
je 0x35bcc
movq %rax, %r15
leaq 0x9c80(%rsp), %rdi
pushq $0x1
popq %rsi
movl $0x6ddd0, %edx          # imm = 0x6DDD0
movq %rbx, 0x30(%rsp)
movq %rbx, %rcx
callq 0x4230
movq %rax, %r12
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
pushq $0x1
popq %r13
pushq $-0x1
popq %r14
xorl %ebx, %ebx
xorl %eax, %eax
cmpq %r12, %rbx
je 0x35bde
movb 0x9c80(%rsp,%rbx), %cl
cltq
cmpb $0xa, %cl
jne 0x35b6f
movb $0x0, 0x1e(%rsp,%rax)
leaq 0x1e(%rsp), %rdi
cmpl $-0x1, %r14d
je 0x35baa
movsd %xmm2, 0x8(%rsp)
callq 0x4130
movsd 0x8(%rsp), %xmm2
movslq %r14d, %rax
movsd %xmm0, 0x40(%rsp,%rax,8)
addsd %xmm0, %xmm2
mulsd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
incl %r14d
xorl %eax, %eax
cmpl %ebp, %r14d
jne 0x35bc4
movsd %xmm2, 0x8(%rsp)
testl %r13d, %r13d
je 0x35b10
movq %r15, %rdi
leaq 0x6aa3e(%rip), %rsi     # 0xa0545
movl %ebp, %edx
xorl %eax, %eax
callq 0x42e0
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd 0x10(%rsp), %xmm0
divsd %xmm1, %xmm0
movq 0x28(%rsp), %rdi
leaq 0x63fd7(%rip), %rsi     # 0x99b07
movb $0x1, %al
callq 0x42e0
movsd 0x8(%rsp), %xmm2
divsd 0x38(%rsp), %xmm2
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x35b77
movsd 0x40(%rsp,%rcx,8), %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
jmp 0x35b53
movb %cl, 0x1e(%rsp,%rax)
incl %eax
jmp 0x35bc4
leal -0x1(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x63f7b(%rip), %rsi     # 0x99b07
movb $0x1, %al
movsd %xmm2, 0x8(%rsp)
callq 0x42e0
movsd 0x8(%rsp), %xmm2
xorl %eax, %eax
pushq $-0x1
popq %r14
xorl %r13d, %r13d
jmp 0x35bc4
callq 0x4200
movl %eax, %ebp
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorpd %xmm2, %xmm2
xorl %r14d, %r14d
incq %rbx
jmp 0x35a83
addq $0x77a58, %rsp          # imm = 0x77A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rdi
callq 0x42a0
movq 0x28(%rsp), %rdi
callq 0x42a0
movq %r15, %rdi
addq $0x77a58, %rsp          # imm = 0x77A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
nop