// File: /workspace/github_c_makefile_star2_O1/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
movq $-0x8, %r12
movq $-0x10, %rdi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
addq $0x8, %r12
addq $0x10, %rdi
incl %ebp
cmpq $0x0, (%rbx,%r15,8)
leaq 0x1(%r15), %r15
jne 0x95c94
leaq -0x1(%r15), %r14
leaq 0x1900b(%rip), %rsi     # 0xaecbf
movl $0x5, %edx
callq 0x390f5
movq %rax, %r13
movq %rbx, %rdi
movq %rax, %rsi
movl %r14d, %edx
callq 0x95628
cmpl $-0x1, %eax
je 0x9611e
movl %ebp, 0x3c(%rsp)
movl %eax, %ebx
movl (%r13), %eax
movq %rax, 0x8(%rsp)
movq %r13, %rbp
leaq 0x18fce(%rip), %r13     # 0xaecbf
movq %r12, %rdi
movq %r13, %rsi
movl $0xb, %edx
callq 0x390f5
movq %rax, %r12
movslq %ebx, %rdi
movl $0x8, %esi
movq %r13, %rdx
movl $0xc, %ecx
callq 0x39210
movq %rax, %r13
cmpq $0x1, %r15
movq %r15, 0x30(%rsp)
movq %rbp, (%rsp)
je 0x95d87
addq $0x8, %rbp
xorl %r15d, %r15d
movq -0x8(%rbp), %rdi
movq (%rbp), %rsi
callq 0x3eab7
movq %rax, (%r12,%r15,8)
incq %r15
addq $0x10, %rbp
cmpq %r15, %r14
jne 0x95d32
movq 0x30(%rsp), %r15
leaq -0x1(%r15), %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x95d7f
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 0x95d64
incq %rcx
cmpq %rcx, %rax
jne 0x95d5a
testl %ebx, %ebx
jle 0x95daf
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
xorl %eax, %eax
movsd (%r13,%rax,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%r13,%rax,8)
incq %rax
cmpq %rax, %rbx
jne 0x95d95
movl %ebx, %edi
movl %ebx, %esi
callq 0x3c6e5
movq %rax, 0x20(%rsp)
movq %rdx, 0x28(%rsp)
movl %ebx, %edi
movl %ebx, %esi
callq 0x3c6e5
movq %rax, 0x10(%rsp)
movq %rdx, 0x18(%rsp)
cmpq $0x1, %r15
je 0x95e38
leaq -0x1(%r15), %rax
xorl %ecx, %ecx
testl %ebx, %ebx
jle 0x95e30
movq 0x28(%rsp), %rdx
movq (%r12,%rcx,8), %rsi
xorl %edi, %edi
movq (%rdx,%rdi,8), %r8
xorl %r9d, %r9d
movsd (%rsi,%rdi,8), %xmm0
subsd (%r13,%rdi,8), %xmm0
movsd (%rsi,%r9,8), %xmm1
subsd (%r13,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r8,%r9,8), %xmm1
movsd %xmm1, (%r8,%r9,8)
incq %r9
cmpq %r9, %rbx
jne 0x95df7
incq %rdi
cmpq %rbx, %rdi
jne 0x95df0
incq %rcx
cmpq %rcx, %rax
jne 0x95de1
xorps %xmm0, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm0
leaq 0x20(%rsp), %rdi
callq 0x3e50d
movq %r13, %rdi
callq 0x39194
cmpq $0x1, %r15
je 0x95f17
leaq -0x1(%r15), %rax
xorl %ecx, %ecx
movq 0x8(%rsp), %r13
movq (%rsp), %rbp
testl %r13d, %r13d
jle 0x95edf
movq %rcx, %rdx
shlq $0x4, %rdx
addq %rbp, %rdx
addq $0x8, %rdx
xorl %esi, %esi
testl %ebx, %ebx
jle 0x95ed7
movq 0x18(%rsp), %rdi
movq (%rdx), %r8
movq (%r8,%rsi,8), %r8
movq (%r12,%rcx,8), %r9
xorl %r10d, %r10d
movq (%rdi,%r10,8), %r11
xorl %r15d, %r15d
movsd (%r8,%r10,8), %xmm0
subsd (%r9,%r10,8), %xmm0
movsd (%r8,%r15,8), %xmm1
subsd (%r9,%r15,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r11,%r15,8), %xmm1
movsd %xmm1, (%r11,%r15,8)
incq %r15
cmpq %r15, %rbx
jne 0x95e9f
incq %r10
cmpq %rbx, %r10
jne 0x95e98
incq %rsi
cmpq %r13, %rsi
jne 0x95e81
incq %rcx
cmpq %rcx, %rax
jne 0x95e6c
movq %rbp, %r13
addq $0x8, %r13
xorl %ebp, %ebp
movq 0x30(%rsp), %r15
movq (%r12,%rbp,8), %rdi
callq 0x39194
movq -0x8(%r13), %rdi
movq (%r13), %rsi
callq 0x3dbad
incq %rbp
addq $0x10, %r13
cmpq %rbp, %r14
jne 0x95ef5
movq (%rsp), %rdi
callq 0x39194
movq %r12, %rdi
callq 0x39194
leaq 0x10(%rsp), %r12
movq (%r12), %rdi
movq 0x8(%r12), %rsi
movq 0x20(%rsp), %rdx
movq 0x28(%rsp), %rcx
callq 0x3e6a0
movq %rax, %r14
movq %rdx, %r13
movq (%r12), %rdi
movq 0x8(%r12), %rsi
callq 0x3f436
movsd %xmm0, (%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3f436
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movq %r12, %rdi
callq 0x3f648
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq %r12, %rdi
callq 0x3e83e
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x58(%rsp), %rdi
callq 0x41571
testq %rax, %rax
je 0x9608a
movq %rax, %r12
movq %r13, 0x48(%rsp)
movq %r14, 0x50(%rsp)
cmpl $0x0, 0x14(%rsp)
jle 0x95ffa
xorl %r13d, %r13d
leaq 0xc7e5(%rip), %rbp      # 0xa27b0
leaq 0xf64f(%rip), %r14      # 0xa5621
movsd (%r12,%r13,8), %xmm0
incq %r13
movq %rbp, %rdi
movl %r13d, %esi
movl $0x1, %edx
movq %r14, %rcx
movb $0x1, %al
callq 0x32c64
movslq 0x14(%rsp), %rax
cmpq %rax, %r13
jl 0x95fd2
movq %r12, 0x40(%rsp)
cmpl $0x0, 0x14(%rsp)
jle 0x96062
xorl %r12d, %r12d
leaq 0xc7a0(%rip), %r13      # 0xa27b0
leaq 0xf60a(%rip), %rbp      # 0xa5621
cmpl $0x0, 0x10(%rsp)
jle 0x96055
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 0x32c64
movslq 0x10(%rsp), %rax
cmpq %rax, %r15
jl 0x96026
incq %r12
movslq 0x14(%rsp), %rax
cmpq %rax, %r12
jl 0x96017
movq 0x40(%rsp), %rdi
callq 0x39194
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
callq 0x3dbad
movq 0x30(%rsp), %r15
movq 0x50(%rsp), %r14
movq 0x48(%rsp), %r13
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x3dbad
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x3dbad
movq %r14, %rdi
movq %r13, %rsi
callq 0x3dbad
movq 0x8(%rsp), %rcx
decl %ecx
movl %r15d, %ebp
leal (%rbx,%r15), %eax
decl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
addl $-0x2, %ebp
mulsd 0xcc43(%rip), %xmm1     # 0xa2d18
imull 0x3c(%rsp), %ecx
leal (%r15,%rcx), %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 0x1f4cd
movapd %xmm0, %xmm1
movsd 0xc408(%rip), %xmm0     # 0xa2520
subsd %xmm1, %xmm0
jmp 0x9614c
cmpq $0x1, %r15
je 0x96140
movq %r13, %rbx
addq $0x8, %rbx
movq -0x8(%rbx), %rdi
movq (%rbx), %rsi
callq 0x3dbad
addq $0x10, %rbx
decq %r14
jne 0x9612b
movq %r13, %rdi
callq 0x39194
xorpd %xmm0, %xmm0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq