// File: /workspace/github_c_makefile_star2_O3/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 $0x7a1c8, %rsp          # imm = 0x7A1C8
leaq 0xa6d9c(%rip), %rax     # 0xd54b8
movl 0x8(%rax), %ebx
testl %ebx, %ebx
je 0x2ea81
movq %rdi, %r12
movl 0x10(%rdi), %r15d
leaq 0x7a29c(%rip), %r8      # 0xa89d1
movl $0x8, %edi
movl $0x8, %esi
movl %r15d, %edx
movl %r15d, %ecx
movl $0xa, %r9d
callq 0x3a3ac
movq %rax, %r14
leaq 0x7a2f0(%rip), %rdi     # 0xa8a4a
callq 0x4090
callq 0x4250
negq %rax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, 0x40(%rsp)
movl 0x10(%r12), %eax
testl %eax, %eax
jle 0x2ea2c
leal -0x1(%r15), %ecx
imull %r15d, %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
cvtsi2sd %edx, %xmm1
divsd 0x79667(%rip), %xmm1    # 0xa7e08
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movapd %xmm0, 0x70(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0x90(%rsp)
movl $0x1, %ebp
xorl %edx, %edx
xorpd %xmm2, %xmm2
movsd %xmm1, 0x18(%rsp)
movq %r14, 0x38(%rsp)
movq %rdx, %r13
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jge 0x2ea20
movq %rdx, 0x58(%rsp)
leaq (,%r13,8), %rax
addq %r13, %rax
movq %rax, 0x30(%rsp)
movq %rbp, 0x60(%rsp)
movq 0x40(%rsp), %rbx
addsd 0x76d16(%rip), %xmm2    # 0xa5520
ucomisd %xmm1, %xmm2
jb 0x2e832
movsd %xmm2, 0x8(%rsp)
movl $0x2e, %edi
callq 0x40d0
movsd 0x8(%rsp), %xmm2
movsd 0x18(%rsp), %xmm1
subsd %xmm1, %xmm2
jmp 0x2e80a
movq (%r14,%r13,8), %rax
movq $0x0, (%rax,%rbp,8)
movq 0x8(%rbx), %rax
movq 0x30(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
jle 0x2e9f7
movsd %xmm2, 0x8(%rsp)
xorl %r12d, %r12d
leaq (,%rbp,8), %r15
addq %rbp, %r15
movl %r13d, 0x2c(%rsp)
movl %r12d, 0x24(%rsp)
leaq 0x2c(%rsp), %rdi
leaq 0x24(%rsp), %rsi
movl $0x1, %edx
callq 0x26fc2
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x68(%rsp)
ucomisd 0x77469(%rip), %xmm0    # 0xa5d08
movq 0x8(%rbx), %rax
jne 0x2e8ab
jnp 0x2e986
cmpl $0x0, 0x10(%rax,%r15,8)
jle 0x2e986
xorl %r14d, %r14d
movl %r13d, 0x50(%rsp)
movl %ebp, 0x54(%rsp)
movl %r12d, 0x48(%rsp)
movl %r14d, 0x4c(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movl $0x2, %edx
callq 0x26fc2
movl %eax, %ebx
movl %ebp, 0x28(%rsp)
movl %r14d, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl $0x1, %edx
callq 0x26fc2
movd %ebx, %xmm0
movd %eax, %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
cvtdq2pd %xmm1, %xmm2
divpd 0x90(%rsp), %xmm2
movapd %xmm2, %xmm0
cmpneqpd 0x78eaa(%rip), %xmm0    # 0xa77d0
movmskpd %xmm0, %eax
cmpl $0x3, %eax
jne 0x2e96f
movsd 0x68(%rsp), %xmm1
mulsd %xmm2, %xmm1
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
movapd %xmm2, 0x80(%rsp)
movapd %xmm2, %xmm0
divsd %xmm1, %xmm0
callq 0x39bdc
movq 0x38(%rsp), %rax
movq (%rax,%r13,8), %rax
mulsd 0x80(%rsp), %xmm0
addsd (%rax,%rbp,8), %xmm0
movsd %xmm0, (%rax,%rbp,8)
incl %r14d
movq 0x40(%rsp), %rbx
movq 0x8(%rbx), %rax
cmpl 0x10(%rax,%r15,8), %r14d
jl 0x2e8ba
incl %r12d
movq 0x30(%rsp), %rcx
movl 0x10(%rax,%rcx,8), %ecx
cmpl %ecx, %r12d
jl 0x2e866
movq 0x38(%rsp), %r14
movq (%r14,%r13,8), %rdx
movsd (%rdx,%rbp,8), %xmm0
ucomisd 0x77357(%rip), %xmm0    # 0xa5d08
jne 0x2e9b5
jnp 0x2e9e9
decl %ecx
movl 0x10(%rax,%r15,8), %edi
decl %edi
imull %ecx, %edi
addsd %xmm0, %xmm0
mulsd 0x70(%rsp), %xmm0
callq 0x1fc11
movapd %xmm0, %xmm1
movsd 0x76b44(%rip), %xmm0    # 0xa5520
subsd %xmm1, %xmm0
movq (%r14,%r13,8), %rax
movsd %xmm0, (%rax,%rbp,8)
movsd 0x18(%rsp), %xmm1
movsd 0x8(%rsp), %xmm2
jmp 0x2e9fb
xorpd %xmm0, %xmm0
movq (%r14,%rbp,8), %rax
movsd %xmm0, (%rax,%r13,8)
incq %rbp
movl 0x10(%rbx), %eax
cmpl %ebp, %eax
jg 0x2e802
movslq %eax, %rcx
movq 0x60(%rsp), %rbp
movq 0x58(%rsp), %rdx
incq %rbp
cmpq %rcx, %rdx
jl 0x2e7d1
callq 0x4250
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
leaq 0x79f98(%rip), %rsi     # 0xa89e8
leaq 0x7a744(%rip), %rdx     # 0xa919b
leaq 0xa0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3a535
movsd 0x10(%rsp), %xmm0
divsd 0x772ab(%rip), %xmm0    # 0xa5d20
movq %rbx, %rdi
movb $0x1, %al
callq 0x4030
jmp 0x2ea84
xorl %r14d, %r14d
movq %r14, %rax
addq $0x7a1c8, %rsp          # imm = 0x7A1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq