// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/indtests.c
// Function: zero_independence_test
double **zero_independence_test(bayesiangraphptr mygraph)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 09.03.2001*/
 double time;
	char pst[READLINELENGTH];
 int flength, i, j, k, l, total = (mygraph->nodecount) * (mygraph->nodecount - 1) / 2;
 double p1, p2, p3, walk = total / ((double)80.0), c;
 int list1[2], list2[1], list3[1];
 int value_list1[2], value_list2[1], value_list3[1];
 double **result;
 flength = train.row;
 if (flength == 0)
   return NULL;
 result = (double **)safemalloc_2d(sizeof(double *), sizeof(double), mygraph->nodecount, mygraph->nodecount, "zero_independence_test", 10);
 printf(m1269);
 time = -clock();
 c = 0;
 for (i = 0; i < mygraph->nodecount; i++)
   for (j = i + 1; j < mygraph->nodecount; j++)
    {
     c++;
     while (c >= walk)
      {
       printf(".");
       c -= walk;
      }
     result[i][j] = 0;
     for (k = 0; k < mygraph->nodes[i].value_count; k++)
      {
       list2[0] = i;
       value_list2[0] = k;
       p2 = count_data(list2, value_list2, 1) / (double)(flength + 0.0);
       if (p2 != 0)
         for (l = 0; l < mygraph->nodes[j].value_count; l++)
          {
           list1[0] = i;
           list1[1] = j;
           value_list1[0] = k;
           value_list1[1] = l;
           p1 = count_data(list1, value_list1, 2) / (double)(flength + 0.0);
           list3[0] = j;
           value_list3[0] = l;
           p3 = count_data(list3, value_list3, 1) / (double)(flength + 0.0);
           if ((p1 != 0) && (p3 != 0))
             result[i][j] += p1 * log2(p1 / (p2 * p3));
          }
      }
     if (result[i][j] != 0)
       result[i][j] = 1 - chi_square((mygraph->nodes[i].value_count - 1) * (mygraph->nodes[j].value_count - 1), 2 * result[i][j] * flength);
     result[j][i] = result[i][j];
    }
 time += clock();
	set_precision(pst, "Time for 0 independence calculations:", "\n");
 printf(pst, time / CLOCKS_PER_SEC);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7a1b8, %rsp          # imm = 0x7A1B8
