// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rdx, %rbx
movsd %xmm0, 0x10(%rsp)
leaq 0x18(%rsp), %rsi
callq 0x98796
testq %rax, %rax
je 0x9dc34
movq %rax, %r14
movq %rbx, 0x20(%rsp)
movq (%rax), %rdi
movl 0x18(%rsp), %r15d
movl %r15d, %esi
callq 0x38677
movsd %xmm0, 0x8(%rsp)
movq 0x8(%r14), %rdi
movl 0x1c(%rsp), %r13d
movl %r13d, %esi
callq 0x38677
movsd %xmm0, (%rsp)
movl %r15d, %edi
callq 0x391d6
movq %rax, %r12
movsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm0
movsd (%rsp), %xmm3
addsd %xmm3, %xmm0
movsd %xmm0, 0x28(%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, 0x30(%rsp)
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
divsd %xmm0, %xmm3
subsd %xmm3, %xmm2
movsd %xmm2, 0x8(%rsp)
leal (%r15,%r13), %eax
decl %eax
movl %eax, (%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
xorl %ebx, %ebx
xorpd %xmm0, %xmm0
testl %r15d, %r15d
jle 0x9db71
xorl %eax, %eax
movl (%r12,%rax,4), %ecx
xorl %edx, %edx
cmpl %r15d, %ecx
movl %r15d, %esi
cmovll %ebp, %esi
setge %dl
subl %esi, %ecx
movq (%r14,%rdx,8), %rdx
movslq %ecx, %rcx
addsd (%rdx,%rcx,8), %xmm0
incq %rax
cmpq %rax, %r15
jne 0x9db49
movsd 0x28(%rsp), %xmm1
subsd %xmm0, %xmm1
incl %r13d
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
divpd 0x30(%rsp), %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
subsd %xmm1, %xmm0
xorl %eax, %eax
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
seta %al
addl %eax, %ebx
movq %r12, %rdi
movl %r15d, %esi
movl (%rsp), %edx
callq 0x39814
testl %eax, %eax
jne 0x9db3e
movq %r14, %rdi
movl $0x2, %esi
callq 0x3a14b
leaq 0xeaf0(%rip), %rdi      # 0xac6bb
callq 0x54920
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
divsd %xmm1, %xmm0
movq 0x20(%rsp), %rcx
movsd %xmm0, (%rcx)
cmpl $0x2, %eax
jne 0x9dc45
movsd 0x7927(%rip), %xmm1     # 0xa5520
movsd 0x10(%rsp), %xmm2
addsd %xmm2, %xmm1
mulsd 0x810d(%rip), %xmm1     # 0xa5d18
ucomisd %xmm0, %xmm1
jbe 0x9dc2d
movsd 0x7907(%rip), %xmm1     # 0xa5520
subsd %xmm2, %xmm1
mulsd 0x80f3(%rip), %xmm1     # 0xa5d18
xorl %eax, %eax
ucomisd %xmm1, %xmm0
ja 0x9dc54
movl $0x1, %eax
jmp 0x9dc54
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, (%rbx)
xorl %eax, %eax
jmp 0x9dc54
xorl %eax, %eax
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
setbe %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq