// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/tests.c
// Function: anova
double anova(char **files)
{
 /*Last Changed 02.02.2004 added safemalloc*/
 /*Last Changed 23.04.2001*/
 FILE *myfile;
 int treatments = 0, df1, df2;
 int *counts = NULL, i, j, total = 0;
 double **observations = NULL;
 double *means, overall_mean = 0.0;
 double res, mst, mse, sst = 0.0, sse = 0.0;
 while (files[treatments])
  {
   treatments++;
   counts = alloc(counts, treatments * sizeof(int), treatments);
   observations = alloc(observations, treatments * sizeof(double *), treatments);
   counts[treatments - 1] = file_length(files[treatments - 1]);
   observations[treatments - 1] = (double *)safemalloc(counts[treatments - 1] * sizeof(double), "anova", 13);
   if ((myfile = fopen(files[treatments - 1], "r")) == NULL)
    {
     printf(m1274, files[treatments - 1]);
     return 0;
    }
   for (i = 0; i < counts[treatments - 1]; i++)
     fscanf(myfile, "%lf", &observations[treatments - 1][i]);
   fclose(myfile);
  }
 means = (double *)safecalloc(treatments, sizeof(double), "anova", 23);
 for (i = 0; i < treatments; i++)
  {
   for (j = 0; j < counts[i]; j++)
     means[i] += observations[i][j];
   overall_mean += means[i];
   total += counts[i];
   means[i] /= counts[i];
  }
 overall_mean /= total;
 for (i = 0; i < treatments; i++)
  {
   sst += counts[i] * pow(means[i] - overall_mean, 2);
   for (j = 0; j < counts[i]; j++)
     sse += pow(observations[i][j] - means[i], 2);
  }
 df1 = treatments - 1;
 df2 = total - treatments;
 mst=sst / df1;
 mse=sse / df2;
 free_2d((void**)observations, treatments);
 safe_free(counts);
 safe_free(means);
 res = f_distribution(mst / mse, df1, df2);
 return 1-res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r13
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %ebx, %ebx
movq %rdi, 0x10(%rsp)
cmpq $0x0, (%r13,%r14,8)
je 0x8a453
leaq 0x1(%r14), %rbp
leaq 0x4(,%r14,4), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x34f30
movq %rax, %rbx
leaq 0x8(,%r14,8), %rsi
movq %r15, %rdi
movl %ebp, %edx
callq 0x34f30
movq %rax, %r15
movq (%r13,%r14,8), %rdi
callq 0x33f62
movl %eax, (%rbx,%r14,4)
movslq %eax, %rdi
shlq $0x3, %rdi
leaq 0x173be(%rip), %rsi     # 0xa179f
pushq $0xd
popq %rdx
callq 0x34f59
movq %rax, (%r15,%r14,8)
movq (%r13,%r14,8), %rdi
leaq 0x11486(%rip), %rsi     # 0x9b87f
callq 0x40f0
testq %rax, %rax
je 0x8a5ab
movq %rax, %r12
movq %rbp, (%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq (%rbx,%r14,4), %rax
cmpq %rax, %rbp
jge 0x8a43d
movq (%r15,%r14,8), %rdx
addq %r13, %rdx
movq %r12, %rdi
leaq 0xf77b(%rip), %rsi      # 0x99ba8
xorl %eax, %eax
callq 0x4070
incq %rbp
addq $0x8, %r13
jmp 0x8a413
movq %r12, %rdi
callq 0x42a0
movq (%rsp), %r14
movq 0x10(%rsp), %r13
jmp 0x8a38b
leaq 0x17345(%rip), %rdx     # 0xa179f
pushq $0x8
popq %rsi
pushq $0x17
popq %rcx
movq %r14, %rdi
callq 0x35067
movq %rax, %r12
movl %r14d, %eax
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
xorl %ebp, %ebp
cmpq %rax, %rcx
je 0x8a4c9
movl (%rbx,%rcx,4), %edx
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x8a4aa
movq (%r15,%rcx,8), %r8
movsd (%r8,%rdi,8), %xmm1
addsd (%r12,%rcx,8), %xmm1
movsd %xmm1, (%r12,%rcx,8)
incq %rdi
jmp 0x8a48a
movsd (%r12,%rcx,8), %xmm1
addsd %xmm1, %xmm0
cvtsi2sd %edx, %xmm2
addl %edx, %ebp
divsd %xmm2, %xmm1
movsd %xmm1, (%r12,%rcx,8)
incq %rcx
jmp 0x8a476
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm5, %xmm5
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x8a53e
movl (%rbx,%rcx,4), %edx
movsd (%r12,%rcx,8), %xmm2
movapd %xmm2, %xmm1
subsd %xmm0, %xmm1
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
mulsd %xmm1, %xmm1
movapd %xmm5, %xmm3
unpckhpd %xmm5, %xmm3            # xmm3 = xmm3[1],xmm5[1]
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x8a525
movq (%r15,%rcx,8), %r8
movsd (%r8,%rdi,8), %xmm4
subsd %xmm2, %xmm4
mulsd %xmm4, %xmm4
addsd %xmm4, %xmm3
incq %rdi
jmp 0x8a505
cvtsi2sd %edx, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm5, %xmm2
incq %rcx
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
movapd %xmm2, %xmm5
jmp 0x8a4d7
leal -0x1(%r14), %r13d
subl %r14d, %ebp
movd %ebp, %xmm0
movd %r13d, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm0
divpd %xmm0, %xmm5
movapd %xmm5, (%rsp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x34fc3
movq %rbx, %rdi
callq 0x34ff7
movq %r12, %rdi
callq 0x34ff7
movapd (%rsp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movl %r13d, %edi
movl %ebp, %esi
callq 0x1db37
movapd %xmm0, %xmm1
movsd 0xaf7b(%rip), %xmm0     # 0x95520
subsd %xmm1, %xmm0
jmp 0x8a5c2
movq (%r13,%r14,8), %rsi
leaq 0xbc53(%rip), %rdi      # 0x9620a
xorl %eax, %eax
callq 0x4030
xorpd %xmm0, %xmm0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq