// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/ordering.c
// Function: min_table_ordering
void min_table_ordering(bayesiangraphptr mygraph, double **edges, int edgecount)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 13.03.2001*/
 int i, j, k, orderno, minindex;
 double *table_counts, min;
	table_counts = safemalloc(mygraph->nodecount * sizeof(double), "min_table_ordering", 3);
 if (mygraph->ordering)
   safe_free(mygraph->ordering);
 mygraph->ordering = safemalloc(mygraph->nodecount * sizeof(int), "min_table_ordering", 6);
 /* Step 1 */
 for (i = 0; i < mygraph->nodecount; i++)
   table_counts[i] = mygraph->nodes[i].value_count;
 for (i = 0; i < edgecount; i++)
  {
   j = (int) edges[i][0];
   k = (int) edges[i][1];
   table_counts[j] *= mygraph->nodes[k].value_count;
   table_counts[k] *= mygraph->nodes[j].value_count;
  }
 /* Step 2 */
 orderno = mygraph->nodecount - 1;
 while (orderno >= 0)
  {
   /* Step 3 */
   min = LONG_MAX;
   for (i = 0; i < mygraph->nodecount; i++)
     if (table_counts[i] < min)
      {
       min = table_counts[i];
       minindex = i;
      }
   /* Step 4 */
   mygraph->ordering[minindex] = orderno;
   table_counts[minindex] = LONG_MAX;
   /* Step 5 */
   for (i = 0; i < edgecount; i++)
    {
     j = (int) edges[i][0];
     k = (int) edges[i][1];
     if (j == minindex)
       table_counts[k] /= mygraph->nodes[j].value_count;
     else
       if (k == minindex)
         table_counts[j] /= mygraph->nodes[k].value_count;
    }
   /* Step 6 */
   orderno--;
  }
	safe_free(table_counts);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x6ed44(%rip), %rsi     # 0xe754a
movl $0x3, %edx
callq 0x52d70
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0x7882c
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x52e80
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
shlq $0x2, %rdi
leaq 0x6ed0b(%rip), %rsi     # 0xe754a
movl $0x6, %edx
callq 0x52d70
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x40(%rax)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x78897
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x18(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x7885b
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x78933
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x10(%rax), %xmm0
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x7889e
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
subl $0x1, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x78a96
movsd 0x6a65e(%rip), %xmm0    # 0xe2fb0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x789a7
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7899a
movq -0x30(%rbp), %rax
movslq -0x18(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x28(%rbp)
jmp 0x7899c
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x7895e
movl -0x24(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
movslq -0x28(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movslq -0x28(%rbp), %rcx
movsd 0x6a5e7(%rip), %xmm0    # 0xe2fb0
movsd %xmm0, (%rax,%rcx,8)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x78a88
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si 0x8(%rax), %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x78a40
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x10(%rax), %xmm1
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x78a78
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x78a76
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x20(%rbp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
cvtsi2sdl 0x10(%rax), %xmm1
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x78a78
jmp 0x78a7a
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x789d5
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x78940
movq -0x30(%rbp), %rdi
callq 0x52e80
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)