// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/savenet.c
// Function: save_graph_xml
void save_graph_xml(bayesiangraphptr mygraph, char *file_name)
{
/*!Last Changed 28.12.2000*/
 FILE *myfile;
 int i, j, k, *list, *valuelist;
 myfile = fopen(file_name, "w");
	if (!myfile)
		 return;
 fprintf(myfile, "<ANALYSISNOTEBOOK NAME=\"%s\"\n", mygraph->name);
 fprintf(myfile, "                  ROOT=\"%s\">\n", mygraph->name);
 fprintf(myfile, "   <BNMODEL NAME=\"%s\">\n", mygraph->name);
 fprintf(myfile, "      <STATICPROPERTIES>\n");
 fprintf(myfile, "         <FORMAT VALUE=\"MSR DTAS XML\"/>\n");
 fprintf(myfile, "         <VERSION VALUE=\"0.2\"/>\n");
 fprintf(myfile, "         <CREATOR VALUE=\"Bayesian Learner\"/>\n");
 fprintf(myfile, "      </STATICPROPERTIES>\n");
 fprintf(myfile, "      <VARIABLES>\n");
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "         <VAR NAME=\"%s\" TYPE=\"discrete\" XPOS=\"%d\" YPOS=\"%d\">\n", mygraph->nodes[i].name, mygraph->nodes[i].xpos, mygraph->nodes[i].ypos);
   fprintf(myfile, "            <DESCRIPTION></DESCRIPTION>\n");
   for (j = 0; j < mygraph->nodes[i].value_count; j++)
     fprintf(myfile, "            <STATENAME>%s</STATENAME>\n", mygraph->nodes[i].values[j]);
   fprintf(myfile, "         </VAR>\n");
  }
 fprintf(myfile, "      </VARIABLES>\n");
 fprintf(myfile, "      <STRUCTURE>\n");
 for (i = 0; i < mygraph->nodecount; i++)
   for (j = 0; j < mygraph->nodes[i].parents; j++)
    {
     k = parent_index(mygraph, i, j);
     fprintf(myfile, "         <ARC PARENT=\"%s\" CHILD=\"%s\"/>\n", mygraph->nodes[k].name, mygraph->nodes[i].name);
    }
 fprintf(myfile, "      </STRUCTURE>\n");
 fprintf(myfile, "      <DISTRIBUTIONS>\n");
 for (i = 0; i < mygraph->nodecount; i++)
  {
   fprintf(myfile, "         <DIST TYPE=\"discrete\">\n");
   if (mygraph->nodes[i].parents > 0)
    {
     fprintf(myfile, "            <CONDSET>\n");
     for (j = 0; j < mygraph->nodes[i].parents; j++)
      {
       k = parent_index(mygraph, i, j);
       fprintf(myfile, "               <CONDELEM NAME=\"%s\"/>\n", mygraph->nodes[k].name);
      }
     fprintf(myfile, "            </CONDSET>\n");
    }
   fprintf(myfile, "            <PRIVATE NAME=\"%s\"/>\n", mygraph->nodes[i].name);
   fprintf(myfile, "            <DPIS>\n");
   if (mygraph->nodes[i].parents == 0)
    {
     fprintf(myfile, "               <DPI>");
     for (j = 0; j < mygraph->nodes[i].value_count; j++)
       fprintf(myfile, " %.4f", mygraph->nodes[i].table[0][j]);
     fprintf(myfile, " <\\DPI>\n");
    }
   else
    {
     list = find_parents(mygraph, i);/*Print parents*/
     for (j = 0; j < mygraph->nodes[i].table_count; j++)
      {
       fprintf(myfile, "               <DPI INDEXES=\"");
       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, "</DPI>\n");  
       safe_free(valuelist);
      }
     safe_free(list);
    }
   fprintf(myfile, "            </DPIS>\n");
   fprintf(myfile, "         </DIST>\n");
  }
 fprintf(myfile, "      </DISTRIBUTIONS>\n");
 fprintf(myfile, "   </BNMODEL>\n");
 fprintf(myfile, "</ANALYSISNOTEBOOK>\n");
 fclose(myfile);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rax
movq %rdi, %r14
leaq 0x1f78b(%rip), %rsi     # 0x9b891
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x7c651
movq %rax, %rbx
movq (%r14), %rdx
leaq 0x24c93(%rip), %rsi     # 0xa0db7
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
movq (%r14), %rdx
leaq 0x24c9c(%rip), %rsi     # 0xa0dd4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x42e0
movq %r14, 0x48(%rsp)
movq (%r14), %rdx
leaq 0x24ca1(%rip), %rsi     # 0xa0df2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x42e0
leaq 0x24ca8(%rip), %rdi     # 0xa0e0a
pushq $0x19
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24ca9(%rip), %rdi     # 0xa0e24
pushq $0x28
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24cbd(%rip), %rdi     # 0xa0e4d
pushq $0x20
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24cc9(%rip), %rdi     # 0xa0e6e
pushq $0x2d
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24ce2(%rip), %rdi     # 0xa0e9c
pushq $0x1a
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24ce8(%rip), %rdi     # 0xa0eb7
pushq $0x12
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24d4d(%rip), %r12     # 0xa0f31
xorl %r13d, %r13d
movq %rbx, %r14
movq 0x48(%rsp), %rcx
movslq 0x10(%rcx), %rax
cmpq %rax, %r13
jge 0x7c289
movq 0x8(%rcx), %rax
imulq $0x48, %r13, %rbp
movq (%rax,%rbp), %rdx
movl 0x40(%rax,%rbp), %ecx
movl 0x44(%rax,%rbp), %r8d
movq %rbx, %rdi
leaq 0x24caf(%rip), %rsi     # 0xa0eca
xorl %eax, %eax
callq 0x42e0
leaq 0x24cdf(%rip), %rdi     # 0xa0f08
pushq $0x28
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
xorl %ebx, %ebx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x10(%rax,%rbp), %rcx
cmpq %rcx, %rbx
jge 0x7c269
addq %rbp, %rax
movq 0x8(%rax), %rax
movq (%rax,%rbx,8), %rdx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x42e0
incq %rbx
jmp 0x7c239
leaq 0x24ce8(%rip), %rdi     # 0xa0f58
pushq $0x10
popq %rsi
movq %r15, %rdx
movq %r14, %rbx
movq %r14, %rcx
callq 0x42c0
incq %r13
jmp 0x7c1ea
leaq 0x24cd9(%rip), %rdi     # 0xa0f69
pushq $0x13
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24cd4(%rip), %rdi     # 0xa0f7d
pushq $0x12
popq %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x42c0
xorl %r15d, %r15d
movq 0x48(%rsp), %r12
movq 0x48(%rsp), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r15
jge 0x7c319
imulq $0x48, %r15, %r13
xorl %ebp, %ebp
movq 0x8(%r12), %rax
cmpl 0x20(%rax,%r13), %ebp
jge 0x7c314
movq %r12, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x47365
movq 0x8(%r12), %rcx
cltq
imulq $0x48, %rax, %rax
movq (%rcx,%rax), %rdx
movq (%rcx,%r13), %rcx
movq %rbx, %rdi
leaq 0x24c87(%rip), %rsi     # 0xa0f90
xorl %eax, %eax
callq 0x42e0
incl %ebp
jmp 0x7c2d3
incq %r15
jmp 0x7c2bf
leaq 0x24c98(%rip), %rdi     # 0xa0fb8
pushq $0x13
popq %rsi
pushq $0x1
popq %r12
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24c93(%rip), %rdi     # 0xa0fcc
pushq $0x16
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24d56(%rip), %rbp     # 0xa10a4
xorl %r13d, %r13d
movq 0x48(%rsp), %r15
movslq 0x10(%r15), %rax
cmpq %rax, %r13
jge 0x7c5f8
leaq 0x24c79(%rip), %rdi     # 0xa0fe3
pushq $0x20
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x8(%r15), %rax
movq %r13, 0x50(%rsp)
imulq $0x48, %r13, %r13
cmpl $0x0, 0x20(%rax,%r13)
jle 0x7c401
leaq 0x24c70(%rip), %rdi     # 0xa1004
pushq $0x16
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
xorl %ebp, %ebp
movq 0x8(%r15), %rax
cmpl 0x20(%rax,%r13), %ebp
jge 0x7c3e1
movq %r15, %rdi
movq 0x50(%rsp), %rsi
movl %ebp, %edx
callq 0x47365
movq 0x8(%r15), %rcx
cltq
imulq $0x48, %rax, %rax
movq (%rcx,%rax), %rdx
movq %rbx, %rdi
leaq 0x24c45(%rip), %rsi     # 0xa101b
xorl %eax, %eax
callq 0x42e0
incl %ebp
jmp 0x7c3a4
leaq 0x24c59(%rip), %rdi     # 0xa1041
pushq $0x17
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x8(%r15), %rax
leaq 0x24ca3(%rip), %rbp     # 0xa10a4
movq (%rax,%r13), %rdx
movq %rbx, %rdi
leaq 0x24c4a(%rip), %rsi     # 0xa1059
xorl %eax, %eax
callq 0x42e0
leaq 0x24c5e(%rip), %rdi     # 0xa107b
pushq $0x13
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x8(%r15), %rax
cmpl $0x0, 0x20(%rax,%r13)
je 0x7c563
movq %r15, %rdi
movq 0x50(%rsp), %rsi
callq 0x47301
movq %rax, %r15
xorl %r12d, %r12d
movq 0x48(%rsp), %rbp
movq 0x8(%rbp), %rax
cmpq %r12, 0x28(%rax,%r13)
jle 0x7c54b
leaq 0x24c4a(%rip), %rdi     # 0xa10b3
pushq $0x1d
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x8(%rbp), %rsi
addq %r13, %rsi
pushq $0x9
popq %rcx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movl %r12d, %edi
callq 0x4727f
movq %rax, %rbp
xorl %ebx, %ebx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x20(%rax,%r13), %rcx
cmpq %rcx, %rbx
jge 0x7c4d3
movslq (%r15,%rbx,4), %rcx
imulq $0x48, %rcx, %rcx
movq 0x8(%rax,%rcx), %rax
movslq (%rbp,%rbx,4), %rcx
movq (%rax,%rcx,8), %rdx
movq %r14, %rdi
leaq 0x248e8(%rip), %rsi     # 0xa0daf
xorl %eax, %eax
callq 0x42e0
incq %rbx
jmp 0x7c494
leaq 0x24bf7(%rip), %rdi     # 0xa10d1
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rcx
callq 0x42c0
xorl %ebx, %ebx
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x10(%rax,%r13), %rcx
cmpq %rcx, %rbx
jge 0x7c523
addq %r13, %rax
movq 0x38(%rax), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r14, %rdi
leaq 0x24bbd(%rip), %rsi     # 0xa10d4
movb $0x1, %al
callq 0x42e0
incq %rbx
jmp 0x7c4ea
leaq 0x24bb1(%rip), %rdi     # 0xa10db
pushq $0x7
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rbx
movq %r14, %rcx
callq 0x42c0
movq %rbp, %rdi
callq 0x34ff7
incq %r12
jmp 0x7c44e
movq %r15, %rdi
callq 0x34ff7
movq %rbp, %r15
pushq $0x1
popq %r12
leaq 0x24b43(%rip), %rbp     # 0xa10a4
jmp 0x7c5c1
leaq 0x24b25(%rip), %rdi     # 0xa108f
pushq $0x14
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
xorl %ebx, %ebx
movq 0x8(%r15), %rax
movslq 0x10(%rax,%r13), %rcx
cmpq %rcx, %rbx
jge 0x7c5a9
addq %r13, %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movsd (%rax,%rbx,8), %xmm0
movq %r14, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x42e0
incq %rbx
jmp 0x7c57a
leaq 0x24afa(%rip), %rdi     # 0xa10aa
pushq $0x8
popq %rsi
movq %r12, %rdx
movq %r14, %rbx
movq %r14, %rcx
callq 0x42c0
leaq 0x24b1b(%rip), %rdi     # 0xa10e3
pushq $0x14
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24b1b(%rip), %rdi     # 0xa10f8
pushq $0x11
popq %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x42c0
movq 0x50(%rsp), %r13
incq %r13
jmp 0x7c356
leaq 0x24b0b(%rip), %rdi     # 0xa110a
pushq $0x17
popq %rsi
pushq $0x1
popq %r14
movq %r14, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24b0a(%rip), %rdi     # 0xa1122
pushq $0xe
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x42c0
leaq 0x24b04(%rip), %rdi     # 0xa1131
pushq $0x14
popq %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x42c0
movq %rbx, %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