// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, %rax
movq %rdi, %rbx
leaq 0x21c71(%rip), %rsi     # 0xa88a1
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x87277
movq %rax, %r14
movq (%rbx), %rdx
leaq 0x2716d(%rip), %rsi     # 0xaddbb
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
movq (%rbx), %rdx
leaq 0x27176(%rip), %rsi     # 0xaddd8
movq %r14, %rdi
xorl %eax, %eax
callq 0x42e0
movq (%rbx), %rdx
leaq 0x27180(%rip), %rsi     # 0xaddf6
movq %r14, %rdi
xorl %eax, %eax
callq 0x42e0
leaq 0x27187(%rip), %rdi     # 0xade0e
movl $0x19, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27188(%rip), %rdi     # 0xade28
movl $0x28, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27198(%rip), %rdi     # 0xade51
movl $0x20, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x271a0(%rip), %rdi     # 0xade72
movl $0x2d, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x271b5(%rip), %rdi     # 0xadea0
movl $0x1a, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x271b7(%rip), %rdi     # 0xadebb
movl $0x12, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
cmpl $0x0, 0x10(%rbx)
jle 0x86dd6
leaq 0x2720e(%rip), %r13     # 0xadf35
xorl %ebp, %ebp
movq 0x8(%rbx), %rax
leaq (,%rbp,8), %rcx
leaq (%rcx,%rcx,8), %r15
movq (%rax,%r15), %rdx
movl 0x40(%rax,%r15), %ecx
movl 0x44(%rax,%r15), %r8d
movq %r14, %rdi
leaq 0x2717d(%rip), %rsi     # 0xadece
xorl %eax, %eax
callq 0x42e0
movl $0x28, %esi
movl $0x1, %edx
leaq 0x271a3(%rip), %rdi     # 0xadf0c
movq %r14, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
cmpl $0x0, 0x10(%rax,%r15)
movq %r14, %r12
jle 0x86daa
xorl %r14d, %r14d
movq 0x8(%rax,%r15), %rax
movq (%rax,%r14,8), %rdx
movq %r12, %rdi
movq %r13, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%rbx), %rax
movslq 0x10(%rax,%r15), %rcx
cmpq %rcx, %r14
jl 0x86d83
movl $0x10, %esi
movl $0x1, %edx
leaq 0x271a1(%rip), %rdi     # 0xadf5c
movq %r12, %rcx
callq 0x42c0
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
movq %r12, %r14
jl 0x86d29
leaq 0x27190(%rip), %rdi     # 0xadf6d
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x2718b(%rip), %rdi     # 0xadf81
movl $0x12, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
cmpl $0x0, 0x10(%rbx)
movq %rbx, %r13
jle 0x86e7c
xorl %r15d, %r15d
leaq 0x27179(%rip), %r12     # 0xadf94
movq 0x8(%r13), %rax
leaq (%r15,%r15,8), %rcx
cmpl $0x0, 0x20(%rax,%rcx,8)
jle 0x86e70
leaq (,%r15,8), %rax
leaq (%rax,%rax,8), %rbx
xorl %ebp, %ebp
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x4d140
movq 0x8(%r13), %rcx
cltq
leaq (%rax,%rax,8), %rax
movq (%rcx,%rax,8), %rdx
movq (%rcx,%rbx), %rcx
movq %r14, %rdi
movq %r12, %rsi
xorl %eax, %eax
callq 0x42e0
incl %ebp
movq 0x8(%r13), %rax
cmpl 0x20(%rax,%rbx), %ebp
jl 0x86e38
incq %r15
movslq 0x10(%r13), %rax
cmpq %rax, %r15
jl 0x86e1b
leaq 0x27139(%rip), %rdi     # 0xadfbc
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27134(%rip), %rdi     # 0xadfd0
movl $0x16, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
cmpl $0x0, 0x10(%r13)
jle 0x87216
leaq 0x2715f(%rip), %r15     # 0xae01f
leaq 0x271e1(%rip), %rbp     # 0xae0a8
xorl %r12d, %r12d
movl $0x20, %esi
movl $0x1, %edx
leaq 0x2710c(%rip), %rdi     # 0xadfe7
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
leaq (%r12,%r12,8), %rbx
cmpl $0x0, 0x20(%rax,%rbx,8)
jle 0x86f6c
movl $0x16, %esi
movl $0x1, %edx
leaq 0x27105(%rip), %rdi     # 0xae008
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%rbx,8)
jle 0x86f4c
xorl %ebp, %ebp
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x4d140
movq 0x8(%r13), %rcx
cltq
leaq (%rax,%rax,8), %rax
movq (%rcx,%rax,8), %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e0
incl %ebp
movq 0x8(%r13), %rax
cmpl 0x20(%rax,%rbx,8), %ebp
jl 0x86f18
movl $0x17, %esi
movl $0x1, %edx
leaq 0x270e8(%rip), %rdi     # 0xae045
movq %r14, %rcx
callq 0x42c0
leaq 0x2713c(%rip), %rbp     # 0xae0a8
movq %rbx, 0x48(%rsp)
movq 0x8(%r13), %rax
leaq (,%r12,8), %rcx
leaq (%rcx,%rcx,8), %r15
movq (%rax,%r15), %rdx
movq %r14, %rdi
leaq 0x270ce(%rip), %rsi     # 0xae05d
xorl %eax, %eax
callq 0x42e0
movl $0x13, %esi
movl $0x1, %edx
leaq 0x270d8(%rip), %rdi     # 0xae07f
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%r15)
movq %r12, 0x58(%rsp)
je 0x87151
movq %r13, %rdi
movl %r12d, %esi
callq 0x4d0d4
movq %rax, 0x50(%rsp)
movq 0x8(%r13), %rax
movq 0x48(%rsp), %rcx
cmpq $0x0, 0x28(%rax,%rcx,8)
jle 0x87137
xorl %ebp, %ebp
movq %r15, 0x60(%rsp)
movl $0x1d, %esi
movl $0x1, %edx
leaq 0x270b6(%rip), %rdi     # 0xae0b7
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rsi
addq %r15, %rsi
movl $0x9, %ecx
movq %rsp, %rdi
rep  movsq (%rsi), %es:(%rdi)
movq %rbp, 0x70(%rsp)
movl %ebp, %edi
callq 0x4d03e
movq %rax, %rbx
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%r15)
movq %r13, %r12
movq %r14, %r13
leaq 0x26d72(%rip), %r15     # 0xaddb3
movq 0x50(%rsp), %rbp
jle 0x87085
xorl %r14d, %r14d
movslq (%rbp,%r14,4), %rcx
leaq (%rcx,%rcx,8), %rcx
movq 0x8(%rax,%rcx,8), %rax
movslq (%rbx,%r14,4), %rcx
movq (%rax,%rcx,8), %rdx
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x42e0
incq %r14
movq 0x8(%r12), %rax
movq 0x48(%rsp), %rcx
movslq 0x20(%rax,%rcx,8), %rcx
cmpq %rcx, %r14
jl 0x8704b
movq %rbx, 0x68(%rsp)
movl $0x2, %esi
movl $0x1, %edx
leaq 0x2703a(%rip), %rdi     # 0xae0d5
movq %r13, %rcx
callq 0x42c0
movq 0x8(%r12), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
leaq 0x2701f(%rip), %rbx     # 0xae0d8
movq 0x60(%rsp), %r15
movq 0x70(%rsp), %rbp
jle 0x870f6
xorl %r14d, %r14d
movq 0x38(%rax,%r15), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r14,8), %xmm0
movq %r13, %rdi
movq %rbx, %rsi
movb $0x1, %al
callq 0x42e0
incq %r14
movq 0x8(%r12), %rax
movslq 0x10(%rax,%r15), %rcx
cmpq %rcx, %r14
jl 0x870c8
movl $0x7, %esi
movl $0x1, %edx
leaq 0x26fd8(%rip), %rdi     # 0xae0df
movq %r13, %rcx
callq 0x42c0
movq 0x68(%rsp), %rdi
callq 0x39194
incq %rbp
movq 0x8(%r12), %rax
movq 0x48(%rsp), %rcx
cmpq %rbp, 0x28(%rax,%rcx,8)
movq %r13, %r14
movq %r12, %r13
jg 0x86ff0
movq 0x50(%rsp), %rdi
callq 0x39194
leaq 0x26ed7(%rip), %r15     # 0xae01f
leaq 0x26f59(%rip), %rbp     # 0xae0a8
jmp 0x871cf
movl $0x14, %esi
movl $0x1, %edx
leaq 0x26f31(%rip), %rdi     # 0xae093
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
movq %r14, %rbx
jle 0x871ac
xorl %r14d, %r14d
movq 0x38(%rax,%r15), %rax
movq (%rax), %rax
movsd (%rax,%r14,8), %xmm0
movq %rbx, %rdi
movq %rbp, %rsi
movb $0x1, %al
callq 0x42e0
incq %r14
movq 0x8(%r13), %rax
movslq 0x10(%rax,%r15), %rcx
cmpq %rcx, %r14
jl 0x87180
movl $0x8, %esi
movl $0x1, %edx
leaq 0x26ef1(%rip), %rdi     # 0xae0ae
movq %rbx, %rcx
callq 0x42c0
movq %rbx, %r14
leaq 0x26e50(%rip), %r15     # 0xae01f
movl $0x14, %esi
movl $0x1, %edx
leaq 0x26f07(%rip), %rdi     # 0xae0e7
movq %r14, %rcx
callq 0x42c0
movl $0x11, %esi
movl $0x1, %edx
leaq 0x26f03(%rip), %rdi     # 0xae0fc
movq %r14, %rcx
callq 0x42c0
movq 0x58(%rsp), %r12
incq %r12
movslq 0x10(%r13), %rax
cmpq %rax, %r12
jl 0x86eca
leaq 0x26ef1(%rip), %rdi     # 0xae10e
movl $0x17, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x26ef0(%rip), %rdi     # 0xae126
movl $0xe, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x26ee6(%rip), %rdi     # 0xae135
movl $0x14, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
movq %r14, %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