// File: /workspace/github_c_makefile_star2_O1/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, %rbp
movslq 0x10(%rdi), %rdi
shlq $0x3, %rdi
leaq 0x56d84(%rip), %r14     # 0xa47a9
movq %r14, %rsi
movl $0x3, %edx
callq 0x390f5
movq %rax, %rbx
movslq 0x10(%rbp), %rdi
shlq $0x2, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, %r14
cmpl $0x0, 0x10(%rbp)
jle 0x4da8a
xorl %r15d, %r15d
leaq 0x56d4c(%rip), %r12     # 0xa47a9
movl $0x1, (%r14,%r15,4)
movl $0x4, %edi
movq %r12, %rsi
movl $0x8, %edx
callq 0x390f5
movq %rax, (%rbx,%r15,8)
movl %r15d, (%rax)
incq %r15
movslq 0x10(%rbp), %rax
cmpq %rax, %r15
jl 0x4da5d
movl 0x10(%rbp), %esi
testl %esi, %esi
jle 0x4dbc2
xorl %r12d, %r12d
movl $0x0, 0xc(%rsp)
movq %rbp, 0x10(%rsp)
movq 0x8(%rbp), %rax
leaq (%r12,%r12,8), %rcx
movl 0x30(%rax,%rcx,8), %eax
cmpl $-0x1, %eax
je 0x4dba8
movslq %eax, %r13
movslq 0x10(%rbp), %rsi
xorl %eax, %eax
testq %rsi, %rsi
jle 0x4db24
movq 0x28(%rbp), %rcx
movl (%rcx,%r13,4), %edi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r8d, %r8d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movslq (%r14,%r8,4), %r9
testq %r9, %r9
jle 0x4db07
movq (%rbx,%r8,8), %r10
xorl %r11d, %r11d
movl (%r10,%r11,4), %r15d
cmpq %r15, %r12
cmovel %r8d, %edx
cmpl %edi, %r15d
cmovel %r8d, %ecx
incq %r11
cmpq %r11, %r9
jne 0x4daed
xorl %r10d, %r10d
testl %r9d, %r9d
setg %r10b
addl %r10d, %eax
incq %r8
cmpq %rsi, %r8
jne 0x4dadd
cmpl $0x1, %eax
sete %al
jmp 0x4db2e
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testb %al, %al
jne 0x4dba0
cmpl %ecx, %edx
je 0x4db93
movslq %edx, %rbp
movq (%rbx,%rbp,8), %rdi
movslq (%r14,%rbp,4), %rax
movslq %ecx, %r15
movslq (%r14,%r15,4), %rdx
addq %rax, %rdx
movq %rdx, %rsi
shlq $0x2, %rsi
callq 0x390c8
movq %rax, (%rbx,%rbp,8)
movl (%r14,%r15,4), %edx
testl %edx, %edx
jle 0x4db82
movq (%rbx,%r15,8), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edx
movslq (%r14,%rbp,4), %rdi
addq %rsi, %rdi
movl %edx, (%rax,%rdi,4)
incq %rsi
movslq (%r14,%r15,4), %rdx
cmpq %rdx, %rsi
jl 0x4db69
addl %edx, (%r14,%rbp,4)
movl $0x0, (%r14,%r15,4)
movq 0x10(%rsp), %rbp
movq 0x18(%rbp), %rax
movl (%rax,%r13,4), %eax
jmp 0x4dab1
movl $0x1, 0xc(%rsp)
incq %r12
movslq 0x10(%rbp), %rsi
cmpq %rsi, %r12
jl 0x4daa5
cmpl $0x0, 0xc(%rsp)
sete %al
jmp 0x4dbc4
movb $0x1, %al
movl $0x1, %ebp
testb %al, %al
je 0x4dbf9
testl %esi, %esi
jle 0x4dbf7
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 0x4dbd7
xorl %ebp, %ebp
cmpl $0x1, %edx
sete %bpl
jmp 0x4dbf9
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x3915f
movq %r14, %rdi
callq 0x39194
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq