// File: /workspace/github_c_makefile_star2_O1/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 $0x7a198, %rsp          # imm = 0x7A198
leaq 0xa4624(%rip), %rax     # 0xd24b8
movl 0x8(%rax), %ebx
testl %ebx, %ebx
je 0x2e1cb
movq %rdi, %r14
movl 0x10(%rdi), %r15d
leaq 0x77aac(%rip), %r8      # 0xa5959
movl $0x8, %edi
movl $0x8, %esi
movl %r15d, %edx
movl %r15d, %ecx
movl $0xa, %r9d
callq 0x393b5
movq %rax, %r12
leaq 0x77b00(%rip), %rdi     # 0xa59d2
callq 0x4090
callq 0x4250
negq %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x8(%rsp)
cmpl $0x0, 0x10(%r14)
jle 0x2e179
leal -0x1(%r15), %eax
imull %r15d, %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
divsd 0x76e6b(%rip), %xmm0    # 0xa4d80
cvtsi2sd %ebx, %xmm1
movsd %xmm1, (%rsp)
movl $0x1, %r13d
xorl %ebx, %ebx
xorpd %xmm1, %xmm1
movq %r12, 0x38(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0x1(%rbx), %rcx
movslq 0x10(%r14), %rax
movq %rcx, 0x58(%rsp)
cmpq %rax, %rcx
movq %r13, 0x60(%rsp)
jge 0x2e15f
leaq (%rbx,%rbx,8), %rax
movq %rax, 0x30(%rsp)
addsd 0x745bf(%rip), %xmm1    # 0xa2520
ucomisd %xmm0, %xmm1
jb 0x2df89
movsd %xmm1, 0x10(%rsp)
movl $0x2e, %edi
callq 0x40d0
movsd 0x10(%rsp), %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm0, %xmm1
jmp 0x2df61
movsd %xmm1, 0x10(%rsp)
movq (%r12,%rbx,8), %rax
movq $0x0, (%rax,%r13,8)
movq 0x8(%r14), %rcx
movq 0x30(%rsp), %rax
movl 0x10(%rcx,%rax,8), %eax
leaq (,%r13,8), %rbp
addq %r13, %rbp
testl %eax, %eax
jle 0x2e0e9
xorl %r15d, %r15d
movl %ebx, 0x24(%rsp)
movl %r15d, 0x1c(%rsp)
leaq 0x24(%rsp), %rdi
leaq 0x1c(%rsp), %rsi
movl $0x1, %edx
callq 0x26882
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd (%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
ucomisd 0x74d13(%rip), %xmm0    # 0xa2d08
jne 0x2dffd
jnp 0x2e0d0
movq 0x8(%r14), %rax
cmpl $0x0, 0x10(%rax,%rbp,8)
jle 0x2e0d0
xorl %r12d, %r12d
movl %ebx, 0x50(%rsp)
movl %r13d, 0x54(%rsp)
movl %r15d, 0x48(%rsp)
movl %r12d, 0x4c(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movl $0x2, %edx
callq 0x26882
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd (%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movl %r13d, 0x20(%rsp)
movl %r12d, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
movl $0x1, %edx
callq 0x26882
movsd 0x40(%rsp), %xmm1
ucomisd 0x74c94(%rip), %xmm1    # 0xa2d08
jne 0x2e078
jnp 0x2e0be
movapd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd (%rsp), %xmm1
ucomisd 0x74c78(%rip), %xmm1    # 0xa2d08
jne 0x2e094
jnp 0x2e0be
mulsd 0x68(%rsp), %xmm1
divsd %xmm1, %xmm0
callq 0x38e99
movq 0x38(%rsp), %rax
movq (%rax,%rbx,8), %rax
mulsd 0x40(%rsp), %xmm0
addsd (%rax,%r13,8), %xmm0
movsd %xmm0, (%rax,%r13,8)
incl %r12d
movq 0x8(%r14), %rax
cmpl 0x10(%rax,%rbp,8), %r12d
jl 0x2e00f
incl %r15d
movq 0x8(%r14), %rcx
movq 0x30(%rsp), %rax
movl 0x10(%rcx,%rax,8), %eax
cmpl %eax, %r15d
jl 0x2dfbe
movq 0x38(%rsp), %r12
movq (%r12,%rbx,8), %rdx
movsd (%rdx,%r13,8), %xmm0
ucomisd 0x74c08(%rip), %xmm0    # 0xa2d08
jne 0x2e104
jnp 0x2e133
decl %eax
movl 0x10(%rcx,%rbp,8), %edi
decl %edi
imull %eax, %edi
addsd %xmm0, %xmm0
mulsd (%rsp), %xmm0
callq 0x1f4cd
movsd 0x743fb(%rip), %xmm1    # 0xa2520
subsd %xmm0, %xmm1
movq (%r12,%rbx,8), %rax
movsd %xmm1, (%rax,%r13,8)
movq (%r12,%rbx,8), %rax
movsd (%rax,%r13,8), %xmm0
movq (%r12,%r13,8), %rax
movsd %xmm0, (%rax,%rbx,8)
incq %r13
cmpl %r13d, 0x10(%r14)
movsd 0x28(%rsp), %xmm0
movsd 0x10(%rsp), %xmm1
jg 0x2df59
movslq 0x10(%r14), %rax
movq 0x60(%rsp), %r13
incq %r13
movq 0x58(%rsp), %rbx
cmpq %rax, %rbx
jl 0x2df35
callq 0x4250
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x777d3(%rip), %rsi     # 0xa5970
leaq 0x77fc7(%rip), %rdx     # 0xa616b
leaq 0x70(%rsp), %r14
movq %r14, %rdi
callq 0x39529
movsd 0x8(%rsp), %xmm0
divsd 0x74b61(%rip), %xmm0    # 0xa2d20
movq %r14, %rdi
movb $0x1, %al
callq 0x4030
jmp 0x2e1ce
xorl %r12d, %r12d
movq %r12, %rax
addq $0x7a198, %rsp          # imm = 0x7A198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq