// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/network.c
// Function: make_one_conditional_table
void make_one_conditional_table(bayesiangraphptr mygraph,int node)
{
 /*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 09.03.2001*/
 int i,j,k,value_pos,pos;
 int *list1,*parents;
 double sum;
 alloc_conditional_table(&mygraph->nodes[node]);
 if (mygraph->nodes[node].parents)
  {
   parents=find_parents(mygraph,node);
   list1 = safemalloc(mygraph->nodes[node].parents*sizeof(int), "make_one_conditional_table", 8);
  }
 for (i=0;i<train.row;i++)
  {
   value_pos=train.data[i][node];
   if (mygraph->nodes[node].parents)
    {
     for (k=0;k<mygraph->nodes[node].parents;k++)
       list1[k]=train.data[i][parents[k]];
     pos=table_pos(mygraph->nodes[node],list1);
    }
   else/*No parents*/
     pos=0;
   mygraph->nodes[node].table[pos][value_pos]++;
  }
 if (mygraph->nodes[node].parents)
  {
   safe_free(parents);
   safe_free(list1);
  } 
 for (j=0;j<mygraph->nodes[node].table_count;j++)
  {
   sum=0;
   for (k=0;k<mygraph->nodes[node].value_count;k++)
     sum+=mygraph->nodes[node].table[j][k];
   if (sum!=0)
    {
     for (k=0;k<mygraph->nodes[node].value_count;k++)
       mygraph->nodes[node].table[j][k]/=sum;
    }
   else
     for (k=0;k<mygraph->nodes[node].value_count;k++)
       mygraph->nodes[node].table[j][k] = (double) 1.0 / mygraph->nodes[node].value_count;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movslq %esi, %r14
leaq (,%r14,8), %rax
leaq (%rax,%rax,8), %r12
movl 0x10(%r15,%r12), %ecx
movl 0x28(%r15,%r12), %edx
leaq 0x5951f(%rip), %r8      # 0xa7697
movl $0x8, %edi
movl $0x8, %esi
movl $0x2, %r9d
callq 0x39245
movq %rax, 0x38(%r15,%r12)
movq 0x8(%rbx), %rax
cmpl $0x0, 0x20(%rax,%r12)
je 0x4e1d3
movq %rbx, %rdi
movl %r14d, %esi
callq 0x4d0d4
movq %rax, %r15
movq 0x8(%rbx), %rax
leaq (%r14,%r14,8), %rcx
movslq 0x20(%rax,%rcx,8), %rdi
shlq $0x2, %rdi
leaq 0x59515(%rip), %rsi     # 0xa76d9
movl $0x8, %edx
callq 0x390f5
movq %rax, %r12
jmp 0x4e1d3
cmpl $0x0, 0x842e6(%rip)     # 0xd24c0
jle 0x4e291
movq 0x842d1(%rip), %rax     # 0xd24b8
movq 0x8(%rbx), %rcx
leaq (%r14,%r14,8), %rdx
leaq (%rcx,%rdx,8), %rcx
addq $0x20, %rcx
movq 0x18(%rcx), %rdx
xorl %esi, %esi
movsd 0x5431b(%rip), %xmm0    # 0xa2520
movq (%rax,%rsi,8), %r8
movslq (%r8,%r14,4), %rdi
cmpl $0x0, (%rcx)
je 0x4e267
movl (%rcx), %r9d
testl %r9d, %r9d
jle 0x4e234
xorl %r10d, %r10d
movslq (%r15,%r10,4), %r9
movl (%r8,%r9,4), %r9d
movl %r9d, (%r12,%r10,4)
incq %r10
movslq (%rcx), %r9
cmpq %r9, %r10
jl 0x4e21d
testl %r9d, %r9d
jle 0x4e267
movq -0x8(%rcx), %r8
movl %r9d, %r9d
xorl %r10d, %r10d
xorl %r11d, %r11d
testq %r10, %r10
je 0x4e256
imull (%r8,%r10,4), %r11d
addl (%r12,%r10,4), %r11d
jmp 0x4e25a
movl (%r12), %r11d
incq %r10
cmpq %r10, %r9
jne 0x4e246
movslq %r11d, %r8
jmp 0x4e26a
xorl %r8d, %r8d
movq (%rdx,%r8,8), %r8
movsd (%r8,%rdi,8), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%r8,%rdi,8)
incq %rsi
movslq 0x84238(%rip), %rdi     # 0xd24c0
cmpq %rdi, %rsi
jl 0x4e205
movq 0x8(%rbx), %rax
leaq (%r14,%r14,8), %r14
cmpl $0x0, 0x20(%rax,%r14,8)
je 0x4e2b1
movq %r15, %rdi
callq 0x39194
movq %r12, %rdi
callq 0x39194
movq 0x8(%rbx), %rcx
movq 0x28(%rcx,%r14,8), %rax
testq %rax, %rax
jle 0x4e35a
leaq (%rcx,%r14,8), %rcx
movl 0x10(%rcx), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movsd 0x54247(%rip), %xmm0    # 0xa2520
divsd %xmm1, %xmm0
xorl %esi, %esi
xorpd %xmm1, %xmm1
xorpd %xmm2, %xmm2
testl %edx, %edx
jle 0x4e304
movq 0x38(%rcx), %rdi
movq (%rdi,%rsi,8), %rdi
xorl %r8d, %r8d
addsd (%rdi,%r8,8), %xmm2
incq %r8
cmpq %r8, %rdx
jne 0x4e2f6
ucomisd %xmm1, %xmm2
jne 0x4e30c
jnp 0x4e335
testl %edx, %edx
jle 0x4e352
movq 0x38(%rcx), %rdi
movq (%rdi,%rsi,8), %rdi
xorl %r8d, %r8d
movsd (%rdi,%r8,8), %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x4e31b
jmp 0x4e352
testl %edx, %edx
jle 0x4e352
movq 0x38(%rcx), %rdi
movq (%rdi,%rsi,8), %rdi
xorl %r8d, %r8d
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rdx
jne 0x4e344
incq %rsi
cmpq %rax, %rsi
jne 0x4e2e3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq