#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct node {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ explore(int, int *, struct node **, int);
scalar_t__ malloc(int);
int numConnected(struct node *adj[], int NV) {
  int k;
  int *visited;
  int connected_component_id = 1;
  visited = (int *)malloc((NV + 1) * sizeof(int));
  for (k = 1; k <= NV; k++) {
    if (visited[k] == 0) {
      explore(k, visited, adj, connected_component_id);
      connected_component_id++;
    }
  }
  connected_component_id--;
  return connected_component_id;
}


x86 assembly (clang, -O0):
<numConnected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11a1 <numConnected+0x81>
mov    -0x18(%rbp),%rax
movslq -0x10(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    118e <numConnected+0x6e>
mov    -0x10(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <explore@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1193 <numConnected+0x73>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1154 <numConnected+0x34>
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numConnected>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0x4(,%r15,4),%edi
call   1030 <malloc@plt>
test   %r15d,%r15d
jle    1185 <numConnected+0x65>
mov    %rax,%rbx
add    $0x1,%r15d
mov    $0x1,%r12d
mov    $0x1,%ebp
jmp    1169 <numConnected+0x49>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbp
cmp    %rbp,%r15
je     118b <numConnected+0x6b>
cmpl   $0x0,(%rbx,%rbp,4)
jne    1160 <numConnected+0x40>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
mov    %r12d,%ecx
call   1040 <explore@plt>
add    $0x1,%r12d
jmp    1160 <numConnected+0x40>
mov    $0x1,%r12d
add    $0xffffffff,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
define i32 @numConnected(%struct.node** %0, i32 %1) {
%3 = alloca %struct.node**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store %struct.node** %0, %struct.node*** %3
store i32 %1, i32* %4
store i32 1, i32* %7
%8 = load i32, i32* %4
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %6
store i32 1, i32* %5
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %5
%17 = load i32, i32* %4
%18 = icmp sle i32 %16, %17
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load i32*, i32** %6
%21 = load i32, i32* %5
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %34
26: ; preds = %19
%27 = load i32, i32* %5
%28 = load i32*, i32** %6
%29 = load %struct.node**, %struct.node*** %3
%30 = load i32, i32* %7
%31 = call i32 @explore(i32 %27, i32* %28, %struct.node** %29, i32 %30)
%32 = load i32, i32* %7
%33 = add nsw i32 %32, 1
store i32 %33, i32* %7
br label %34
34: ; preds = %26, %19
br label %35
35: ; preds = %34
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %15
38: ; preds = %15
%39 = load i32, i32* %7
%40 = add nsw i32 %39, -1
store i32 %40, i32* %7
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
%struct.node = type { i32 }
define i32 @numConnected(%struct.node** %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = add i32 %3, 4
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp slt i32 %1, 1
br i1 %7, label %25, label %8
8: ; preds = %2
%9 = add nuw i32 %1, 1
%10 = zext i32 %9 to i64
br label %11
11: ; preds = %8, %21
%12 = phi i64 [ 1, %8 ], [ %23, %21 ]
%13 = phi i32 [ 1, %8 ], [ %22, %21 ]
%14 = getelementptr inbounds i32, i32* %6, i64 %12
%15 = load i32, i32* %14
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %11
%18 = trunc i64 %12 to i32
%19 = tail call i32 @explore(i32 %18, i32* %6, %struct.node** %0, i32 %13)
%20 = add nsw i32 %13, 1
br label %21
21: ; preds = %11, %17
%22 = phi i32 [ %20, %17 ], [ %13, %11 ]
%23 = add nuw nsw i64 %12, 1
%24 = icmp eq i64 %23, %10
br i1 %24, label %25, label %11
25: ; preds = %21, %2
%26 = phi i32 [ 1, %2 ], [ %22, %21 ]
%27 = add nsw i32 %26, -1
ret i32 %27
}