// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/tests.c
// Function: manova
double manova(char **files)
{
 int i, j, p, L = 0, k, t, v, df1, df2, df3;
 matrix* observations;
 matrix H, E, EH, eigenvectors;
 double **averages;
 double *overallaverage, *eigenvalues, statistic, ratio, res;
 while (files[L])
   L++;
 observations = safemalloc(L * sizeof(matrix), "manova", 5);
 p = read_multivariate_observations_for_multiple_file(files, observations, L);
 k = observations[0].row;
 if (p == -1)
  {
   for (i = 0; i < L; i++)
     matrix_free(observations[i]);
   safe_free(observations);
   return 0;
  }
 averages = safemalloc(L * sizeof(double*), "manova", 11);
 overallaverage = safecalloc(p, sizeof(double), "manova", 12);
 for (i = 0; i < L; i++)
   averages[i] = matrix_average_columns(observations[i]);
 for (i = 0; i < L; i++)
   for (j = 0; j < p; j++)
     overallaverage[j] += averages[i][j];
 for (i = 0; i < p; i++)
   overallaverage[i] /= L;
 H = matrix_alloc(p, p);
 E = matrix_alloc(p, p); 
 for (i = 0; i < L; i++)
   for (j = 0; j < p; j++)
     for (t = 0; t < p; t++)
       H.values[j][t] += (averages[i][j] - overallaverage[j]) * (averages[i][t] - overallaverage[t]);
 matrix_multiply_constant(&H, k);
 safe_free(overallaverage);
 for (i = 0; i < L; i++)
   for (j = 0; j < k; j++)
     for (t = 0; t < p; t++)
       for (v = 0; v < p; v++)
         E.values[t][v] += (observations[i].values[j][t] - averages[i][t]) *  (observations[i].values[j][v] - averages[i][v]);
 for (i = 0; i < L; i++)
  {
   safe_free(averages[i]);
   matrix_free(observations[i]);
  }
 safe_free(observations);
 safe_free(averages);
 EH = matrix_sum(E, H);
 ratio = matrix_determinant(E) / matrix_determinant(EH);
 matrix_inverse(&E);
 matrix_product(&E, H);
 eigenvalues = find_eigenvalues_eigenvectors_symmetric(&eigenvectors, E);
 if (eigenvalues != NULL)
  {
   for (i = 1; i < E.col + 1; i++)
     write_array_variables("aout", i, 1, "f", eigenvalues[i - 1]);
   for (i = 0; i < E.col; i++)
     for (j = 0; j < E.row; j++)
       write_array_variables("aout", j + 1, 2 + i, "f", eigenvectors.values[j][i]);
   safe_free(eigenvalues);
   matrix_free(eigenvectors);
  }
 matrix_free(H);
 matrix_free(E);
 matrix_free(EH);
 df1 = p;
 df2 = L * (k - 1);
 df3 = L - 1;
 statistic = ((df1 + df3 + 1) / 2.0 - (df2 + df3)) * log(ratio);
 res = chi_square(df1 * df3, statistic);
 return 1 - res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq $-0x10, %rdi
movq $-0x8, %r12
xorl %eax, %eax
incl %ebp
addq $0x10, %rdi
addq $0x8, %r12
cmpq $0x0, (%rbx,%rax,8)
leaq 0x1(%rax), %rax
jne 0x988d4
leaq -0x1(%rax), %r15
leaq 0x1944b(%rip), %rsi     # 0xb1d3f
movl $0x5, %edx
movq %rax, %r14
callq 0x3a0e1
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
movl %r15d, %edx
callq 0x9824f
cmpl $-0x1, %eax
je 0x98a4f
movl %ebp, 0x44(%rsp)
movl %eax, %ebx
movq %r13, (%rsp)
movl (%r13), %eax
movq %rax, 0x28(%rsp)
leaq 0x1940a(%rip), %r13     # 0xb1d3f
movq %r12, %rdi
movq %r13, %rsi
movl $0xb, %edx
callq 0x3a0e1
movq %rax, %r12
movslq %ebx, %rdi
movl $0x8, %esi
movq %r13, %rdx
movl $0xc, %ecx
callq 0x3a1fc
movq %rax, %r13
cmpq $0x1, %r14
movq %r14, 0x8(%rsp)
je 0x989ce
movq (%rsp), %rax
leaq 0x8(%rax), %r14
xorl %ebp, %ebp
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3fe12
movq %rax, (%r12,%rbp,8)
incq %rbp
addq $0x10, %r14
cmpq %rbp, %r15
jne 0x98975
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
je 0x989ce
decq %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x989c6
movq (%r12,%rcx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm0
addsd (%r13,%rsi,8), %xmm0
movsd %xmm0, (%r13,%rsi,8)
incq %rsi
cmpq %rsi, %rbx
jne 0x989ab
incq %rcx
cmpq %rcx, %rax
jne 0x989a1
testl %ebx, %ebx
jle 0x989f6
xorps %xmm0, %xmm0
cvtsi2sd %r15d, %xmm0
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x989dc
movl %ebx, %edi
movl %ebx, %esi
callq 0x3d79d
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
movl %ebx, %edi
movl %ebx, %esi
callq 0x3d79d
movq %rdx, %rbp
movq %rax, 0x20(%rsp)
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movq 0x8(%rsp), %rax
cmpq $0x1, %rax
jne 0x98a82
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%rsp), %xmm0
leaq 0x10(%rsp), %rdi
callq 0x3f7c2
movq %r13, %rdi
callq 0x3a180
jmp 0x98bc0
cmpq $0x1, %r14
je 0x98a71
movq %r13, %rbx
addq $0x8, %rbx
movq -0x8(%rbx), %rdi
movq (%rbx), %rsi
callq 0x3ed51
addq $0x10, %rbx
decq %r15
jne 0x98a5c
movq %r13, %rdi
callq 0x3a180
xorpd %xmm0, %xmm0
jmp 0x98dc2
leaq -0x1(%rax), %r14
xorl %eax, %eax
movq 0x28(%rsp), %r9
testl %ebx, %ebx
jle 0x98adc
movq 0x18(%rsp), %rcx
movq (%r12,%rax,8), %rdx
xorl %esi, %esi
movq (%rcx,%rsi,8), %rdi
xorl %r8d, %r8d
movsd (%rdx,%rsi,8), %xmm0
subsd (%r13,%rsi,8), %xmm0
movsd (%rdx,%r8,8), %xmm1
subsd (%r13,%r8,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%rdi,%r8,8), %xmm1
movsd %xmm1, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rbx
jne 0x98aa3
incq %rsi
cmpq %rbx, %rsi
jne 0x98a9c
incq %rax
cmpq %rax, %r14
jne 0x98a8d
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
leaq 0x10(%rsp), %rdi
callq 0x3f7c2
movq %r13, %rdi
callq 0x3a180
cmpq $0x1, 0x8(%rsp)
je 0x98bc0
xorl %eax, %eax
movq 0x28(%rsp), %r11
movq (%rsp), %r13
testl %r11d, %r11d
jle 0x98b84
movq %rax, %rcx
shlq $0x4, %rcx
addq %r13, %rcx
addq $0x8, %rcx
xorl %edx, %edx
testl %ebx, %ebx
jle 0x98b7c
movq (%rcx), %rsi
movq (%rsi,%rdx,8), %rsi
movq (%r12,%rax,8), %rdi
xorl %r8d, %r8d
movq (%rbp,%r8,8), %r9
xorl %r10d, %r10d
movsd (%rsi,%r8,8), %xmm0
subsd (%rdi,%r8,8), %xmm0
movsd (%rsi,%r10,8), %xmm1
subsd (%rdi,%r10,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r9,%r10,8), %xmm1
movsd %xmm1, (%r9,%r10,8)
incq %r10
cmpq %r10, %rbx
jne 0x98b44
incq %r8
cmpq %rbx, %r8
jne 0x98b3c
incq %rdx
cmpq %r11, %rdx
jne 0x98b2a
incq %rax
cmpq %rax, %r14
jne 0x98b15
cmpq $0x1, 0x8(%rsp)
je 0x98bc0
movq (%rsp), %r14
addq $0x8, %r14
xorl %r13d, %r13d
movq (%r12,%r13,8), %rdi
callq 0x3a180
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3ed51
incq %r13
addq $0x10, %r14
cmpq %r13, %r15
jne 0x98b9f
movq (%rsp), %rdi
callq 0x3a180
movq %r12, %rdi
callq 0x3a180
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rcx
movq 0x20(%rsp), %rdi
movq %rbp, %rsi
callq 0x3f9ef
movq %rax, %r15
movq %rdx, %r12
leaq 0x30(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
callq 0x4078e
movsd %xmm0, (%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x4078e
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r14, %rdi
callq 0x409b7
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r14, %rdi
callq 0x3fb95
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x58(%rsp), %rdi
callq 0x428e9
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x98d2e
movq %r12, 0x48(%rsp)
movq %r15, 0x50(%rsp)
cmpl $0x0, 0x34(%rsp)
jle 0x98d0b
xorl %r13d, %r13d
leaq 0xcb3b(%rip), %rbp      # 0xa57b0
leaq 0xf9fd(%rip), %r14      # 0xa8679
movq 0x20(%rsp), %r15
movsd (%r15,%r13,8), %xmm0
incq %r13
movq %rbp, %rdi
movl %r13d, %esi
movl $0x1, %edx
movq %r14, %rcx
movb $0x1, %al
callq 0x33644
movslq 0x34(%rsp), %rax
cmpq %rax, %r13
jl 0x98c81
testl %eax, %eax
jle 0x98d0b
xorl %r12d, %r12d
leaq 0xcaf9(%rip), %r13      # 0xa57b0
leaq 0xf9bb(%rip), %rbp      # 0xa8679
cmpl $0x0, 0x30(%rsp)
jle 0x98d00
leal 0x2(%r12), %r14d
xorl %r15d, %r15d
movq 0x60(%rsp), %rax
movq (%rax,%r15,8), %rax
incq %r15
movsd (%rax,%r12,8), %xmm0
movq %r13, %rdi
movl %r15d, %esi
movl %r14d, %edx
movq %rbp, %rcx
movb $0x1, %al
callq 0x33644
movslq 0x30(%rsp), %rax
cmpq %rax, %r15
jl 0x98ccd
movl 0x34(%rsp), %eax
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x98cbe
movq 0x20(%rsp), %rdi
callq 0x3a180
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x3ed51
movq 0x50(%rsp), %r15
movq 0x48(%rsp), %r12
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x3ed51
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3ed51
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ed51
movq 0x28(%rsp), %rdx
decl %edx
movq 0x8(%rsp), %rcx
movl %ecx, %ebp
leal (%rbx,%rcx), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addl $-0x2, %ebp
mulsd 0xcf9c(%rip), %xmm1     # 0xa5d18
imull 0x44(%rsp), %edx
leal (%rcx,%rdx), %eax
addl $-0x2, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movsd (%rsp), %xmm0
callq 0x4160
mulsd 0x8(%rsp), %xmm0
imull %ebx, %ebp
movl %ebp, %edi
callq 0x1fc11
movapd %xmm0, %xmm1
movsd 0xc762(%rip), %xmm0     # 0xa5520
subsd %xmm1, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq