// File: /workspace/github_c_makefile_star2_O3/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 0x224dc(%rip), %rsi     # 0xab96d
movq %rax, %rdi
callq 0x40f0
testq %rax, %rax
je 0x89adc
movq %rax, %r14
movq (%rbx), %rdx
leaq 0x279a4(%rip), %rsi     # 0xb0e53
movq %rax, %rdi
xorl %eax, %eax
callq 0x42e0
movq (%rbx), %rdx
leaq 0x279ad(%rip), %rsi     # 0xb0e70
movq %r14, %rdi
xorl %eax, %eax
callq 0x42e0
movq (%rbx), %rdx
leaq 0x279b7(%rip), %rsi     # 0xb0e8e
movq %r14, %rdi
xorl %eax, %eax
callq 0x42e0
leaq 0x279be(%rip), %rdi     # 0xb0ea6
movl $0x19, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279bf(%rip), %rdi     # 0xb0ec0
movl $0x28, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279cf(%rip), %rdi     # 0xb0ee9
movl $0x20, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279d7(%rip), %rdi     # 0xb0f0a
movl $0x2d, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279ec(%rip), %rdi     # 0xb0f38
movl $0x1a, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279ee(%rip), %rdi     # 0xb0f53
movl $0x12, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
cmpl $0x0, 0x10(%rbx)
jle 0x89637
leaq 0x27a45(%rip), %r13     # 0xb0fcd
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 0x279b4(%rip), %rsi     # 0xb0f66
xorl %eax, %eax
callq 0x42e0
movl $0x28, %esi
movl $0x1, %edx
leaq 0x279da(%rip), %rdi     # 0xb0fa4
movq %r14, %rcx
callq 0x42c0
movq 0x8(%rbx), %rax
cmpl $0x0, 0x10(%rax,%r15)
movq %r14, %r12
jle 0x8960b
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 0x895e4
movl $0x10, %esi
movl $0x1, %edx
leaq 0x279d8(%rip), %rdi     # 0xb0ff4
movq %r12, %rcx
callq 0x42c0
incq %rbp
movslq 0x10(%rbx), %rax
cmpq %rax, %rbp
movq %r12, %r14
jl 0x8958a
leaq 0x279c7(%rip), %rdi     # 0xb1005
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x279c2(%rip), %rdi     # 0xb1019
movl $0x12, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
movl 0x10(%rbx), %ecx
testl %ecx, %ecx
movq %rbx, %r13
jle 0x896e1
movq 0x8(%r13), %rax
xorl %r15d, %r15d
leaq 0x279ab(%rip), %r12     # 0xb102c
leaq (%r15,%r15,8), %rdx
cmpl $0x0, 0x20(%rax,%rdx,8)
jle 0x896d6
leaq (,%r15,8), %rax
leaq (%rax,%rax,8), %rbx
xorl %ebp, %ebp
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x4e5b4
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 0x8969a
movl 0x10(%r13), %ecx
incq %r15
movslq %ecx, %rdx
cmpq %rdx, %r15
jl 0x89681
leaq 0x2796c(%rip), %rdi     # 0xb1054
movl $0x13, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27967(%rip), %rdi     # 0xb1068
movl $0x16, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
cmpl $0x0, 0x10(%r13)
jle 0x89a7b
leaq 0x27992(%rip), %r15     # 0xb10b7
leaq 0x27a14(%rip), %rbp     # 0xb1140
xorl %r12d, %r12d
movl $0x20, %esi
movl $0x1, %edx
leaq 0x2793f(%rip), %rdi     # 0xb107f
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
leaq (%r12,%r12,8), %rbx
cmpl $0x0, 0x20(%rax,%rbx,8)
jle 0x897d5
movl $0x16, %esi
movl $0x1, %edx
leaq 0x27938(%rip), %rdi     # 0xb10a0
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%rbx,8)
jle 0x897b1
xorl %ebp, %ebp
movq %r13, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x4e5b4
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 0x8977d
movl $0x17, %esi
movl $0x1, %edx
leaq 0x2791b(%rip), %rdi     # 0xb10dd
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
leaq 0x2796b(%rip), %rbp     # 0xb1140
movq %rbx, 0x48(%rsp)
leaq (,%r12,8), %rcx
leaq (%rcx,%rcx,8), %r15
movq (%rax,%r15), %rdx
movq %r14, %rdi
leaq 0x27901(%rip), %rsi     # 0xb10f5
xorl %eax, %eax
callq 0x42e0
movl $0x13, %esi
movl $0x1, %edx
leaq 0x2790b(%rip), %rdi     # 0xb1117
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%r15)
movq %r12, 0x58(%rsp)
je 0x899b6
movq %r13, %rdi
movl %r12d, %esi
callq 0x4e548
movq %rax, 0x50(%rsp)
movq 0x8(%r13), %rax
movq 0x48(%rsp), %rcx
cmpq $0x0, 0x28(%rax,%rcx,8)
jle 0x8999c
xorl %ebp, %ebp
movq %r15, 0x60(%rsp)
movl $0x1d, %esi
movl $0x1, %edx
leaq 0x278e9(%rip), %rdi     # 0xb114f
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 0x4e4b2
movq %rax, %rbx
movq 0x8(%r13), %rax
cmpl $0x0, 0x20(%rax,%r15)
movq %r13, %r12
movq %r14, %r13
leaq 0x275a5(%rip), %r15     # 0xb0e4b
movq 0x50(%rsp), %rbp
jle 0x898ea
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 0x898b0
movq %rbx, 0x68(%rsp)
movl $0x2, %esi
movl $0x1, %edx
leaq 0x2786d(%rip), %rdi     # 0xb116d
movq %r13, %rcx
callq 0x42c0
movq 0x8(%r12), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
leaq 0x27852(%rip), %rbx     # 0xb1170
movq 0x60(%rsp), %r15
movq 0x70(%rsp), %rbp
jle 0x8995b
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 0x8992d
movl $0x7, %esi
movl $0x1, %edx
leaq 0x2780b(%rip), %rdi     # 0xb1177
movq %r13, %rcx
callq 0x42c0
movq 0x68(%rsp), %rdi
callq 0x3a180
incq %rbp
movq 0x8(%r12), %rax
movq 0x48(%rsp), %rcx
cmpq %rbp, 0x28(%rax,%rcx,8)
movq %r13, %r14
movq %r12, %r13
jg 0x89855
movq 0x50(%rsp), %rdi
callq 0x3a180
leaq 0x2770a(%rip), %r15     # 0xb10b7
leaq 0x2778c(%rip), %rbp     # 0xb1140
jmp 0x89a34
movl $0x14, %esi
movl $0x1, %edx
leaq 0x27764(%rip), %rdi     # 0xb112b
movq %r14, %rcx
callq 0x42c0
movq 0x8(%r13), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x10(%rax,%rcx,8)
movq %r14, %rbx
jle 0x89a11
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 0x899e5
movl $0x8, %esi
movl $0x1, %edx
leaq 0x27724(%rip), %rdi     # 0xb1146
movq %rbx, %rcx
callq 0x42c0
movq %rbx, %r14
leaq 0x27683(%rip), %r15     # 0xb10b7
movl $0x14, %esi
movl $0x1, %edx
leaq 0x2773a(%rip), %rdi     # 0xb117f
movq %r14, %rcx
callq 0x42c0
movl $0x11, %esi
movl $0x1, %edx
leaq 0x27736(%rip), %rdi     # 0xb1194
movq %r14, %rcx
callq 0x42c0
movq 0x58(%rsp), %r12
incq %r12
movslq 0x10(%r13), %rax
cmpq %rax, %r12
jl 0x8972f
leaq 0x27724(%rip), %rdi     # 0xb11a6
movl $0x17, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27723(%rip), %rdi     # 0xb11be
movl $0xe, %esi
movl $0x1, %edx
movq %r14, %rcx
callq 0x42c0
leaq 0x27719(%rip), %rdi     # 0xb11cd
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