movl 0x10(%rdi), %ecx
leal -0x1(%rcx), %eax
imull %ecx, %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
leaq 0xa2c05(%rip), %rdx     # 0xcd4b8
movl 0x8(%rdx), %ebx
testl %ebx, %ebx
je 0x2abc4
movq %rdi, %r12
cvtsi2sd %eax, %xmm0
divsd 0x6d4bb(%rip), %xmm0    # 0x97d88
movsd %xmm0, 0x8(%rsp)
leaq 0x6e077(%rip), %r8      # 0x98951
pushq $0x8
popq %rdi
pushq $0xa
popq %r9
movq %rdi, %rsi
movl %ecx, %edx
callq 0x351c3
movq %rax, %r13
leaq 0x6e0d5(%rip), %rdi     # 0x989ca
callq 0x4090
callq 0x4250
movsd 0x8(%rsp), %xmm1
negq %rax
movq %rax, 0x40(%rsp)
cvtsi2sd %ebx, %xmm0
movl 0x10(%r12), %eax
movapd %xmm0, 0x60(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0x80(%rsp)
pushq $0x1
popq %r14
xorl %ebx, %ebx
pushq $0x2e
popq %rbp
xorpd %xmm2, %xmm2
movq %r13, 0x20(%rsp)
movslq %eax, %rcx
cmpq %rcx, %rbx
jge 0x2ab6d
imulq $0x48, %rbx, %rcx
movq %rcx, 0x50(%rsp)
movq %r14, 0x48(%rsp)
cmpl %r14d, %eax
jle 0x2ab5d
addsd 0x6abba(%rip), %xmm2    # 0x95520
ucomisd %xmm1, %xmm2
movsd %xmm2, (%rsp)
jb 0x2a989
movl %ebp, %edi
callq 0x40d0
movsd (%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
subsd %xmm1, %xmm2
jmp 0x2a966
movq (%r13,%rbx,8), %rax
andq $0x0, (%rax,%r14,8)
xorl %ebp, %ebp
imulq $0x48, %r14, %rax
movq %rax, 0x28(%rsp)
movq 0x8(%r12), %rcx
movq 0x50(%rsp), %rax
movl 0x10(%rcx,%rax), %eax
cmpl %eax, %ebp
jge 0x2aae2
movq %rbx, %r15
movl %ebx, 0x1c(%rsp)
movl %ebp, 0x14(%rsp)
leaq 0x1c(%rsp), %rdi
leaq 0x14(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x23c61
movsd (%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
cvtsi2sd %eax, %xmm0
divsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
ucomisd 0x6b324(%rip), %xmm0    # 0x95d18
jne 0x2a9fc
jnp 0x2aad8
xorl %ebx, %ebx
movq 0x8(%r12), %rax
movq 0x28(%rsp), %rcx
cmpl 0x10(%rax,%rcx), %ebx
jge 0x2aad8
movq %r12, %r13
movl %r15d, 0x38(%rsp)
movl %r14d, 0x3c(%rsp)
movl %ebp, 0x30(%rsp)
movl %ebx, 0x34(%rsp)
leaq 0x38(%rsp), %rdi
leaq 0x30(%rsp), %rsi
pushq $0x2
popq %rdx
callq 0x23c61
movl %eax, %r12d
movl %r14d, 0x18(%rsp)
movl %ebx, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x23c61
movd %r12d, %xmm0
movd %eax, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm2
divpd 0x80(%rsp), %xmm2
movapd %xmm2, %xmm0
cmpneqpd 0x6b232(%rip), %xmm0    # 0x95cb0
movmskpd %xmm0, %eax
cmpl $0x3, %eax
jne 0x2aac3
movsd 0x58(%rsp), %xmm1
mulsd %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm2, 0x70(%rsp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x34d77
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %rax
mulsd 0x70(%rsp), %xmm0
addsd (%rax,%r14,8), %xmm0
movsd %xmm0, (%rax,%r14,8)
incl %ebx
movq %r13, %r12
movsd 0x8(%rsp), %xmm1
movsd (%rsp), %xmm2
jmp 0x2a9fe
incl %ebp
movq %r15, %rbx
jmp 0x2a99e
movq 0x20(%rsp), %r13
movq (%r13,%rbx,8), %rdx
movsd (%rdx,%r14,8), %xmm0
ucomisd 0x6b21e(%rip), %xmm0    # 0x95d18
jne 0x2aafe
jnp 0x2ab43
decl %eax
movq 0x28(%rsp), %rdx
movl 0x10(%rcx,%rdx), %edi
decl %edi
imull %eax, %edi
addsd %xmm0, %xmm0
mulsd 0x60(%rsp), %xmm0
callq 0x1d59f
movsd (%rsp), %xmm2
movapd %xmm0, %xmm1
movsd 0x6a9f2(%rip), %xmm0    # 0x95520
subsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
movq (%r13,%rbx,8), %rax
movsd %xmm0, (%rax,%r14,8)
pushq $0x2e
popq %rbp
movq (%r13,%r14,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %r14
movl 0x10(%r12), %eax
jmp 0x2a955
incq %rbx
movq 0x48(%rsp), %r14
incq %r14
jmp 0x2a93b
cvtsi2sdq 0x40(%rsp), %xmm0
movsd %xmm0, (%rsp)
callq 0x4250
cvtsi2sd %rax, %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x6ddd4(%rip), %rsi     # 0x98968
leaq 0x6e570(%rip), %rdx     # 0x9910b
leaq 0x90(%rsp), %rbx
movq %rbx, %rdi
callq 0x35305
movsd (%rsp), %xmm0
divsd 0x6b170(%rip), %xmm0    # 0x95d28
movq %rbx, %rdi
movb $0x1, %al
callq 0x4030
jmp 0x2abc7
xorl %r13d, %r13d
movq %r13, %rax
addq $0x7a1b8, %rsp          # imm = 0x7A1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq