// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/savenet.c
// Function: save_graph_bif
void save_graph_bif(bayesiangraphptr mygraph,char *file_name)
{
 /*!Last Changed 11.02.2001*/
 FILE *myfile;
 int i, j, k, *list, *valuelist;
 myfile = fopen(file_name, "w");
	if (!myfile)
		 return;
 fprintf(myfile, "network %s { }\n\n", mygraph->name);
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "variable %s {\n", mygraph->nodes[i].name);
   fprintf(myfile, "type discrete [%d] { ", mygraph->nodes[i].value_count);
   for (j = 0; j < mygraph->nodes[i].value_count - 1; j++)
     fprintf(myfile, "%s, ", mygraph->nodes[i].values[j]);
   fprintf(myfile, "%s };\n}\n\n", mygraph->nodes[i].values[j]);
  }
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "probability (%s", mygraph->nodes[i].name);
   if (mygraph->nodes[i].parents)
    {
     fprintf(myfile, " | ");
     for (j = 0; j < mygraph->nodes[i].parents; j++)
      {
       k = parent_index(mygraph, i, j);
       fprintf(myfile, "%s ", mygraph->nodes[k].name);
      }
    }
   fprintf(myfile, ") {\n");
   if (!mygraph->nodes[i].parents)
    {
     fprintf(myfile, "  table ");
     for (j = 0; j < mygraph->nodes[i].value_count - 1; j++)
       fprintf(myfile, " %4.f, ", mygraph->nodes[i].table[0][j]);
     fprintf(myfile, " %4.f;\n", mygraph->nodes[i].table[0][j]);
    }
   else
    {
     list = find_parents(mygraph, i);
     for (j = 0; j < mygraph->nodes[i].table_count; j++)
      {
       fprintf(myfile, "(");
       valuelist = table_list(mygraph->nodes[i], j);
       for (k = 0; k < mygraph->nodes[i].parents - 1; k++)
         fprintf(myfile, " %s,", mygraph->nodes[list[k]].values[valuelist[k]]);
       fprintf(myfile, "%s ) ", mygraph->nodes[list[k]].values[valuelist[k]]);
       for (k = 0; k < mygraph->nodes[i].value_count - 1; k++)
         fprintf(myfile, "%.4f, ", mygraph->nodes[i].table[j][k]);
       fprintf(myfile, "%.4f;\n", mygraph->nodes[i].table[j][k]);
       safe_free(valuelist);
      }
     safe_free(list);
    }
   fprintf(myfile, "}\n\n");
  }
 fclose(myfile); 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x1efaa(%rip), %rsi     # 0x9b891
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x7cc48
movq %rax, %r14
movq (%rbx), %rdx
leaq 0x248af(%rip), %rsi     # 0xa11b4
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
leaq 0x1a7bf(%rip), %r13     # 0x970d5
leaq 0x248cd(%rip), %rbp     # 0xa11ea
xorl %r15d, %r15d
movq %r14, 0x48(%rsp)
movslq 0x10(%rbx), %rax
cmpq %rax, %r15
jge 0x7c9b8
movq 0x8(%rbx), %rax
imulq $0x48, %r15, %r12
movq (%rax,%r12), %rdx
movq %r14, %rdi
leaq 0x2487d(%rip), %rsi     # 0xa11c5
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
movl 0x10(%rax,%r12), %edx
movq %r14, %rdi
leaq 0x24872(%rip), %rsi     # 0xa11d4
xorl %eax, %eax
callq 0x42e0
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
movq 0x8(%rax,%r12), %rax
cmpq %rcx, %r14
jge 0x7c99a
movq (%rax,%r14,8), %rdx
movq 0x48(%rsp), %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
jmp 0x7c96c
movq (%rax,%r14,8), %rdx
movq 0x48(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r15
jmp 0x7c925
pushq $0x1
popq %r15
leaq 0x24853(%rip), %r13     # 0xa1216
xorl %ecx, %ecx
cltq
cmpq %rax, %rcx
jge 0x7cc32
movq 0x8(%rbx), %rax
movq %rcx, 0x50(%rsp)
imulq $0x48, %rcx, %r12
movq (%rax,%r12), %rdx
movq %r14, %rdi
leaq 0x24809(%rip), %rsi     # 0xa11f4
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
cmpl $0x0, 0x20(%rax,%r12)
je 0x7ca52
leaq 0x247ff(%rip), %rdi     # 0xa1204
pushq $0x3
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x42c0
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
cmpl 0x20(%rax,%r12), %ebp
jge 0x7ca52
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
movl %ebp, %edx
callq 0x47365
movq 0x8(%rbx), %rcx
cltq
imulq $0x48, %rax, %rax
movq (%rcx,%rax), %rdx
movq %r14, %rdi
leaq 0x24368(%rip), %rsi     # 0xa0daf
xorl %eax, %eax
callq 0x42e0
incl %ebp
jmp 0x7ca15
leaq 0x247af(%rip), %rdi     # 0xa1208
pushq $0x4
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
cmpl $0x0, 0x20(%rax,%r12)
je 0x7cba6
movq %rbx, %rdi
movq 0x50(%rsp), %rsi
callq 0x47301
movq %rax, %r15
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
cmpq %r13, 0x28(%rax,%r12)
jle 0x7cb91
pushq $0x28
popq %rdi
movq %r14, %rsi
callq 0x4150
movq 0x8(%rbx), %rsi
addq %r12, %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %r13d, %edi
callq 0x4727f
movq %rax, %rbp
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movslq 0x20(%rax,%r12), %rcx
decq %rcx
cmpq %rcx, %r14
jge 0x7cb01
movslq (%r15,%r14,4), %rcx
imulq $0x48, %rcx, %rcx
movq 0x8(%rax,%rcx), %rax
movslq (%rbp,%r14,4), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x48(%rsp), %rdi
leaq 0x24731(%rip), %rsi     # 0xa1226
xorl %eax, %eax
callq 0x42e0
incq %r14
jmp 0x7cac2
movslq (%r15,%r14,4), %rcx
imulq $0x48, %rcx, %rcx
movq 0x8(%rax,%rcx), %rax
movslq (%rbp,%r14,4), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x48(%rsp), %rdi
leaq 0x24708(%rip), %rsi     # 0xa122b
xorl %eax, %eax
callq 0x42e0
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
movq 0x38(%rax,%r12), %rax
movq (%rax,%r13,8), %rax
cmpq %rcx, %r14
jge 0x7cb65
movsd (%rax,%r14,8), %xmm0
movq 0x48(%rsp), %rdi
leaq 0x246d8(%rip), %rsi     # 0xa1231
movb $0x1, %al
callq 0x42e0
incq %r14
jmp 0x7cb2d
movsd (%rax,%r14,8), %xmm0
movq 0x48(%rsp), %r14
movq %r14, %rdi
leaq 0x246be(%rip), %rsi     # 0xa1238
movb $0x1, %al
callq 0x42e0
movq %rbp, %rdi
callq 0x34ff7
incq %r13
jmp 0x7ca8a
movq %r15, %rdi
callq 0x34ff7
pushq $0x1
popq %r15
leaq 0x24672(%rip), %r13     # 0xa1216
jmp 0x7cc0d
leaq 0x24660(%rip), %rdi     # 0xa120d
pushq $0x8
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x42c0
xorl %r14d, %r14d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
movq 0x38(%rax,%r12), %rax
movq (%rax), %rax
cmpq %rcx, %r14
jge 0x7cbf1
movsd (%rax,%r14,8), %xmm0
movq 0x48(%rsp), %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x42e0
incq %r14
jmp 0x7cbbe
movsd (%rax,%r14,8), %xmm0
movq 0x48(%rsp), %r14
movq %r14, %rdi
leaq 0x24618(%rip), %rsi     # 0xa121e
movb $0x1, %al
callq 0x42e0
leaq 0x24575(%rip), %rdi     # 0xa1189
pushq $0x3
popq %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x42c0
movq 0x50(%rsp), %rcx
incq %rcx
movl 0x10(%rbx), %eax
jmp 0x7c9c5
movq %r14, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop