// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/network.c
// Function: connected
int connected(bayesiangraphptr mygraph)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 25.02.2001*/
 int found=0,i,j,k,l,**connected_components,*component_counts;
 int pos,pos1,pos2,ind1,ind2;
 connected_components = safemalloc (mygraph->nodecount * sizeof(int *), "connected", 3);
 component_counts = safemalloc (mygraph->nodecount * sizeof(int), "connected", 4);
 for (i = 0; i < mygraph->nodecount; i++)
  {
   component_counts[i]=1;
   connected_components[i] = (int *) safemalloc (sizeof(int), "connected", 8);
   connected_components[i][0]=i;
  }
 for (i=0;i<mygraph->nodecount;i++)
  {
   pos=mygraph->nodes[i].pointer;
   while (pos!=-1)
    {
     ind1=i;
     ind2=mygraph->dest[pos];
     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)
      {
       found=1;
       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;
      }
     pos=mygraph->arcs[pos].pointer;
    }
  }
 if (!found)
  {
   k=0;
   for (i=0;i<mygraph->nodecount;i++)
     if (component_counts[i]>0)
       k++;
   if (k==1)
     found=1;
  }
	free_2d((void**)connected_components, mygraph->nodecount);
 safe_free(component_counts);
 return found;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r14
movslq 0x10(%rdi), %rdi
shlq $0x3, %rdi
leaq 0x4fc2e(%rip), %r12     # 0x9776c
pushq $0x3
popq %rdx
movq %r12, %rsi
callq 0x34f59
movq %rax, %rbx
movq %r14, 0x8(%rsp)
movslq 0x10(%r14), %rdi
shlq $0x2, %rdi
pushq $0x4
popq %rdx
movq %r12, %rsi
callq 0x34f59
movq %rax, %r14
xorl %r15d, %r15d
pushq $0x4
popq %r13
pushq $0x8
popq %rbp
movq 0x8(%rsp), %rax
movslq 0x10(%rax), %rsi
cmpq %rsi, %r15
jge 0x47ba0
movl $0x1, (%r14,%r15,4)
movq %r13, %rdi
movq %r12, %rsi
movl %ebp, %edx
callq 0x34f59
movq %rax, (%rbx,%r15,8)
movl %r15d, (%rax)
incq %r15
jmp 0x47b71
xorl %r12d, %r12d
movl $0x0, 0x14(%rsp)
movslq %esi, %rax
cmpq %rax, %r12
jge 0x47cc7
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
imulq $0x48, %r12, %rcx
leaq (%rax,%rcx), %r13
addq $0x30, %r13
movslq (%r13), %r13
cmpq $-0x1, %r13
je 0x47cbf
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
xorl %edx, %edx
testl %esi, %esi
movl $0x0, %edi
cmovgl %esi, %edi
movl (%rax,%r13,4), %r8d
xorl %r9d, %r9d
pushq $-0x1
popq %rax
movl %eax, %ecx
cmpq %rdi, %rdx
je 0x47c45
movl (%r14,%rdx,4), %r10d
testl %r10d, %r10d
movl $0x0, %r11d
cmovgl %r10d, %r11d
xorl %r15d, %r15d
cmpq %r15, %r11
je 0x47c33
movq (%rbx,%rdx,8), %rbp
movl (%rbp,%r15,4), %ebp
cmpq %rbp, %r12
cmovel %edx, %ecx
cmpl %r8d, %ebp
cmovel %edx, %eax
incq %r15
jmp 0x47c14
xorl %r11d, %r11d
testl %r10d, %r10d
setg %r11b
addl %r11d, %r9d
incq %rdx
jmp 0x47bfb
cmpl $0x1, %r9d
je 0x47cb8
cmpl %eax, %ecx
je 0x47ca6
movslq %ecx, %rbp
movq (%rbx,%rbp,8), %rdi
movslq (%r14,%rbp,4), %rcx
movslq %eax, %r15
movslq (%r14,%r15,4), %rdx
addq %rcx, %rdx
movq %rdx, %rsi
shlq $0x2, %rsi
callq 0x34f30
movq %rax, (%rbx,%rbp,8)
xorl %ecx, %ecx
movslq (%r14,%r15,4), %rdx
cmpq %rdx, %rcx
jge 0x47c95
movq (%rbx,%r15,8), %rdx
movl (%rdx,%rcx,4), %edx
movslq (%r14,%rbp,4), %rsi
addq %rcx, %rsi
movl %edx, (%rax,%rsi,4)
incq %rcx
jmp 0x47c76
addl %edx, (%r14,%rbp,4)
andl $0x0, (%r14,%r15,4)
movq 0x8(%rsp), %rax
movl 0x10(%rax), %esi
shlq $0x2, %r13
movq 0x8(%rsp), %rax
addq 0x18(%rax), %r13
jmp 0x47bcc
pushq $0x1
popq %rax
movl %eax, 0x14(%rsp)
incq %r12
jmp 0x47bab
cmpl $0x0, 0x14(%rsp)
je 0x47cd3
pushq $0x1
popq %rbp
jmp 0x47d01
xorl %eax, %eax
testl %esi, %esi
movl $0x0, %ecx
cmovgl %esi, %ecx
xorl %edx, %edx
cmpq %rax, %rcx
je 0x47cf8
xorl %edi, %edi
cmpl $0x0, (%r14,%rax,4)
setg %dil
addl %edi, %edx
incq %rax
jmp 0x47ce1
xorl %ebp, %ebp
cmpl $0x1, %edx
sete %bpl
movq %rbx, %rdi
callq 0x34fc3
movq %r14, %rdi
callq 0x34ff7
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq