// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/savenet.c
// Function: save_graph_net
void save_graph_net(bayesiangraphptr mygraph, char *file_name)
{
 /*!Last Changed 06.02.2001*/
 FILE *myfile;
 int i, j, k, *list, *valuelist;
 myfile = fopen(file_name, "w");
	if (!myfile)
		 return;
 fprintf(myfile, "(network %s:probability)\n", mygraph->name);
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "(var %s (", mygraph->nodes[i].name);
   for (j = 0; j < mygraph->nodes[i].value_count; j++)
     fprintf(myfile, "%s ", mygraph->nodes[i].values[j]);
   fprintf(myfile, "))\n");
  }
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "parents %s ", mygraph->nodes[i].name);
   if (mygraph->nodes[i].parents == 0)/*No parents*/
    {
     fprintf(myfile, "(");
     for (j = 0; j < mygraph->nodes[i].value_count; j++)
       fprintf(myfile, "%.4f ", mygraph->nodes[i].table[0][j]);
     fprintf(myfile, ")\n");
    }
   else
    {
     list = find_parents(mygraph, i);/*Print parents*/
     fprintf(myfile, "(");
     for (j = 0; j < mygraph->nodes[i].parents; j++)
       fprintf(myfile, "%s ", mygraph->nodes[list[j]].name);
     fprintf(myfile, ")(\n");
     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; k++)
         fprintf(myfile, "%s ", mygraph->nodes[list[k]].values[valuelist[k]]);
       fprintf(myfile, ")");
       for (k = 0; k < mygraph->nodes[i].value_count; k++)
         fprintf(myfile, "%.4f ", mygraph->nodes[i].table[j][k]);
       fprintf(myfile, ")\n");
       safe_free(valuelist);
      }
     fprintf(myfile, ")\n");
     safe_free(list);
    }
  }
 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 0x1fa7a(%rip), %rsi     # 0x9b891
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x7c0dc
movq %rax, %r14
movq (%rbx), %rdx
leaq 0x24f4a(%rip), %rsi     # 0xa0d7f
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
leaq 0x24f69(%rip), %r12     # 0xa0daf
xorl %r13d, %r13d
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jge 0x7beb7
movq 0x8(%rbx), %rax
imulq $0x48, %r13, %rbp
movq (%rax,%rbp), %rdx
movq %r14, %rdi
leaq 0x24f31(%rip), %rsi     # 0xa0d99
xorl %eax, %eax
callq 0x42e0
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%rbp), %rcx
cmpq %rcx, %r15
jge 0x7be9d
addq %rbp, %rax
movq 0x8(%rax), %rax
movq (%rax,%r15,8), %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r15
jmp 0x7be72
leaq 0x24eff(%rip), %rdi     # 0xa0da3
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
incq %r13
jmp 0x7be49
xorl %r12d, %r12d
cltq
cmpq %rax, %r12
jge 0x7c0c6
movq 0x8(%rbx), %rax
imulq $0x48, %r12, %r13
movq (%rax,%r13), %rdx
movq %r14, %rdi
leaq 0x24ecc(%rip), %rsi     # 0xa0da7
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
cmpl $0x0, 0x20(%rax,%r13)
je 0x7c064
movq %rbx, %rdi
movl %r12d, %esi
callq 0x47301
movq %rax, 0x48(%rsp)
pushq $0x28
popq %rdi
movq %r14, %rsi
callq 0x4150
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movslq 0x20(%rax,%r13), %rcx
cmpq %rcx, %r15
jge 0x7bf45
movq 0x48(%rsp), %rcx
movslq (%rcx,%r15,4), %rcx
imulq $0x48, %rcx, %rcx
movq (%rax,%rcx), %rdx
movq %r14, %rdi
leaq 0x24e76(%rip), %rsi     # 0xa0daf
xorl %eax, %eax
callq 0x42e0
incq %r15
jmp 0x7bf10
movq %r12, 0x50(%rsp)
leaq 0x24e62(%rip), %rdi     # 0xa0db3
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
cmpq %rbp, 0x28(%rax,%r13)
jle 0x7c03e
pushq $0x28
popq %rdi
movq %r14, %rsi
callq 0x4150
movq 0x8(%rbx), %rsi
addq %r13, %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %ebp, %edi
callq 0x4727f
movq %rax, %r12
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movslq 0x20(%rax,%r13), %rcx
cmpq %rcx, %r15
jge 0x7bfd6
movq 0x48(%rsp), %rcx
movslq (%rcx,%r15,4), %rcx
imulq $0x48, %rcx, %rcx
movq 0x8(%rax,%rcx), %rax
movslq (%r12,%r15,4), %rcx
movq (%rax,%rcx,8), %rdx
movq %r14, %rdi
leaq 0x24de5(%rip), %rsi     # 0xa0daf
xorl %eax, %eax
callq 0x42e0
incq %r15
jmp 0x7bf98
pushq $0x29
popq %rdi
movq %r14, %rsi
callq 0x4150
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r13), %rcx
cmpq %rcx, %r15
jge 0x7c019
addq %r13, %rax
movq 0x38(%rax), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r15,8), %xmm0
movq %r14, %rdi
leaq 0x250c8(%rip), %rsi     # 0xa10d5
movb $0x1, %al
callq 0x42e0
incq %r15
jmp 0x7bfe4
leaq 0x24d84(%rip), %rdi     # 0xa0da4
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
movq %r12, %rdi
callq 0x34ff7
incq %rbp
jmp 0x7bf61
leaq 0x24d5f(%rip), %rdi     # 0xa0da4
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
movq 0x48(%rsp), %rdi
callq 0x34ff7
movq 0x50(%rsp), %r12
jmp 0x7c0bb
pushq $0x28
popq %rdi
movq %r14, %rsi
callq 0x4150
xorl %r15d, %r15d
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r13), %rcx
cmpq %rcx, %r15
jge 0x7c0a6
addq %r13, %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movsd (%rax,%r15,8), %xmm0
movq %r14, %rdi
leaq 0x2503b(%rip), %rsi     # 0xa10d5
movb $0x1, %al
callq 0x42e0
incq %r15
jmp 0x7c072
leaq 0x24cf7(%rip), %rdi     # 0xa0da4
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
incq %r12
movl 0x10(%rbx), %eax
jmp 0x7beba
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