// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x2131f(%rip), %rsi     # 0xa88a1
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x87a08
movq %rax, %r15
movq (%rbx), %rdx
leaq 0x26c18(%rip), %rsi     # 0xae1b8
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
cmpl $0x0, 0x10(%rbx)
movq %r15, 0x58(%rsp)
movq %rbx, 0x50(%rsp)
jle 0x8768d
leaq 0x1cb2e(%rip), %r13     # 0xa40f3
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
leaq (,%rbp,8), %rcx
leaq (%rcx,%rcx,8), %r12
movq (%rax,%r12), %rdx
movq %r15, %rdi
leaq 0x26be4(%rip), %rsi     # 0xae1c9
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
movl 0x10(%rax,%r12), %edx
movq %r15, %rdi
leaq 0x26bd9(%rip), %rsi     # 0xae1d8
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
cmpl $0x2, 0x10(%rax,%r12)
jl 0x8764b
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
movq 0x8(%rax,%r12), %rax
movq (%rax,%r14,8), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
cmpq %rcx, %r14
jl 0x8761f
jmp 0x87658
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
leaq (,%rbp,8), %rcx
addq %rbp, %rcx
movq 0x8(%rax,%rcx,8), %rax
movq (%rax,%r14,8), %rdx
movq %r15, %rdi
leaq 0x26b78(%rip), %rsi     # 0xae1ee
xorl %eax, %eax
callq 0x42e0
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
jl 0x875c7
cmpl $0x0, 0x10(%rbx)
jle 0x879ef
leaq 0x26715(%rip), %r13     # 0xaddb3
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
leaq (,%rbp,8), %rcx
leaq (%rcx,%rcx,8), %r14
movq (%rax,%r14), %rdx
movq %r15, %rdi
leaq 0x26b3a(%rip), %rsi     # 0xae1f8
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
movq %r14, 0x60(%rsp)
cmpl $0x0, 0x20(%rax,%r14)
movq %rbp, %r12
je 0x87739
movl $0x3, %esi
movl $0x1, %edx
leaq 0x26b1e(%rip), %rdi     # 0xae208
movq %r15, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
leaq (%r12,%r12,8), %r14
cmpl $0x0, 0x20(%rax,%r14,8)
jle 0x87739
xorl %ebp, %ebp
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x4d140
movq 0x8(%rbx), %rcx
cltq
leaq (%rax,%rax,8), %rax
movq (%rcx,%rax,8), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x42e0
incl %ebp
movq 0x8(%rbx), %rax
cmpl 0x20(%rax,%r14,8), %ebp
jl 0x87704
movl $0x4, %esi
movl $0x1, %edx
leaq 0x26ac2(%rip), %rdi     # 0xae20c
movq %r15, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
leaq (%r12,%r12,8), %r14
cmpl $0x0, 0x20(%rax,%r14,8)
movq %r12, %rbp
movq %r14, 0x70(%rsp)
je 0x87933
movq %rbx, %rdi
movq %rbp, 0x80(%rsp)
movl %ebp, %esi
callq 0x4d0d4
movq %rax, 0x68(%rsp)
movq 0x8(%rbx), %rax
cmpq $0x0, 0x28(%rax,%r14,8)
movq 0x60(%rsp), %r12
jle 0x87915
xorl %ebp, %ebp
movl $0x28, %edi
movq %r15, %rsi
callq 0x4150
movq 0x8(%rbx), %rsi
addq %r12, %rsi
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %ebp, %edi
callq 0x4d03e
movq 0x8(%rbx), %rsi
cmpl $0x2, 0x20(%rsi,%r12)
movq %rax, 0x78(%rsp)
jl 0x87833
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
leaq 0x26a43(%rip), %r13     # 0xae22a
movq 0x70(%rsp), %r12
movq 0x68(%rsp), %rdx
movslq (%rdx,%r14,4), %rcx
leaq (%rcx,%rcx,8), %rcx
movq 0x8(%rsi,%rcx,8), %rdx
movslq (%rax,%r14,4), %rcx
movq (%rdx,%rcx,8), %rdx
movq %r15, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x42e0
movq 0x78(%rsp), %rax
movq 0x68(%rsp), %rdx
incq %r14
movq 0x8(%rbx), %rsi
movslq 0x20(%rsi,%r12,8), %rcx
decq %rcx
cmpq %rcx, %r14
jl 0x877f1
jmp 0x8784a
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
movq 0x70(%rsp), %r12
movq 0x68(%rsp), %rdx
movslq (%rdx,%r14,4), %rcx
leaq (%rcx,%rcx,8), %rcx
movq 0x8(%rsi,%rcx,8), %rdx
movslq (%rax,%r14,4), %rcx
movq (%rdx,%rcx,8), %rdx
movq %r15, %rdi
leaq 0x269c6(%rip), %rsi     # 0xae22f
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
cmpl $0x2, 0x10(%rax,%r12,8)
jl 0x878c7
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
leaq 0x269a5(%rip), %r13     # 0xae235
movq 0x60(%rsp), %r12
movq 0x38(%rax,%r12), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
cmpq %rcx, %r14
jl 0x87895
jmp 0x878d9
xorl %r14d, %r14d
movq 0x58(%rsp), %r15
movq 0x50(%rsp), %rbx
movq 0x60(%rsp), %r12
movq 0x38(%rax,%r12), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
leaq 0x2694a(%rip), %rsi     # 0xae23c
movb $0x1, %al
callq 0x42e0
movq 0x78(%rsp), %rdi
callq 0x39194
incq %rbp
movq 0x8(%rbx), %rax
cmpq %rbp, 0x28(%rax,%r12)
jg 0x8779c
movq 0x68(%rsp), %rdi
callq 0x39194
leaq 0x2648d(%rip), %r13     # 0xaddb3
movq 0x80(%rsp), %rbp
jmp 0x879c6
movl $0x8, %esi
movl $0x1, %edx
leaq 0x268cd(%rip), %rdi     # 0xae211
movq %r15, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
cmpl $0x2, 0x10(%rax,%r14,8)
jl 0x87998
xorl %r14d, %r14d
movq 0x60(%rsp), %r12
leaq 0x268b3(%rip), %r13     # 0xae21a
movq 0x38(%rax,%r12), %rax
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
movq %r13, %rsi
movb $0x1, %al
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r12), %rcx
decq %rcx
cmpq %rcx, %r14
jl 0x87967
jmp 0x8799b
xorl %r14d, %r14d
movq 0x70(%rsp), %rcx
movq 0x38(%rax,%rcx,8), %rax
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm0
movq %r15, %rdi
leaq 0x2686a(%rip), %rsi     # 0xae222
movb $0x1, %al
callq 0x42e0
leaq 0x263ed(%rip), %r13     # 0xaddb3
movl $0x3, %esi
movl $0x1, %edx
leaq 0x267b6(%rip), %rdi     # 0xae18d
movq %r15, %rcx
callq 0x42c0
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
jl 0x876a0
movq %r15, %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop