// File: /workspace/github_c_makefile_star2_O1/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 0x6ec19(%rip), %rsi     # 0xa888f
callq 0x40f0
testq %rax, %rax
je 0x39e78
movq %rax, %rbx
leaq 0x6ec13(%rip), %rsi     # 0xa88a1
movq %r14, %rdi
callq 0x40f0
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x39e78
leaq 0x6ebf6(%rip), %rsi     # 0xa88a1
movq %r15, %rdi
callq 0x40f0
testq %rax, %rax
je 0x39e78
movq %rax, %r15
leaq 0x9c80(%rsp), %rdi
movl $0x1, %esi
movl $0x6ddd0, %edx          # imm = 0x6DDD0
movq %rbx, 0x30(%rsp)
movq %rbx, %rcx
callq 0x4230
movq %rax, %r12
testl %r12d, %r12d
jle 0x39e4b
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl $0x1, %r14d
xorl %r13d, %r13d
xorl %eax, %eax
movb 0x9c80(%rsp,%r13), %cl
cltq
cmpb $0xa, %cl
jne 0x39de3
movb $0x0, 0x1e(%rsp,%rax)
leaq 0x1e(%rsp), %rdi
cmpl $-0x1, %ebx
je 0x39deb
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
callq 0x4130
movsd 0x8(%rsp), %xmm1
movslq %ebx, %rax
movsd %xmm0, 0x40(%rsp,%rax,8)
addsd %xmm0, %xmm1
mulsd %xmm0, %xmm0
addsd 0x10(%rsp), %xmm0
incl %ebx
xorl %eax, %eax
cmpl %ebp, %ebx
jne 0x39e3f
movsd %xmm1, 0x8(%rsp)
testl %r14d, %r14d
movsd %xmm0, 0x10(%rsp)
je 0x39d8b
movq %r15, %rdi
leaq 0x737cd(%rip), %rsi     # 0xad549
movl %ebp, %edx
xorl %eax, %eax
callq 0x42e0
movsd 0x10(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd %xmm1, 0x38(%rsp)
divsd %xmm1, %xmm0
movq 0x28(%rsp), %rdi
leaq 0x6cdc7(%rip), %rsi     # 0xa6b6f
movb $0x1, %al
callq 0x42e0
movsd 0x8(%rsp), %xmm2
divsd 0x38(%rsp), %xmm2
testl %ebp, %ebp
jle 0x39e00
movl %ebp, %eax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movsd 0x40(%rsp,%rcx,8), %xmm1
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
cmpq %rcx, %rax
jne 0x39dc7
jmp 0x39e04
movb %cl, 0x1e(%rsp,%rax)
incl %eax
jmp 0x39e3f
callq 0x4200
movl %eax, %ebp
xorl %eax, %eax
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
jmp 0x39e3f
xorpd %xmm0, %xmm0
leal -0x1(%rbp), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movq %r15, %rdi
leaq 0x6cd53(%rip), %rsi     # 0xa6b6f
movb $0x1, %al
movsd %xmm2, 0x8(%rsp)
callq 0x42e0
movsd 0x8(%rsp), %xmm1
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %eax, %eax
xorl %r14d, %r14d
movsd 0x10(%rsp), %xmm0
incq %r13
cmpq %r12, %r13
jne 0x39d01
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
addq $0x77a58, %rsp          # imm = 0x77A58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop