#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 */

/* Variables and functions */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ selectSameGroup(int **, int *, int, int);
int findCircleNum(int **M, int MRowSize, int MColSize) {
  int n = MRowSize;
  int nGroup = 0;
  int i;
  int *inGroup = (int *)calloc(n, sizeof(int));
  for (i = 0; i < n; i++) {
    if (inGroup[i] == 0) {
      nGroup++;
      inGroup[i] = 1;
      selectSameGroup(M, inGroup, n, i);
    }
  }
  return nGroup;
}


x86 assembly (clang, -O0):
<findCircleNum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11b3 <findCircleNum+0x93>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11a0 <findCircleNum+0x80>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
call   1040 <selectSameGroup@plt>
jmp    11a5 <findCircleNum+0x85>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1157 <findCircleNum+0x37>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findCircleNum>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%edi
mov    $0x4,%esi
call   1030 <calloc@plt>
test   %ebp,%ebp
jle    117c <findCircleNum+0x5c>
mov    %rax,%rbx
mov    %ebp,%r15d
xor    %ebp,%ebp
xor    %r12d,%r12d
jmp    1159 <findCircleNum+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r15
je     117f <findCircleNum+0x5f>
cmpl   $0x0,(%rbx,%rbp,4)
jne    1150 <findCircleNum+0x30>
add    $0x1,%r12d
movl   $0x1,(%rbx,%rbp,4)
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1040 <selectSameGroup@plt>
jmp    1150 <findCircleNum+0x30>
xor    %r12d,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @findCircleNum(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32*
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %5
store i32 %11, i32* %7
store i32 0, i32* %8
%12 = load i32, i32* %7
%13 = call i64 @calloc(i32 %12, i32 4)
%14 = inttoptr i64 %13 to i32*
store i32* %14, i32** %10
store i32 0, i32* %9
br label %15
15: ; preds = %39, %3
%16 = load i32, i32* %9
%17 = load i32, i32* %7
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %42
19: ; preds = %15
%20 = load i32*, i32** %10
%21 = load i32, i32* %9
%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 %38
26: ; preds = %19
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
%29 = load i32*, i32** %10
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
store i32 1, i32* %32
%33 = load i32**, i32*** %4
%34 = load i32*, i32** %10
%35 = load i32, i32* %7
%36 = load i32, i32* %9
%37 = call i32 @selectSameGroup(i32** %33, i32* %34, i32 %35, i32 %36)
br label %38
38: ; preds = %26, %19
br label %39
39: ; preds = %38
%40 = load i32, i32* %9
%41 = add nsw i32 %40, 1
store i32 %41, i32* %9
br label %15
42: ; preds = %15
%43 = load i32, i32* %8
ret i32 %43
}

LLVM IR (-O2):
define i32 @findCircleNum(i32** %0, i32 %1, i32 %2) {
%4 = tail call i64 @calloc(i32 %1, i32 4)
%5 = inttoptr i64 %4 to i32*
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %23
7: ; preds = %3
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %7, %19
%10 = phi i64 [ 0, %7 ], [ %21, %19 ]
%11 = phi i32 [ 0, %7 ], [ %20, %19 ]
%12 = getelementptr inbounds i32, i32* %5, i64 %10
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = add nsw i32 %11, 1
store i32 1, i32* %12
%17 = trunc i64 %10 to i32
%18 = tail call i32 @selectSameGroup(i32** %0, i32* %5, i32 %1, i32 %17)
br label %19
19: ; preds = %9, %15
%20 = phi i32 [ %16, %15 ], [ %11, %9 ]
%21 = add nuw nsw i64 %10, 1
%22 = icmp eq i64 %21, %8
br i1 %22, label %23, label %9
23: ; preds = %19, %3
%24 = phi i32 [ 0, %3 ], [ %20, %19 ]
ret i32 %24
}