// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/structure.c
// Function: k2_bn
bayesiangraphptr k2_bn(char *graph_name, char *train_file, char *cv_file, char *test_file, ORDERING_TYPE ordering, int maxparents)
{/*Last Changed 04.06.2001*/
 int i, j, nodecount;
 BOOLEAN proceed;
 bayesiangraphptr newnetwork;
 int *current_parents, *modified_parents;
 int selected_node;
 double p_old, p_new;
 int *nodeset;
 newnetwork = initial_graph_from_data(graph_name, train_file, cv_file, test_file);
 if (!newnetwork)
   return NULL;
 switch (ordering)
  {
   case ORDERING_RANDOM  :random_ordering(newnetwork);
                          break;
   case ORDERING_STATE   :state_ordering(newnetwork);
                          break;
   case ORDERING_MINTABLE:break;
   case ORDERING_ALARM   :alarm_ordering(newnetwork);
		                        break;
   default               :printf(m1240, ordering);
                          break;
  }
 for (j = 0; j < newnetwork->nodecount; j++)
  {
   i = newnetwork->ordering[j];
   proceed = BOOLEAN_TRUE;
   while ((proceed) && ((newnetwork->nodes[i].parents) < maxparents))
    {
     current_parents = find_parents(newnetwork, i);
     p_old = calculate_K2_metric(newnetwork, i, current_parents, newnetwork->nodes[i].parents);
     modified_parents = find_parents(newnetwork, i);
     nodeset = find_nodes_before(newnetwork, i);
     nodecount = find_nodecount_before(newnetwork, i);
     selected_node = select_node_maximizes_K2_metric(newnetwork, i, current_parents, newnetwork->nodes[i].parents, nodeset, nodecount);
     if (selected_node == -1)
       proceed = BOOLEAN_FALSE;
     else
      {
       modified_parents = alloc(modified_parents, ((newnetwork->nodes[i].parents + 1) * sizeof(int)), newnetwork->nodes[i].parents + 1);
       modified_parents[newnetwork->nodes[i].parents] = selected_node;
       p_new = calculate_K2_metric(newnetwork, i, modified_parents, newnetwork->nodes[i].parents + 1);
       if (p_new > p_old)
        {
         p_old = p_new;
         add_one_arc(newnetwork);
         add_one_pointer(newnetwork,&newnetwork->nodes[i],selected_node);
         add_parent_counts(newnetwork,&newnetwork->nodes[i],selected_node);
        }
       else
         proceed = BOOLEAN_FALSE;
      }
					safe_free(current_parents);
					safe_free(modified_parents);
					safe_free(nodeset);
		  }
   printf(m1317, i);
  }
 make_conditional_tables(newnetwork);
 return newnetwork;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x36fc0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0xc5b00
movq $0x0, -0x8(%rbp)
jmp 0xc5dbe
movl -0x2c(%rbp), %eax
movq %rax, -0x80(%rbp)
subq $0x3, %rax
ja 0xc5b44
movq -0x80(%rbp), %rax
leaq 0x2847c(%rip), %rcx     # 0xedf94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x48(%rbp), %rdi
callq 0x786a0
jmp 0xc5b55
movq -0x48(%rbp), %rdi
callq 0x786f0
jmp 0xc5b55
jmp 0xc5b55
movq -0x48(%rbp), %rdi
callq 0x78ab0
jmp 0xc5b55
movl -0x2c(%rbp), %esi
leaq 0x28456(%rip), %rdi     # 0xedfa4
movb $0x0, %al
callq 0x4030
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0xc5dad
movq -0x48(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x40(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x40(%rbp)
movb %al, -0x81(%rbp)
je 0xc5bb5
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
cmpl -0x30(%rbp), %eax
setl %al
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0xc5bc4
jmp 0xc5d8e
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x70420
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
callq 0x37a10
movsd %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x70420
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x78db0
movq %rax, -0x78(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x78e50
movl %eax, -0x3c(%rbp)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x50(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
movq -0x78(%rbp), %r8
movl -0x3c(%rbp), %r9d
callq 0x37c60
movl %eax, -0x5c(%rbp)
cmpl $-0x1, -0x5c(%rbp)
jne 0xc5c71
movl $0x0, -0x40(%rbp)
jmp 0xc5d6e
movq -0x58(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x2, %rsi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %edx
addl $0x1, %edx
callq 0x52d10
movq %rax, -0x58(%rbp)
movl -0x5c(%rbp), %edx
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rcx
movq 0x8(%rcx), %rcx
movslq -0x34(%rbp), %rsi
imulq $0x48, %rsi, %rsi
addq %rsi, %rcx
movslq 0x20(%rcx), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x48(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x58(%rbp), %rdx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
callq 0x37a10
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
ucomisd -0x68(%rbp), %xmm0
jbe 0xc5d65
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x48(%rbp), %rdi
callq 0x70a70
movq -0x48(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rsi
movl -0x5c(%rbp), %edx
callq 0x70b20
movq -0x48(%rbp), %rdi
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rsi
movslq -0x34(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rsi
movl -0x5c(%rbp), %edx
callq 0x70c80
jmp 0xc5d6c
movl $0x0, -0x40(%rbp)
jmp 0xc5d6e
movq -0x50(%rbp), %rdi
callq 0x52e80
movq -0x58(%rbp), %rdi
callq 0x52e80
movq -0x78(%rbp), %rdi
callq 0x52e80
jmp 0xc5b85
movl -0x34(%rbp), %esi
leaq 0x28238(%rip), %rdi     # 0xedfd0
movb $0x0, %al
callq 0x4030
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xc5b5c
movq -0x48(%rbp), %rdi
callq 0x72260
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)