// File: /workspace/github_c_makefile_star2_O3/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, %r12
movslq 0x10(%rdi), %rdi
shlq $0x3, %rdi
leaq 0x58969(%rip), %r14     # 0xa77e9
movq %r14, %rsi
movl $0x3, %edx
callq 0x3a0e1
movq %rax, %rbx
movslq 0x10(%r12), %rdi
shlq $0x2, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, %r14
movl 0x10(%r12), %esi
testl %esi, %esi
jle 0x4f06a
xorl %r15d, %r15d
movq %r12, %r13
leaq 0x58926(%rip), %r12     # 0xa77e9
movl $0x1, (%r14,%r15,4)
movl $0x4, %edi
movq %r12, %rsi
movl $0x8, %edx
callq 0x3a0e1
movq %rax, (%rbx,%r15,8)
movl %r15d, (%rax)
incq %r15
movslq 0x10(%r13), %rsi
cmpq %rsi, %r15
jl 0x4eec3
movq %r13, 0x10(%rsp)
testl %esi, %esi
jle 0x4f06a
movb $0x1, %al
xorl %r13d, %r13d
movq 0x10(%rsp), %r12
movl %eax, 0xc(%rsp)
movq 0x8(%r12), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
movl 0x30(%rax,%rcx,8), %eax
cmpl $-0x1, %eax
je 0x4f00e
movslq %eax, %rbp
movslq 0x10(%r12), %rsi
testq %rsi, %rsi
jle 0x4eff8
movq 0x28(%r12), %rax
movl (%rax,%rbp,4), %edx
xorl %edi, %edi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movslq (%r14,%rdi,4), %r9
testq %r9, %r9
jle 0x4ef78
movq (%rbx,%rdi,8), %r10
xorl %r11d, %r11d
movl (%r10,%r11,4), %r15d
cmpq %r15, %r13
cmovel %edi, %ecx
cmpl %edx, %r15d
cmovel %edi, %eax
incq %r11
cmpq %r11, %r9
jne 0x4ef60
xorl %r10d, %r10d
testl %r9d, %r9d
setg %r10b
addl %r10d, %r8d
incq %rdi
cmpq %rsi, %rdi
jne 0x4ef50
cmpl $0x1, %r8d
je 0x4f01f
cmpl %eax, %ecx
je 0x4eff8
movslq %ecx, %r12
movq (%rbx,%r12,8), %rdi
movslq (%r14,%r12,4), %rcx
movslq %eax, %r15
movslq (%r14,%r15,4), %rdx
addq %rcx, %rdx
movq %rdx, %rsi
shlq $0x2, %rsi
callq 0x3a0b4
movq %rax, (%rbx,%r12,8)
movl (%r14,%r15,4), %edx
testl %edx, %edx
jle 0x4efe7
movq (%rbx,%r15,8), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edx
movslq (%r14,%r12,4), %rdi
addq %rsi, %rdi
movl %edx, (%rax,%rdi,4)
incq %rsi
movslq (%r14,%r15,4), %rdx
cmpq %rdx, %rsi
jl 0x4efce
addl %edx, (%r14,%r12,4)
movl $0x0, (%r14,%r15,4)
movq 0x10(%rsp), %r12
movq 0x18(%r12), %rax
movl (%rax,%rbp,4), %eax
cmpl $-0x1, %eax
jne 0x4ef28
movl 0x10(%r12), %esi
incq %r13
movslq %esi, %rax
cmpq %rax, %r13
jl 0x4ef0b
jmp 0x4f034
incq %r13
xorl %eax, %eax
cmpq %rsi, %r13
jl 0x4ef07
movl $0x1, %ebp
jmp 0x4f06c
movl $0x1, %ebp
testb $0x1, 0xc(%rsp)
je 0x4f06c
testl %esi, %esi
jle 0x4f06a
movl %esi, %eax
xorl %ecx, %ecx
xorl %edx, %edx
xorl %edi, %edi
cmpl $0x0, (%r14,%rcx,4)
setg %dil
addl %edi, %edx
incq %rcx
cmpq %rcx, %rax
jne 0x4f04a
xorl %ebp, %ebp
cmpl $0x1, %edx
sete %bpl
jmp 0x4f06c
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x3a14b
movq %r14, %rdi
callq 0x3a180
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq