#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 */
int /*<<< orphan*/ addEdge(int *, int, int);
int /*<<< orphan*/ initializeSet(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int *, int, int);
int /*<<< orphan*/ printSets();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main() {
  int v = 6;
  int *arrLoc = (int *)malloc(sizeof(int) * v);
  memset(arrLoc, -1, sizeof(int) * v);
  initializeSet(v);
  int x, y, i, n, a = 0, aPos = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d%d", &x, &y);
    addEdge(arrLoc, x, y);
  }
  for (i = 0; i < v; i++) {
    aPos = i;
    a = arrLoc[aPos];
    while (a != -1) {
      aPos = a;
      a = arrLoc[aPos];
    }
    printf("For %d head is -> %d\n", i, aPos);
  }
  printf("\n\n");
  printSets();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x6,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edx
mov    $0xffffffff,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
call   1030 <initializeSet@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
lea    0xe34(%rip),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1080 <scanf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    121f <main+0xaf>
lea    0xe0d(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1080 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1070 <addEdge@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e0 <main+0x70>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    128b <main+0x11b>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     1269 <main+0xf9>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x24(%rbp)
jmp    1246 <main+0xd6>
mov    -0x1c(%rbp),%esi
mov    -0x28(%rbp),%edx
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1226 <main+0xb6>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1090 <printSets@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0x18,%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    $0xffffffff,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    $0x6,%edi
call   1040 <initializeSet@plt>
lea    0xe44(%rip),%rdi
xor    %ebx,%ebx
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    1220 <main+0xa0>
lea    0xe26(%rip),%r14
lea    0x14(%rsp),%r15
lea    0x10(%rsp),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x14(%rsp),%esi
mov    0x10(%rsp),%edx
mov    %r13,%rdi
call   1080 <addEdge@plt>
add    $0x1,%ebp
cmp    0xc(%rsp),%ebp
jl     11f0 <main+0x70>
nopl   0x0(%rax)
mov    %ebx,%edx
movslq 0x0(%r13,%rbx,4),%rbx
cmp    $0xffffffffffffffff,%rbx
jne    1220 <main+0xa0>
lea    0xdd1(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%ecx
mov    $0x1,%eax
nopw   0x0(%rax,%rax,1)
mov    %ecx,%edx
movslq 0x0(%r13,%rax,4),%rax
mov    %eax,%ecx
cmp    $0xffffffffffffffff,%rax
jne    1250 <main+0xd0>
lea    0xd9f(%rip),%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x2,%ecx
mov    $0x2,%eax
nopl   0x0(%rax)
mov    %ecx,%edx
movslq 0x0(%r13,%rax,4),%rax
mov    %eax,%ecx
cmp    $0xffffffffffffffff,%rax
jne    1280 <main+0x100>
lea    0xd6f(%rip),%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x3,%ecx
mov    $0x3,%eax
nopl   0x0(%rax)
mov    %ecx,%edx
movslq 0x0(%r13,%rax,4),%rax
mov    %eax,%ecx
cmp    $0xffffffffffffffff,%rax
jne    12b0 <main+0x130>
lea    0xd3f(%rip),%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x4,%ecx
mov    $0x4,%eax
nopl   0x0(%rax)
mov    %ecx,%edx
movslq 0x0(%r13,%rax,4),%rax
mov    %eax,%ecx
cmp    $0xffffffffffffffff,%rax
jne    12e0 <main+0x160>
lea    0xd0f(%rip),%rdi
mov    $0x4,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x5,%ecx
mov    $0x5,%eax
nopl   0x0(%rax)
mov    %ecx,%edx
movslq 0x0(%r13,%rax,4),%rax
mov    %eax,%ecx
cmp    $0xffffffffffffffff,%rax
jne    1310 <main+0x190>
lea    0xcdf(%rip),%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xce0(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   10a0 <printSets@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [22 x i8] c"For %d head is -> %d\0A\00"
@.str.3 = [3 x i8] c"\0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %1
store i32 6, i32* %2
%10 = load i32, i32* %2
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = load i32, i32* %2
%18 = sext i32 %17 to i64
%19 = mul i64 4, %18
%20 = trunc i64 %19 to i32
%21 = call i32 @memset(i32* %16, i32 -1, i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @initializeSet(i32 %22)
store i32 0, i32* %8
store i32 0, i32* %9
%24 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 0, i32* %6
br label %25
25: ; preds = %35, %0
%26 = load i32, i32* %6
%27 = load i32, i32* %7
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %38
29: ; preds = %25
%30 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %4, i32* %5)
%31 = load i32*, i32** %3
%32 = load i32, i32* %4
%33 = load i32, i32* %5
%34 = call i32 @addEdge(i32* %31, i32 %32, i32 %33)
br label %35
35: ; preds = %29
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %25
38: ; preds = %25
store i32 0, i32* %6
br label %39
39: ; preds = %64, %38
%40 = load i32, i32* %6
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %67
43: ; preds = %39
%44 = load i32, i32* %6
store i32 %44, i32* %9
%45 = load i32*, i32** %3
%46 = load i32, i32* %9
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %45, i64 %47
%49 = load i32, i32* %48
store i32 %49, i32* %8
br label %50
50: ; preds = %53, %43
%51 = load i32, i32* %8
%52 = icmp ne i32 %51, -1
br i1 %52, label %53, label %60
53: ; preds = %50
%54 = load i32, i32* %8
store i32 %54, i32* %9
%55 = load i32*, i32** %3
%56 = load i32, i32* %9
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
%59 = load i32, i32* %58
store i32 %59, i32* %8
br label %50
60: ; preds = %50
%61 = load i32, i32* %6
%62 = load i32, i32* %9
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %61, i32 %62)
br label %64
64: ; preds = %60
%65 = load i32, i32* %6
%66 = add nsw i32 %65, 1
store i32 %66, i32* %6
br label %39
67: ; preds = %39
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%69 = call i32 (...) @printSets()
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [22 x i8] c"For %d head is -> %d\0A\00"
@str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = tail call i64 @malloc(i32 24)
%5 = inttoptr i64 %4 to i32*
%6 = tail call i32 @memset(i32* %5, i32 -1, i32 24)
%7 = tail call i32 @initializeSet(i32 6)
%8 = bitcast i32* %1 to i8*
%9 = bitcast i32* %2 to i8*
%10 = bitcast i32* %3 to i8*
%11 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%12 = load i32, i32* %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %0, %14
%15 = phi i32 [ %20, %14 ], [ 0, %0 ]
%16 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%17 = load i32, i32* %1
%18 = load i32, i32* %2
%19 = call i32 @addEdge(i32* %5, i32 %17, i32 %18)
%20 = add nuw nsw i32 %15, 1
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %14, label %23
23: ; preds = %14, %0
br label %24
24: ; preds = %23, %24
%25 = phi i64 [ %30, %24 ], [ 0, %23 ]
%26 = phi i32 [ %28, %24 ], [ 0, %23 ]
%27 = getelementptr inbounds i32, i32* %5, i64 %25
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, -1
%30 = sext i32 %28 to i64
br i1 %29, label %31, label %24
31: ; preds = %24
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 %26)
br label %33
33: ; preds = %33, %31
%34 = phi i64 [ 1, %31 ], [ %39, %33 ]
%35 = phi i32 [ 1, %31 ], [ %37, %33 ]
%36 = getelementptr inbounds i32, i32* %5, i64 %34
%37 = load i32, i32* %36
%38 = icmp eq i32 %37, -1
%39 = sext i32 %37 to i64
br i1 %38, label %40, label %33
40: ; preds = %33
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 1, i32 %35)
br label %42
42: ; preds = %42, %40
%43 = phi i64 [ 2, %40 ], [ %48, %42 ]
%44 = phi i32 [ 2, %40 ], [ %46, %42 ]
%45 = getelementptr inbounds i32, i32* %5, i64 %43
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, -1
%48 = sext i32 %46 to i64
br i1 %47, label %49, label %42
49: ; preds = %42
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 2, i32 %44)
br label %51
51: ; preds = %51, %49
%52 = phi i64 [ 3, %49 ], [ %57, %51 ]
%53 = phi i32 [ 3, %49 ], [ %55, %51 ]
%54 = getelementptr inbounds i32, i32* %5, i64 %52
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, -1
%57 = sext i32 %55 to i64
br i1 %56, label %58, label %51
58: ; preds = %51
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 3, i32 %53)
br label %60
60: ; preds = %60, %58
%61 = phi i64 [ 4, %58 ], [ %66, %60 ]
%62 = phi i32 [ 4, %58 ], [ %64, %60 ]
%63 = getelementptr inbounds i32, i32* %5, i64 %61
%64 = load i32, i32* %63
%65 = icmp eq i32 %64, -1
%66 = sext i32 %64 to i64
br i1 %65, label %67, label %60
67: ; preds = %60
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 4, i32 %62)
br label %69
69: ; preds = %69, %67
%70 = phi i64 [ 5, %67 ], [ %75, %69 ]
%71 = phi i32 [ 5, %67 ], [ %73, %69 ]
%72 = getelementptr inbounds i32, i32* %5, i64 %70
%73 = load i32, i32* %72
%74 = icmp eq i32 %73, -1
%75 = sext i32 %73 to i64
br i1 %74, label %76, label %69
76: ; preds = %69
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 %71)
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%79 = call i32 (...) @printSets()
ret i32 0
}