// File: /workspace/github_c_makefile_star2_O1/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
movq $-0x1, %rbx
movq $-0x10, %rdi
addq $0x10, %rdi
cmpq $0x0, 0x8(%r15,%rbx,8)
leaq 0x1(%rbx), %rbx
jne 0x97e7e
leaq 0x16e55(%rip), %rsi     # 0xaecea
movl $0x5, %edx
callq 0x390f5
movq %rax, %r12
movq %r15, %rdi
movq %rax, %rsi
movl %ebx, %edx
callq 0x95628
cmpl $-0x1, %eax
je 0x97ed2
testq %rbx, %rbx
movl %eax, 0x8(%rsp)
je 0x97f00
xorl %ebp, %ebp
movq %rbx, %rax
movq %r12, %rcx
addl (%rcx), %ebp
addq $0x10, %rcx
decq %rax
jne 0x97ec5
jmp 0x97f02
testq %rbx, %rbx
je 0x97ef3
movq %r12, %r14
addq $0x8, %r14
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3dbad
addq $0x10, %r14
decq %rbx
jne 0x97ede
movq %r12, %rdi
callq 0x39194
jmp 0x98131
xorl %ebp, %ebp
movl (%r12), %r15d
leaq 0x16ddd(%rip), %rdx     # 0xaecea
movl $0x8, %esi
movq %rbx, %rdi
movl $0xf, %ecx
callq 0x39210
movq %rax, 0x20(%rsp)
movq %r12, 0x10(%rsp)
movq %r12, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x96c9b
movq %rax, %r13
movq %rdx, %r14
movq %rax, %rsi
movl %ebp, %r8d
callq 0x97268
testq %rax, %rax
je 0x98131
movq %rax, %r12
movq %r15, 0x18(%rsp)
movq %rax, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x973ad
movq %r13, %rdi
movq %r14, %rsi
callq 0x3dbad
movl %ebp, %r14d
testl %ebp, %ebp
jle 0x97fdf
xorl %r13d, %r13d
movl $0x4, %edx
testq %rbx, %rbx
je 0x97fb6
xorl %eax, %eax
movq 0x10(%rsp), %rcx
xorl %esi, %esi
movslq (%rcx), %r8
movslq %esi, %rdi
addq %r8, %rdi
cmpq %rdi, %r13
jl 0x97fab
incq %rax
addq $0x10, %rcx
movl %edi, %esi
cmpq %rax, %rbx
jne 0x97f8d
jmp 0x97fb6
movl %r13d, %r15d
subl %esi, %r15d
addl $0x5, %eax
movl %eax, %edx
leal 0x1(%r15), %esi
movl 0xf433a0(%r12,%r13,4), %r8d
leaq 0xa7e7(%rip), %rdi      # 0xa27b0
leaq 0x15b8e(%rip), %rcx     # 0xadb5e
xorl %eax, %eax
callq 0x32c64
incq %r13
cmpq %r14, %r13
jne 0x97f7a
cmpl $0x2, 0x8(%rsp)
movq 0x10(%rsp), %r13
jne 0x97ff8
movq %r12, %rdi
movq %r13, %rsi
movl %ebx, %edx
callq 0x96e1b
testl %ebp, %ebp
movq 0x20(%rsp), %rbp
jle 0x98068
xorl %eax, %eax
movabsq $0x100000000, %rcx      # imm = 0x100000000
movq $-0x1, %rdx
testq %rbx, %rbx
je 0x98047
xorl %esi, %esi
movq %r13, %rdi
movq %rbx, %r8
xorl %r9d, %r9d
movslq (%rdi), %r10
movslq %r9d, %r9
addq %r10, %r9
cmpq %r9, %rax
jl 0x98040
addq %rcx, %rsi
addq $0x10, %rdi
decq %r8
jne 0x98024
jmp 0x98047
sarq $0x20, %rsi
movq %rsi, %rdx
xorps %xmm0, %xmm0
cvtsi2sdl 0xf433a0(%r12,%rax,4), %xmm0
addsd (%rbp,%rdx,8), %xmm0
movsd %xmm0, (%rbp,%rdx,8)
incq %rax
cmpq %r14, %rax
jne 0x9800d
movq %r12, %rdi
callq 0x1b530
xorpd %xmm2, %xmm2
testq %rbx, %rbx
je 0x980a3
xorl %eax, %eax
movq %r13, %rcx
movsd (%rbp,%rax,8), %xmm0
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx), %xmm1
divsd %xmm1, %xmm0
addsd %xmm0, %xmm2
incq %rax
addq $0x10, %rcx
cmpq %rax, %rbx
jne 0x9807e
movsd %xmm2, 0x8(%rsp)
testq %rbx, %rbx
je 0x980cd
movq %r13, %r14
addq $0x8, %r14
movq %rbx, %r15
movq -0x8(%r14), %rdi
movq (%r14), %rsi
callq 0x3dbad
addq $0x10, %r14
decq %r15
jne 0x980b8
movq %r13, %rdi
callq 0x39194
movq %rbp, %rdi
callq 0x39194
movq 0x18(%rsp), %rcx
imull %ebx, %ecx
leal 0x1(%rcx), %eax
imull %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd 0x16b6e(%rip), %xmm1    # 0xaec68
divsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
mulsd %xmm1, %xmm0
leal (%rax,%rax,2), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
subsd %xmm1, %xmm0
decl %ebx
movl %ebx, %edi
callq 0x1f4cd
movapd %xmm0, %xmm1
movsd 0xa3f5(%rip), %xmm0     # 0xa2520
subsd %xmm1, %xmm0
jmp 0x98135
xorpd %xmm0, %xmm0
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq