// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/statistics.c
// Function: connected_components
int connected_components(Linkptr edges, int nodecount)
{
 /*Last Changed 12.03.2004*/
 int** components, i, j, *counts, compcount = 0, compf, comps;
 Linkptr e;
 components = (int **)safemalloc_2d(sizeof(int *), sizeof(int), nodecount, nodecount, "connected_components", 3);
 counts = (int *)safemalloc(nodecount * sizeof(int), "connected_components", 4);
 for (i = 0; i < nodecount; i++)
  {
   components[i][0] = i;
   counts[i] = 1;
  }
 e = edges;
 while (e)
  {
   for (i = 0; i < nodecount; i++)
     for (j = 0; j < counts[i]; j++)
       if (components[i][j] == e->from)
        {
         compf = i;
         i = nodecount;
         break;
        }
   for (i = 0; i < nodecount; i++)
     for (j = 0; j < counts[i]; j++)
       if (components[i][j] == e->to)
        {
         comps = i;
         i = nodecount;
         break;
        }
   if (compf != comps)
    {
     components[compf] = alloc(components[compf], (counts[compf] + counts[comps]) * sizeof(int), counts[compf] + counts[comps]);
     for (i = 0; i < counts[comps]; i++)
       components[compf][counts[compf] + i] = components[comps][i];
     counts[compf] = counts[compf] + counts[comps];
     safe_free(components[comps]);
     counts[comps] = 0;
    }
   e = e->next;
  }
 for (i = 0; i < nodecount; i++)
   if (counts[i] > 0)
     safe_free(components[i]);
 safe_free(components);
 for (i = 0; i < nodecount; i++)
   if (counts[i] > 0)
     compcount++;
 safe_free(counts);
 return compcount;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %esi, %ebp
movq %rdi, %r15
leaq 0x22e34(%rip), %rbx     # 0xae6a5
movl $0x8, %edi
movl $0x4, %esi
movl %ebp, %edx
movl %ebp, %ecx
movq %rbx, %r8
movl $0x3, %r9d
callq 0x393b5
movq %rax, %r14
movslq %ebp, %r12
leaq (,%r12,4), %rdi
movq %rbx, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, %rbx
movl %ebp, %r13d
testl %r12d, %r12d
jle 0x8b8ca
xorl %eax, %eax
movq (%r14,%rax,8), %rcx
movl %eax, (%rcx)
movl $0x1, (%rbx,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x8b8b5
testq %r15, %r15
je 0x8b9d5
movq %r13, 0x10(%rsp)
testl %ebp, %ebp
jle 0x8b910
xorl %eax, %eax
movl %eax, %edx
movslq (%rbx,%rdx,4), %rcx
testq %rcx, %rcx
jle 0x8b8ff
movq (%r14,%rdx,8), %rdx
movl (%r15), %esi
xorl %edi, %edi
cmpl %esi, (%rdx,%rdi,4)
je 0x8b903
incq %rdi
cmpq %rdi, %rcx
jne 0x8b8f2
movl %eax, %ecx
jmp 0x8b908
movl %ebp, %ecx
movl %eax, %r9d
incl %ecx
movl %ecx, %eax
cmpl %ebp, %ecx
jl 0x8b8de
testl %ebp, %ebp
jle 0x8b949
xorl %eax, %eax
movl %eax, %edx
movslq (%rbx,%rdx,4), %rcx
testq %rcx, %rcx
jle 0x8b938
movq (%r14,%rdx,8), %rdx
movl 0x4(%r15), %esi
xorl %edi, %edi
cmpl %esi, (%rdx,%rdi,4)
je 0x8b93c
incq %rdi
cmpq %rdi, %rcx
jne 0x8b92b
movl %eax, %ecx
jmp 0x8b941
movl %ebp, %ecx
movl %eax, %r8d
incl %ecx
movl %ecx, %eax
cmpl %ebp, %ecx
jl 0x8b916
cmpl %r8d, %r9d
je 0x8b9c8
movl %r9d, 0x8(%rsp)
movslq %r9d, %r12
movq (%r14,%r12,8), %rdi
movslq (%rbx,%r12,4), %rax
movl %r8d, 0xc(%rsp)
movslq %r8d, %r13
movslq (%rbx,%r13,4), %rdx
addq %rax, %rdx
movq %rdx, %rsi
shlq $0x2, %rsi
callq 0x390c8
movq %rax, (%r14,%r12,8)
movl (%rbx,%r13,4), %edx
testl %edx, %edx
jle 0x8b9a4
movq (%r14,%r13,8), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edx
movslq (%rbx,%r12,4), %rdi
addq %rsi, %rdi
movl %edx, (%rax,%rdi,4)
incq %rsi
movslq (%rbx,%r13,4), %rdx
cmpq %rdx, %rsi
jl 0x8b98b
addl %edx, (%rbx,%r12,4)
movq (%r14,%r13,8), %rdi
callq 0x39194
movl $0x0, (%rbx,%r13,4)
movq 0x10(%rsp), %r13
movl 0xc(%rsp), %r8d
movl 0x8(%rsp), %r9d
movq 0x8(%r15), %r15
testq %r15, %r15
jne 0x8b8d8
testl %ebp, %ebp
jle 0x8b9f4
xorl %r15d, %r15d
cmpl $0x0, (%rbx,%r15,4)
jle 0x8b9ec
movq (%r14,%r15,8), %rdi
callq 0x39194
incq %r15
cmpq %r15, %r13
jne 0x8b9dc
movq %r14, %rdi
callq 0x39194
testl %ebp, %ebp
jle 0x8ba19
xorl %eax, %eax
xorl %ebp, %ebp
xorl %ecx, %ecx
cmpl $0x0, (%rbx,%rax,4)
setg %cl
addl %ecx, %ebp
incq %rax
cmpq %rax, %r13
jne 0x8ba04
jmp 0x8ba1b
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x39194
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq