// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/graphdata.c
// Function: calculate_K2_metric
double calculate_K2_metric(bayesiangraphptr mygraph, int node, int *parents, int parentcount)
{
 /*!Last Changed 02.02.2004*/
 int i, j, k;
 int ri, qi, xijk, Nij;
 double lnsum, result;
 int *list, *value;
 int **combinations;
 ri = mygraph->nodes[node].value_count;
 qi = 1;/*qi is the number of different instantiations of the parents of node*/
 for (i = 0; i < parentcount; i++)
   qi = qi * mygraph->nodes[parents[i]].value_count;
 list = (int *) safemalloc ((parentcount + 1) * sizeof(int), "calculate_K2_metric", 10);	/*sizes are for node+parents*/
 value = (int *) safemalloc ((parentcount + 1) * sizeof(int), "calculate_K2_metric", 11);
 combinations = parent_value_combinations(mygraph, parents, parentcount, qi);
 list[0] = node;
 for (i = 0; i < parentcount; i++)
   list[i + 1] = parents[i];
 result = 0;
 for (j = 0; j < qi; j++)
  {
   Nij = 0;
   lnsum = 0;
   for (k = 0; k < ri; k++)
    {
     value[0] = k;
     for (i = 0; i < parentcount; i++)
       value[i + 1] = combinations[j][i];
     xijk = count_data(list, value, parentcount + 1);
     Nij = Nij + xijk;
     lnsum = lnsum + lnfact(xijk);
    }
   result = result + (lnfact(ri - 1) - lnfact(Nij + ri - 1) + lnsum);
  }
 return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0xc(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x37a88
movl -0x30(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x18(%rbp), %rdx
movslq -0x20(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x48, %rdx, %rdx
addq %rdx, %rcx
imull 0x10(%rcx), %eax
movl %eax, -0x30(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x37a50
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0xad2ba(%rip), %rsi     # 0xe4d56
movl $0xa, %edx
callq 0x52d70
movq %rax, -0x50(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
leaq 0xad298(%rip), %rsi     # 0xe4d56
movl $0xb, %edx
callq 0x52d70
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x30(%rbp), %ecx
callq 0x37850
movq %rax, -0x60(%rbp)
movl -0xc(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x37b21
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x50(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x37af3
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x37c49
movl $0x0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x37bf4
movl -0x28(%rbp), %ecx
movq -0x58(%rbp), %rax
movl %ecx, (%rax)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x37ba4
movq -0x60(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x58(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x37b6e
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x1c(%rbp), %edx
addl $0x1, %edx
callq 0x37200
movl %eax, -0x34(%rbp)
movl -0x38(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movl -0x34(%rbp), %edi
callq 0x379b0
movaps %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x37b52
movsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x2c(%rbp), %edi
subl $0x1, %edi
callq 0x379b0
movsd %xmm0, -0x78(%rbp)
movl -0x38(%rbp), %edi
addl -0x2c(%rbp), %edi
subl $0x1, %edi
callq 0x379b0
movsd -0x78(%rbp), %xmm1
movaps %xmm0, %xmm2
movsd -0x70(%rbp), %xmm0
subsd %xmm2, %xmm1
addsd -0x40(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x37b30
movsd -0x48(%rbp), %xmm0
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)