// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/tests.c
// Function: kruskalwallis_multivariate
double kruskalwallis_multivariate(char **files)
{
 Graphptr mst;
 matrix* observations, distancematrix;
 int treatmentno, pos, i, p, n, treatments = 0, df, N = 0;
 double *T, S, sumd, res;
 while (files[treatments])
   treatments++;
 observations = safemalloc(treatments * sizeof(matrix), "kruskalwallis_multivariate", 5);
 p = read_multivariate_observations_for_multiple_file(files, observations, treatments);
 if (p == -1)
  {
   for (i = 0; i < treatments; i++)
     matrix_free(observations[i]);
   safe_free(observations);
   return 0;
  } 
 n = observations[0].row; 
 for (i = 0; i < treatments; i++) 
   N += observations[i].row; 
 T = (double *)safecalloc(treatments, sizeof(double), "kruskalwallis_multivariate", 15);
 distancematrix = distance_matrix_for_multiple_multivariate_sample(observations, treatments, N);
 mst = minimum_spanning_tree_from_observations(observations, distancematrix, treatments, N);
 if (mst == NULL)
   return 0;
 ranks_from_minimum_spanning_tree(mst, distancematrix);
 matrix_free(distancematrix);
 for (i = 0; i < N; i++)
  {
   treatmentno = index_in_multiple_sample(i, &pos, observations, treatments);
   write_array_variables("aout", pos + 1, 5 + treatmentno, "d", mst->visitorder[i]);
  }
 if (p == 2)
   save_mst_to_array_variables(mst, observations, treatments);
 for (i = 0; i < N; i++)
  {
   treatmentno = index_in_multiple_sample(i, &pos, observations, treatments);
   T[treatmentno] += mst->visitorder[i];
  }
 free_graph(mst);
 sumd = 0;
 for (i = 0; i < treatments; i++)
   sumd += T[i] * T[i] / observations[i].row;
 for (i = 0; i < treatments; i++)
   matrix_free(observations[i]);
 safe_free(observations); 
 safe_free(T);
 S = sumd * ((12 + 0.0) / (treatments * n * (treatments * n + 1))) - 3 * (treatments * n + 1);
 df = treatments - 1;
 res = chi_square(df, S);
 return 1 - res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
pushq $-0x1
popq %rbx
pushq $-0x10
popq %rdi
addq $0x10, %rdi
cmpq $0x0, 0x8(%r15,%rbx,8)
leaq 0x1(%rbx), %rbx
jne 0x8bf35
leaq 0x15d76(%rip), %rsi     # 0xa1cc2
pushq $0x5
popq %rdx
callq 0x34f59
movq %rax, %r14
movq %r15, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x898c0
cmpl $-0x1, %eax
movq %r14, 0x8(%rsp)
je 0x8c152
movl %eax, 0x18(%rsp)
movl (%r14), %eax
movq %rax, 0x20(%rsp)
xorl %r12d, %r12d
movq %r14, %rax
movq %rbx, %rcx
subq $0x1, %rcx
jb 0x8bf96
addl (%rax), %r12d
addq $0x10, %rax
jmp 0x8bf87
leaq 0x15d25(%rip), %rdx     # 0xa1cc2
pushq $0x8
popq %rsi
pushq $0xf
popq %rcx
movq %rbx, %rdi
callq 0x35067
movq %rax, %r15
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x8ae48
movq %rax, %r14
movq %rdx, %rbp
movq %rax, %rsi
movl %r12d, %r8d
callq 0x8b34c
testq %rax, %rax
je 0x8c178
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
movq %rbp, %rdx
callq 0x8b49c
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3929f
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
xorl %ebp, %ebp
movq 0x8(%rsp), %r14
cmpq %rbp, %r12
je 0x8c042
movl %ebp, %edi
leaq 0x14(%rsp), %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x8ae14
movl 0x14(%rsp), %esi
incl %esi
leal 0x5(%rax), %edx
movl 0xf433a0(%r13,%rbp,4), %r8d
leaq 0x9781(%rip), %rdi      # 0x957b0
leaq 0x14b24(%rip), %rcx     # 0xa0b5a
xorl %eax, %eax
callq 0x2f310
incq %rbp
jmp 0x8c001
cmpl $0x2, 0x18(%rsp)
jne 0x8c056
movq %r13, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x8af60
xorl %ebp, %ebp
leaq 0x14(%rsp), %r14
cmpq %rbp, %r12
je 0x8c090
movl %ebp, %edi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movl %ebx, %ecx
callq 0x8ae14
cvtsi2sdl 0xf433a0(%r13,%rbp,4), %xmm0
cltq
addsd (%r15,%rax,8), %xmm0
movsd %xmm0, (%r15,%rax,8)
incq %rbp
jmp 0x8c05d
movq %r13, %rdi
callq 0x19992
xorpd %xmm2, %xmm2
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movq %rdx, %rcx
cmpq %rax, %rbx
je 0x8c0ca
movsd (%r15,%rax,8), %xmm0
mulsd %xmm0, %xmm0
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rax
addq $0x10, %rcx
jmp 0x8c0a6
movsd %xmm2, 0x18(%rsp)
movq %rdx, %r14
addq $0x8, %r14
movq %rbx, %r12
subq $0x1, %r12
jb 0x8c0f2
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3929f
addq $0x10, %r14
jmp 0x8c0da
movq 0x8(%rsp), %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movq 0x20(%rsp), %rcx
imull %ebx, %ecx
leal 0x1(%rcx), %eax
imull %eax, %ecx
cvtsi2sd %ecx, %xmm0
movsd 0xecba(%rip), %xmm1     # 0x9add8
leal (%rax,%rax,2), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
mulsd %xmm1, %xmm0
subsd %xmm2, %xmm0
decl %ebx
movl %ebx, %edi
callq 0x1d59f
movapd %xmm0, %xmm1
movsd 0x93d4(%rip), %xmm0     # 0x95520
subsd %xmm1, %xmm0
jmp 0x8c17c
addq $0x8, %r14
subq $0x1, %rbx
jb 0x8c16e
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3929f
addq $0x10, %r14
jmp 0x8c156
movq 0x8(%rsp), %rdi
callq 0x34ff7
xorpd %xmm0, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq