// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/network.c
// Function: find_edges
double **find_edges(bayesiangraphptr mygraph,double threshold,int *edgecount)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 13.03.2001*/
 int i,j,k,l,found,total=(mygraph->nodecount)*(mygraph->nodecount-1)/2;
 double **sorted=sort_independence(mygraph),thrhold,**edges=NULL;
 int ind1,ind2,pos1,pos2,**connected_components,*component_counts;
 connected_components = safemalloc (mygraph->nodecount * sizeof(int *), "find_edges", 4);
 component_counts = safemalloc (mygraph->nodecount * sizeof(int), "find_edges", 5);
 *edgecount=0;
 for (i = 0; i < mygraph->nodecount; i++)
  {
   component_counts[i]=1;
   connected_components[i] = (int *) safemalloc (sizeof(int), "find_edges", 10);
   connected_components[i][0]=i;
  }
 for (i=0;i<total;i++)
  {
   j = (int) sorted[i][0];
   k = (int) sorted[i][1];
   found=0;
   for (l=0;l<mygraph->nodecount;l++)/*One independence lara bakiyorum*/
     if ((l!=j)&&(l!=k)&&(mygraph->one_independence[j][k][l]<1-threshold))
      {
       found=1;
       break;
      }
   if (!found)
    {
     (*edgecount)++;
     edges=alloc(edges,(*edgecount)*sizeof(double *),*edgecount);
     edges[(*edgecount)-1] = safemalloc(2*sizeof(double), "find_edges", 28);
     edges[(*edgecount)-1][0]=j;
     edges[(*edgecount)-1][1]=k;
     ind1=j;
     ind2=k;
     pos1=-1;
     pos2=-1;
     j=0;
     l=0;
     while (j<mygraph->nodecount)
      {
       for (k=0;k<component_counts[j];k++)
        {
         if (connected_components[j][k]==ind1)
           pos1=j;
         if (connected_components[j][k]==ind2)
           pos2=j;
        }
       if (component_counts[j]>0)
         l++;
       j++;
      }
     if (l==1)
      {
       thrhold = sorted[i][2];
       break;
      }
     if (pos1!=pos2)
      {
       connected_components[pos1] = alloc(connected_components[pos1], (component_counts[pos1] + component_counts[pos2]) * sizeof(int), component_counts[pos1] + component_counts[pos2]);
       for (j=0;j<component_counts[pos2];j++)
         connected_components[pos1][component_counts[pos1]+j]=connected_components[pos2][j];
       component_counts[pos1]+=component_counts[pos2];
       component_counts[pos2]=0;
      }
    }
  }
 i++;  
 while (i < total && sorted[i][2] == thrhold)
  {
   j = (int) sorted[i][0];
   k = (int) sorted[i][1];
   found = 0;
   for (l = 0; l < mygraph->nodecount; l++)
     if ((l != j) && (l != k) && (mygraph->one_independence[j][k][l] < 1-threshold)){
       found = 1;
       break;
     }
   if (!found)
    {
     (*edgecount)++;
     edges=alloc(edges,(*edgecount)*sizeof(double *),*edgecount);
     edges[(*edgecount)-1] = safemalloc(2*sizeof(double), "find_edges", 80);
     edges[(*edgecount)-1][0]=j;
     edges[(*edgecount)-1][1]=k;
    }
   i++;
  }
	free_2d((void**)connected_components, mygraph->nodecount);
 safe_free(component_counts);
	free_2d((void**)sorted, total);
 return edges;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
imull %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
callq 0x712f0
movq %rax, -0x38(%rbp)
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x75a36(%rip), %rsi     # 0xe7292
movl $0x4, %edx
callq 0x52d70
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rax
movslq 0x10(%rax), %rdi
shlq $0x2, %rdi
leaq 0x75a15(%rip), %rsi     # 0xe7292
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x718f8
movq -0x68(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl $0x4, %edi
leaq 0x759cf(%rip), %rsi     # 0xe7292
movl $0xa, %edx
callq 0x52d70
movq %rax, %rdx
movq -0x60(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %ecx
movq -0x60(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x7189c
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x71c0d
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x719a6
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x71999
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x71999
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x70693(%rip), %xmm0    # 0xe2018
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x71999
movl $0x1, -0x2c(%rbp)
jmp 0x719a6
jmp 0x7199b
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x71940
cmpl $0x0, -0x2c(%rbp)
jne 0x71bfd
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq (%rax), %rsi
shlq $0x3, %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
callq 0x52d10
movq %rax, -0x48(%rbp)
movl $0x10, %edi
leaq 0x758ad(%rip), %rsi     # 0xe7292
movl $0x1c, %edx
callq 0x52d70
movq %rax, %rdx
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
cvtsi2sdl -0x20(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
cvtsi2sdl -0x24(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x8(%rax)
movl -0x20(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0xffffffff, -0x54(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x58(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x71afe
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x68(%rbp), %rcx
movslq -0x20(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x71ad9
movq -0x60(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x4c(%rbp), %eax
jne 0x71aae
movl -0x20(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x60(%rbp), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl -0x50(%rbp), %eax
jne 0x71acc
movl -0x20(%rbp), %eax
movl %eax, -0x58(%rbp)
jmp 0x71ace
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x71a80
movq -0x68(%rbp), %rax
movslq -0x20(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x71af0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x71a69
cmpl $0x1, -0x28(%rbp)
jne 0x71b1f
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x71c0d
movl -0x54(%rbp), %eax
cmpl -0x58(%rbp), %eax
je 0x71bfb
movq -0x60(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x68(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x68(%rbp), %rcx
movslq -0x58(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movslq %eax, %rsi
shlq $0x2, %rsi
movq -0x68(%rbp), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movslq -0x58(%rbp), %rcx
addl (%rax,%rcx,4), %edx
callq 0x52d10
movq %rax, %rdx
movq -0x60(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x68(%rbp), %rcx
movslq -0x58(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x71bd3
movq -0x60(%rbp), %rax
movslq -0x58(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x20(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x60(%rbp), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x68(%rbp), %rcx
movslq -0x54(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x71b85
movq -0x68(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq -0x68(%rbp), %rax
movslq -0x54(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movq -0x68(%rbp), %rax
movslq -0x58(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
jmp 0x71bfd
jmp 0x71bff
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x718ff
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x30(%rbp), %ecx
movb %al, -0x69(%rbp)
jge 0x71c44
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x10(%rax), %xmm0
ucomisd -0x40(%rbp), %xmm0
sete %al
setnp %cl
andb %cl, %al
movb %al, -0x69(%rbp)
movb -0x69(%rbp), %al
testb $0x1, %al
jne 0x71c50
jmp 0x71d94
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cvttsd2si 0x8(%rax), %eax
movl %eax, -0x24(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x71ceb
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
je 0x71cde
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x71cde
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x28(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x7034e(%rip), %xmm0    # 0xe2018
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x71cde
movl $0x1, -0x2c(%rbp)
jmp 0x71ceb
jmp 0x71ce0
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x71c85
cmpl $0x0, -0x2c(%rbp)
jne 0x71d86
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rax
movslq (%rax), %rsi
shlq $0x3, %rsi
movq -0x18(%rbp), %rax
movl (%rax), %edx
callq 0x52d10
movq %rax, -0x48(%rbp)
movl $0x10, %edi
leaq 0x75568(%rip), %rsi     # 0xe7292
movl $0x50, %edx
callq 0x52d70
movq %rax, %rdx
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
cvtsi2sdl -0x20(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, (%rax)
cvtsi2sdl -0x24(%rbp), %xmm0
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x8(%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x71c16
movq -0x60(%rbp), %rdi
movq -0x8(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x52e20
movq -0x68(%rbp), %rdi
callq 0x52e80
movq -0x38(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x52e20
movq -0x48(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)