// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, %rax
movq %rdi, %r13
leaq 0x22042(%rip), %rsi     # 0xa88a1
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x86c06
movq %rax, %rbx
movq (%r13), %rdx
leaq 0x27505(%rip), %rsi     # 0xadd83
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
cmpl $0x0, 0x10(%r13)
jle 0x8691c
leaq 0x27519(%rip), %r12     # 0xaddb3
xorl %ebp, %ebp
movq 0x8(%r13), %rax
leaq (,%rbp,8), %rcx
leaq (%rcx,%rcx,8), %r15
movq (%rax,%r15), %rdx
movq %rbx, %rdi
leaq 0x274e3(%rip), %rsi     # 0xadd9d
xorl %eax, %eax
callq 0x42e0
movq 0x8(%r13), %rax
cmpl $0x0, 0x10(%rax,%r15)
jle 0x868f7
xorl %r14d, %r14d
movq 0x8(%rax,%r15), %rax
movq (%rax,%r14,8), %rdx
movq %rbx, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%r13), %rax
movslq 0x10(%rax,%r15), %rcx
cmpq %rcx, %r14
jl 0x868d0
movl $0x3, %esi
movl $0x1, %edx
leaq 0x2749f(%rip), %rdi     # 0xadda7
movq %rbx, %rcx
callq 0x42c0
incq %rbp
movslq 0x10(%r13), %rax
cmpq %rax, %rbp
jl 0x8689c
cmpl $0x0, 0x10(%r13)
movq %rbx, %r12
jle 0x86bf0
movq %r13, %rbx
leaq 0x277a5(%rip), %r15     # 0xae0d9
leaq 0x27478(%rip), %rbp     # 0xaddb3
xorl %r13d, %r13d
movq 0x8(%rbx), %rax
leaq (,%r13,8), %rcx
leaq (%rcx,%rcx,8), %r14
movq (%rax,%r14), %rdx
movq %r12, %rdi
leaq 0x2744f(%rip), %rsi     # 0xaddab
xorl %eax, %eax
callq 0x42e0
movq 0x8(%rbx), %rax
movq %r14, 0x48(%rsp)
cmpl $0x0, 0x20(%rax,%r14)
je 0x86b6b
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4d0d4
movq %rax, %r15
movl $0x28, %edi
movq %r12, %rsi
callq 0x4150
movq 0x8(%rbx), %rax
movq %r13, 0x60(%rsp)
leaq (%r13,%r13,8), %r13
cmpl $0x0, 0x20(%rax,%r13,8)
jle 0x869d6
xorl %r14d, %r14d
movslq (%r15,%r14,4), %rcx
leaq (%rcx,%rcx,8), %rcx
movq (%rax,%rcx,8), %rdx
movq %r12, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movslq 0x20(%rax,%r13,8), %rcx
cmpq %rcx, %r14
jl 0x869ac
movq %r15, 0x58(%rsp)
movl $0x3, %esi
movl $0x1, %edx
leaq 0x273cb(%rip), %rdi     # 0xaddb7
movq %r12, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
cmpq $0x0, 0x28(%rax,%r13,8)
jle 0x86b3a
xorl %r15d, %r15d
movq %r13, 0x50(%rsp)
movl $0x28, %edi
movq %r12, %rsi
callq 0x4150
movq 0x8(%rbx), %rsi
movq 0x48(%rsp), %r14
addq %r14, %rsi
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %r15, 0x70(%rsp)
movl %r15d, %edi
callq 0x4d03e
movq %rax, %r13
movq 0x8(%rbx), %rax
cmpl $0x0, 0x20(%rax,%r14)
movq %rbp, %r15
movq 0x58(%rsp), %rbp
jle 0x86a91
xorl %r14d, %r14d
movslq (%rbp,%r14,4), %rcx
leaq (%rcx,%rcx,8), %rcx
movq 0x8(%rax,%rcx,8), %rax
movslq (%r13,%r14,4), %rcx
movq (%rax,%rcx,8), %rdx
movq %r12, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movq 0x50(%rsp), %rcx
movslq 0x20(%rax,%rcx,8), %rcx
cmpq %rcx, %r14
jl 0x86a57
movq %r13, 0x68(%rsp)
movl $0x29, %edi
movq %r12, %rsi
callq 0x4150
movq 0x8(%rbx), %rax
movq 0x50(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
leaq 0x27621(%rip), %rbp     # 0xae0d9
movq 0x48(%rsp), %rdx
movq 0x70(%rsp), %r15
jle 0x86af9
xorl %r14d, %r14d
movq 0x38(%rax,%rdx), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r14,8), %xmm0
movq %r12, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x42e0
movq 0x48(%rsp), %rdx
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%rdx), %rcx
cmpq %rcx, %r14
jl 0x86ac7
movl $0x2, %esi
movl $0x1, %edx
leaq 0x2729e(%rip), %rdi     # 0xadda8
movq %r12, %rcx
callq 0x42c0
movq 0x68(%rsp), %rdi
callq 0x39194
incq %r15
movq 0x8(%rbx), %rax
movq 0x50(%rsp), %r13
cmpq %r15, 0x28(%rax,%r13,8)
leaq 0x2727f(%rip), %rbp     # 0xaddb3
jg 0x86a0c
movl $0x2, %esi
movl $0x1, %edx
leaq 0x2725d(%rip), %rdi     # 0xadda8
movq %r12, %rcx
callq 0x42c0
movq 0x58(%rsp), %rdi
callq 0x39194
leaq 0x27575(%rip), %r15     # 0xae0d9
movq 0x60(%rsp), %r13
jmp 0x86be0
movl $0x28, %edi
movq %r12, %rsi
callq 0x4150
movq 0x8(%rbx), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
movq 0x48(%rsp), %rdx
jle 0x86bc7
xorl %r14d, %r14d
movq 0x38(%rax,%rdx), %rax
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm0
movq %r12, %rdi
movq %r15, %rsi
movb $0x1, %al
callq 0x42e0
movq 0x48(%rsp), %rdx
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%rdx), %rcx
cmpq %rcx, %r14
jl 0x86b96
movl $0x2, %esi
movl $0x1, %edx
leaq 0x271d0(%rip), %rdi     # 0xadda8
movq %r12, %rcx
callq 0x42c0
incq %r13
movslq 0x10(%rbx), %rax
cmpq %rax, %r13
jl 0x8693e
movq %r12, %rdi
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x42a0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq