// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %rbp
pushq $-0x10
popq %rdi
pushq $-0x8
popq %r15
xorl %r14d, %r14d
incl %ebp
addq $0x10, %rdi
addq $0x8, %r15
cmpq $0x0, (%rbx,%r14,8)
leaq 0x1(%r14), %r14
jne 0x89ec1
leaq -0x1(%r14), %r12
leaq 0x17db6(%rip), %rsi     # 0xa1c97
pushq $0x5
popq %rdx
callq 0x34f59
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
movl %r12d, %edx
callq 0x898c0
cmpl $-0x1, %eax
je 0x8a333
movq %r12, (%rsp)
movl %eax, %ebx
movl (%r13), %eax
movq %rax, 0x48(%rsp)
movq %r13, 0x10(%rsp)
leaq 0x17d79(%rip), %r13     # 0xa1c97
pushq $0xb
popq %rdx
movq %r15, %rdi
movq %r13, %rsi
callq 0x34f59
movq %rax, %r12
movslq %ebx, %rdi
pushq $0x8
popq %rsi
pushq $0xc
popq %rcx
movq %r13, %rdx
callq 0x35067
movq %rax, %r13
movq %r14, 0x50(%rsp)
leaq -0x1(%r14), %rax
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rax
leaq 0x8(%rax), %r14
xorl %r15d, %r15d
cmpq %r15, (%rsp)
je 0x89f7c
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x39f86
movq %rax, (%r12,%r15,8)
incq %r15
addq $0x10, %r14
jmp 0x89f5d
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %r14d
cmovgl %ebx, %r14d
movq 0x8(%rsp), %rsi
cmpq %rax, %rsi
je 0x89fbc
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x89fb7
movq (%r12,%rax,8), %rdx
movsd (%rdx,%rcx,8), %xmm0
addsd (%r13,%rcx,8), %xmm0
movsd %xmm0, (%r13,%rcx,8)
incq %rcx
jmp 0x89f96
incq %rax
jmp 0x89f8f
cvtsi2sdl (%rsp), %xmm0
xorl %eax, %eax
cmpq %rax, %r14
je 0x89fdf
movsd (%r13,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
jmp 0x89fc3
movl %ebp, 0x44(%rsp)
movl %ebx, %edi
movl %ebx, %esi
callq 0x380d3
movq %rdx, %r15
movq %rax, 0x18(%rsp)
movq %rdx, 0x20(%rsp)
movl %ebx, %edi
movl %ebx, %esi
callq 0x380d3
movq %rdx, %rbp
movq %rax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
xorl %eax, %eax
cmpq %rax, 0x8(%rsp)
je 0x8a068
xorl %ecx, %ecx
cmpq %r14, %rcx
je 0x8a063
xorl %edx, %edx
cmpq %rdx, %rbx
je 0x8a05e
movq (%r12,%rax,8), %rsi
movsd (%rsi,%rcx,8), %xmm0
subsd (%r13,%rcx,8), %xmm0
movsd (%rsi,%rdx,8), %xmm1
subsd (%r13,%rdx,8), %xmm1
mulsd %xmm0, %xmm1
movq (%r15,%rcx,8), %rsi
addsd (%rsi,%rdx,8), %xmm1
movsd %xmm1, (%rsi,%rdx,8)
incq %rdx
jmp 0x8a026
incq %rcx
jmp 0x8a01f
incq %rax
jmp 0x8a016
movq 0x48(%rsp), %r15
cvtsi2sd %r15d, %xmm0
leaq 0x18(%rsp), %rdi
callq 0x39a42
movq %r13, %rdi
callq 0x34ff7
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
movq (%rsp), %r13
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %r15
cmpq %rax, %r15
je 0x8a115
movq %rax, %rdx
shlq $0x4, %rdx
addq %r11, %rdx
addq $0x8, %rdx
xorl %esi, %esi
cmpq %rcx, %rsi
je 0x8a110
xorl %edi, %edi
cmpq %r14, %rdi
je 0x8a10b
xorl %r8d, %r8d
cmpq %r8, %rbx
je 0x8a106
movq (%rdx), %r9
movq (%r9,%rsi,8), %r9
movsd (%r9,%rdi,8), %xmm0
movq (%r12,%rax,8), %r10
subsd (%r10,%rdi,8), %xmm0
movsd (%r9,%r8,8), %xmm1
subsd (%r10,%r8,8), %xmm1
mulsd %xmm0, %xmm1
movq (%rbp,%rdi,8), %r9
addsd (%r9,%r8,8), %xmm1
movsd %xmm1, (%r9,%r8,8)
incq %r8
jmp 0x8a0c4
incq %rdi
jmp 0x8a0bc
incq %rsi
jmp 0x8a0b5
incq %rax
jmp 0x8a0a0
movq %r11, %r14
addq $0x8, %r14
xorl %r15d, %r15d
cmpq %r15, %r13
je 0x8a142
movq (%r12,%r15,8), %rdi
callq 0x34ff7
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3929f
incq %r15
addq $0x10, %r14
jmp 0x8a11f
movq 0x10(%rsp), %rdi
callq 0x34ff7
movq %r12, %rdi
callq 0x34ff7
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
callq 0x39bde
movq %rax, %r15
movq %rdx, %r12
leaq 0x30(%rsp), %r14
movq (%r14), %rdi
movq 0x8(%r14), %rsi
callq 0x3a822
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3a822
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movq %r14, %rdi
callq 0x3a9f7
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x39d59
movq (%r14), %rsi
movq 0x8(%r14), %rdx
leaq 0x58(%rsp), %rdi
callq 0x3c5c1
movq %rax, (%rsp)
testq %rax, %rax
je 0x8a2a4
movq %r15, 0x10(%rsp)
pushq $0x1
popq %r13
leaq 0xb5c5(%rip), %r14      # 0x957b0
leaq 0xe407(%rip), %rbp      # 0x985f9
pushq $0x1
popq %r15
movslq 0x34(%rsp), %rax
cmpq %rax, %r13
jg 0x8a223
movq (%rsp), %rax
movsd -0x8(%rax,%r13,8), %xmm0
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
movq %rbp, %rcx
movb $0x1, %al
callq 0x2f310
incq %r13
jmp 0x8a1f6
movq %r12, 0x28(%rsp)
xorl %r12d, %r12d
leaq 0xb57e(%rip), %r13      # 0x957b0
leaq 0xe3c0(%rip), %rbp      # 0x985f9
cltq
cmpq %rax, %r12
jge 0x8a282
leal 0x2(%r12), %r14d
xorl %r15d, %r15d
movslq 0x30(%rsp), %rax
cmpq %rax, %r15
jge 0x8a279
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 0x2f310
jmp 0x8a248
incq %r12
movl 0x34(%rsp), %eax
jmp 0x8a239
movq (%rsp), %rdi
callq 0x34ff7
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x3929f
movq 0x10(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rsi
callq 0x3929f
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3929f
movq %r15, %rdi
movq %r12, %rsi
callq 0x3929f
movq 0x48(%rsp), %rdx
decl %edx
movq 0x50(%rsp), %rcx
movl %ecx, %ebp
leal (%rbx,%rcx), %eax
decl %eax
cvtsi2sd %eax, %xmm1
addl $-0x2, %ebp
mulsd 0xba31(%rip), %xmm1     # 0x95d20
imull 0x44(%rsp), %edx
leal (%rcx,%rdx), %eax
addl $-0x2, %eax
cvtsi2sd %eax, %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movsd 0x8(%rsp), %xmm0
callq 0x4160
mulsd (%rsp), %xmm0
imull %ebx, %ebp
movl %ebp, %edi
callq 0x1d59f
movapd %xmm0, %xmm1
movsd 0xb1f3(%rip), %xmm0     # 0x95520
subsd %xmm1, %xmm0
jmp 0x8a35e
movq %r13, %rbx
addq $0x8, %rbx
subq $0x1, %r12
jb 0x8a352
movq -0x8(%rbx), %rdi
movq (%rbx), %rsi
callq 0x3929f
addq $0x10, %rbx
jmp 0x8a33a
movq %r13, %rdi
callq 0x34ff7
xorpd %xmm0, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq