// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/tests.c
// Function: permutation_test
int permutation_test(char **files, int *which, double confidence, double *real_confidence)
{
 /*One Tailed Test for H0: mu1 <= mu2 H1: mu1 > mu2*/
 /*Two Tailed Test for H0: mu1 = mu2 H1: mu1 != mu2*/
 /*confidence = 0.95 for alpha = 0.05, confidence = 0.99 for alpha = 0.01 etc.*/
 int i, counts[2], count, total;
 double **observations, sum[2], current[2];
 int* combination;
 observations = read_observations_for_two_file(files, counts);
 if (!observations)
  {
   *real_confidence = 0.5;
   return 0;
  }
 sum[0] = sum_of_list_double(observations[0], counts[0]);
 sum[1] = sum_of_list_double(observations[1], counts[1]);
 combination = first_combination(counts[0]);
 count = 0;
 total = 0;
 do{
   current[0] = 0;
   for (i = 0; i < counts[0]; i++)
     if (combination[i] < counts[0])
       current[0] += observations[0][combination[i]];
     else
       current[0] += observations[1][combination[i] - counts[0]];
   current[1] = sum[0] + sum[1] - current[0];
   total++;
   if (sum[0] / counts[0] - sum[1] / counts[1] > current[0] / counts[0] - current[1] / counts[1])
     count++;
 }while (next_combination(combination, counts[0], counts[0] + counts[1] - 1));
 free_2d((void**)observations, 2);
 if (get_parameter_i("tailed") == 2)
  {
   (*real_confidence) = count / (total + 0.0);
   if ((*real_confidence) < ((1 + confidence) / 2) && (*real_confidence) > ((1 - confidence) / 2))
     return 0;
   else
     return 1;
  }
 else
  {
   (*real_confidence) = count / (total + 0.0);
   if ((*real_confidence) < confidence)
     return 0;
   else
     return 1;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movsd %xmm0, 0x20(%rsp)
leaq 0x28(%rsp), %rsi
callq 0x89dc2
testq %rax, %rax
je 0x8ea96
movq %rax, %r14
movq %rbx, 0x30(%rsp)
movq (%rax), %rdi
movl 0x28(%rsp), %r15d
movl %r15d, %esi
callq 0x33c3e
movsd %xmm0, 0x10(%rsp)
movq 0x8(%r14), %rdi
movl 0x2c(%rsp), %r13d
movl %r13d, %esi
callq 0x33c3e
movsd %xmm0, 0x8(%rsp)
movl %r15d, %edi
callq 0x34598
movq %rax, %r12
movsd 0x10(%rsp), %xmm2
movapd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm3
addsd %xmm3, %xmm0
movsd %xmm0, 0x38(%rsp)
movd %r15d, %xmm0
movd %r13d, %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
cvtdq2pd %xmm0, %xmm0
divsd %xmm0, %xmm2
movapd %xmm0, 0x40(%rsp)
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
divsd %xmm0, %xmm3
subsd %xmm3, %xmm2
movsd %xmm2, 0x10(%rsp)
leal (%r15,%r13), %eax
decl %eax
movl %eax, 0x1c(%rsp)
xorl %ebp, %ebp
testl %r15d, %r15d
movl $0x0, %r13d
cmovgl %r15d, %r13d
movl $0x0, 0x8(%rsp)
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq %rax, %r13
je 0x8e9da
movl (%r12,%rax,4), %ecx
xorl %edx, %edx
cmpl %r15d, %ecx
setge %dl
movl %r15d, %esi
cmovll %ebp, %esi
subl %esi, %ecx
movq (%r14,%rdx,8), %rdx
movslq %ecx, %rcx
addsd (%rdx,%rcx,8), %xmm0
incq %rax
jmp 0x8e9b0
movsd 0x38(%rsp), %xmm1
subsd %xmm0, %xmm1
incl 0x8(%rsp)
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd 0x40(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
subsd %xmm1, %xmm0
xorl %eax, %eax
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
seta %al
addl %eax, %ebx
movq %r12, %rdi
movl %r15d, %esi
movl 0x1c(%rsp), %edx
callq 0x349ff
testl %eax, %eax
jne 0x8e9aa
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x34fc3
leaq 0xdbab(%rip), %rdi      # 0x9c5df
callq 0x4cd35
cvtsi2sd %ebx, %xmm0
cvtsi2sdl 0x8(%rsp), %xmm1
divsd %xmm1, %xmm0
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rcx)
cmpl $0x2, %eax
jne 0x8eaa7
movsd 0x6ac3(%rip), %xmm1     # 0x95520
movsd 0x20(%rsp), %xmm2
addsd %xmm2, %xmm1
mulsd 0x72b1(%rip), %xmm1     # 0x95d20
ucomisd %xmm0, %xmm1
jbe 0x8ea91
movsd 0x6aa3(%rip), %xmm1     # 0x95520
subsd %xmm2, %xmm1
mulsd 0x7297(%rip), %xmm1     # 0x95d20
xorl %eax, %eax
ucomisd %xmm1, %xmm0
ja 0x8eab6
pushq $0x1
popq %rax
jmp 0x8eab6
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x8eab6
xorl %eax, %eax
movsd 0x20(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq