#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 check_node(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(void) {
  int id[10], treeSize[10], i, j, p, q, n;
  char r[10];
  for (i = 0; i < 10; ++i) {
    id[i] = i;
    treeSize[i] = 1;
  }
  for (;;) {
    printf("Give the 1st node or -1 to terminate: ");
    fgets(r, 10, stdin);
    n = strlen(r);
    r[n - 1] = '\0';
    p = check_node(r);
    if (p == -1)
      break;
    printf("Give the 2nd node or -1 to terminate: ");
    fgets(r, 10, stdin);
    n = strlen(r);
    r[n - 1] = '\0';
    q = check_node(r);
    if (q == -1)
      break;
    for (i = p; i != id[i]; i = id[i])
      ;
    for (j = q; j != id[j]; j = id[j])
      ;
    if (i == j) {
      puts("Nodes already linked.\n");
      continue;
    }
    if (treeSize[i] < treeSize[j]) {
      id[i] = j;
      treeSize[j] += treeSize[i];
    } else {
      id[j] = i;
      treeSize[i] += treeSize[j];
    }
    puts("Nodes linked!\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    1198 <main+0x48>
mov    -0x64(%rbp),%ecx
movslq -0x64(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
movslq -0x64(%rbp),%rax
movl   $0x1,-0x60(%rbp,%rax,4)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1169 <main+0x19>
jmp    119d <main+0x4d>
lea    0xe5c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x7e(%rbp),%rdi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1060 <fgets@plt>
lea    -0x7e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x7e(%rbp,%rax,1)
lea    -0x7e(%rbp),%rdi
call   1070 <check_node@plt>
mov    %eax,-0x6c(%rbp)
cmpl   $0xffffffff,-0x6c(%rbp)
jne    11f4 <main+0xa4>
jmp    132a <main+0x1da>
lea    0xe2c(%rip),%rdi
call   1050 <printf@plt>
lea    -0x7e(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%edx
mov    $0xa,%esi
call   1060 <fgets@plt>
lea    -0x7e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x7e(%rbp,%rax,1)
lea    -0x7e(%rbp),%rdi
call   1070 <check_node@plt>
mov    %eax,-0x70(%rbp)
cmpl   $0xffffffff,-0x70(%rbp)
jne    124b <main+0xfb>
jmp    132a <main+0x1da>
mov    -0x6c(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
movslq -0x64(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     1277 <main+0x127>
jmp    1267 <main+0x117>
movslq -0x64(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x64(%rbp)
jmp    1251 <main+0x101>
mov    -0x70(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
movslq -0x68(%rbp),%rcx
cmp    -0x30(%rbp,%rcx,4),%eax
je     12a3 <main+0x153>
jmp    1293 <main+0x143>
movslq -0x68(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%eax
mov    %eax,-0x68(%rbp)
jmp    127d <main+0x12d>
mov    -0x64(%rbp),%eax
cmp    -0x68(%rbp),%eax
jne    12c0 <main+0x170>
lea    0xd98(%rip),%rdi
call   1030 <puts@plt>
jmp    119d <main+0x4d>
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%eax
movslq -0x68(%rbp),%rcx
cmp    -0x60(%rbp,%rcx,4),%eax
jge    12fa <main+0x1aa>
mov    -0x68(%rbp),%ecx
movslq -0x64(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%ecx
movslq -0x68(%rbp),%rax
add    -0x60(%rbp,%rax,4),%ecx
mov    %ecx,-0x60(%rbp,%rax,4)
jmp    1319 <main+0x1c9>
mov    -0x64(%rbp),%ecx
movslq -0x68(%rbp),%rax
mov    %ecx,-0x30(%rbp,%rax,4)
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%ecx
movslq -0x64(%rbp),%rax
add    -0x60(%rbp,%rax,4),%ecx
mov    %ecx,-0x60(%rbp,%rax,4)
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
jmp    119d <main+0x4d>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
movaps 0xe9b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xe9f(%rip),%xmm0
movaps %xmm0,(%rsp)
movaps 0xea4(%rip),%xmm1
movaps %xmm1,0x40(%rsp)
movaps %xmm0,0x10(%rsp)
movabs $0x900000008,%rax
mov    %rax,0x50(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x20(%rsp)
lea    0xe85(%rip),%r14
mov    0x2e36(%rip),%r12
lea    0x5e(%rsp),%rbx
lea    0xe99(%rip),%r15
lea    0xeb9(%rip),%r13
jmp    11d5 <main+0x85>
nopw   0x0(%rax,%rax,1)
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <check_node@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x15e>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <printf@plt>
mov    (%r12),%edx
mov    %rbx,%rdi
mov    $0xa,%esi
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbx,%rdi
call   1070 <check_node@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0x15e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edx
movslq %ebp,%rcx
mov    0x30(%rsp,%rcx,4),%ebp
cmp    %ebp,%ecx
jne    1250 <main+0x100>
nopl   (%rax)
mov    %eax,%ebp
movslq %eax,%rsi
mov    0x30(%rsp,%rsi,4),%eax
cmp    %eax,%esi
jne    1260 <main+0x110>
mov    %r13,%rdi
cmp    %ebp,%edx
je     11d0 <main+0x80>
mov    (%rsp,%rcx,4),%eax
mov    (%rsp,%rsi,4),%edi
cmp    %edi,%eax
jge    1290 <main+0x140>
lea    (%rsp,%rsi,4),%r8
mov    %ebp,0x30(%rsp,%rcx,4)
jmp    1298 <main+0x148>
nopl   0x0(%rax)
lea    (%rsp,%rcx,4),%r8
mov    %edx,0x30(%rsp,%rsi,4)
add    %eax,%edi
mov    %edi,(%r8)
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
jmp    11d5 <main+0x85>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Give the 1st node or -1 to terminate: \00"
@stdin = global i32 0
@.str.1 = [39 x i8] c"Give the 2nd node or -1 to terminate: \00"
@.str.2 = [23 x i8] c"Nodes already linked.\0A\00"
@.str.3 = [15 x i8] c"Nodes linked!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca [10 x i32]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10 x i8]
store i32 0, i32* %1
store i32 0, i32* %4
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 10
br i1 %12, label %13, label %24
13: ; preds = %10
%14 = load i32, i32* %4
%15 = load i32, i32* %4
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %16
store i32 %14, i32* %17
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %19
store i32 1, i32* %20
br label %21
21: ; preds = %13
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %10
24: ; preds = %10
br label %25
25: ; preds = %131, %91, %24
%26 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%28 = load i32, i32* @stdin
%29 = call i32 @fgets(i8* %27, i32 10, i32 %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = sub nsw i32 %32, 1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %34
store i8 0, i8* %35
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%37 = call i32 @check_node(i8* %36)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %25
br label %133
41: ; preds = %25
%42 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%44 = load i32, i32* @stdin
%45 = call i32 @fgets(i8* %43, i32 10, i32 %44)
%46 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = sub nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 %50
store i8 0, i8* %51
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %9, i64 0, i64 0
%53 = call i32 @check_node(i8* %52)
store i32 %53, i32* %7
%54 = load i32, i32* %7
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %57
56: ; preds = %41
br label %133
57: ; preds = %41
%58 = load i32, i32* %6
store i32 %58, i32* %4
br label %59
59: ; preds = %67, %57
%60 = load i32, i32* %4
%61 = load i32, i32* %4
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %62
%64 = load i32, i32* %63
%65 = icmp ne i32 %60, %64
br i1 %65, label %66, label %72
66: ; preds = %59
br label %67
67: ; preds = %66
%68 = load i32, i32* %4
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %69
%71 = load i32, i32* %70
store i32 %71, i32* %4
br label %59
72: ; preds = %59
%73 = load i32, i32* %7
store i32 %73, i32* %5
br label %74
74: ; preds = %82, %72
%75 = load i32, i32* %5
%76 = load i32, i32* %5
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %77
%79 = load i32, i32* %78
%80 = icmp ne i32 %75, %79
br i1 %80, label %81, label %87
81: ; preds = %74
br label %82
82: ; preds = %81
%83 = load i32, i32* %5
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %84
%86 = load i32, i32* %85
store i32 %86, i32* %5
br label %74
87: ; preds = %74
%88 = load i32, i32* %4
%89 = load i32, i32* %5
%90 = icmp eq i32 %88, %89
br i1 %90, label %91, label %93
91: ; preds = %87
%92 = call i32 @puts(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %25
93: ; preds = %87
%94 = load i32, i32* %4
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %95
%97 = load i32, i32* %96
%98 = load i32, i32* %5
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %99
%101 = load i32, i32* %100
%102 = icmp slt i32 %97, %101
br i1 %102, label %103, label %117
103: ; preds = %93
%104 = load i32, i32* %5
%105 = load i32, i32* %4
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %106
store i32 %104, i32* %107
%108 = load i32, i32* %4
%109 = sext i32 %108 to i64
%110 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %109
%111 = load i32, i32* %110
%112 = load i32, i32* %5
%113 = sext i32 %112 to i64
%114 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %113
%115 = load i32, i32* %114
%116 = add nsw i32 %115, %111
store i32 %116, i32* %114
br label %131
117: ; preds = %93
%118 = load i32, i32* %4
%119 = load i32, i32* %5
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %120
store i32 %118, i32* %121
%122 = load i32, i32* %5
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %123
%125 = load i32, i32* %124
%126 = load i32, i32* %4
%127 = sext i32 %126 to i64
%128 = getelementptr inbounds [10 x i32], [10 x i32]* %3, i64 0, i64 %127
%129 = load i32, i32* %128
%130 = add nsw i32 %129, %125
store i32 %130, i32* %128
br label %131
131: ; preds = %117, %103
%132 = call i32 @puts(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
br label %25
133: ; preds = %56, %40
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Give the 1st node or -1 to terminate: \00"
@stdin = global i32 0
@.str.1 = [39 x i8] c"Give the 2nd node or -1 to terminate: \00"
@.str.2 = [23 x i8] c"Nodes already linked.\0A\00"
@.str.3 = [15 x i8] c"Nodes linked!\0A\00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = alloca [10 x i32]
%3 = alloca [10 x i8]
%4 = bitcast [10 x i32]* %1 to i8*
%5 = bitcast [10 x i32]* %2 to i8*
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = bitcast [10 x i32]* %1 to <4 x i32>*
store <4 x i32> <i32 0, i32 1, i32 2, i32 3>, <4 x i32>* %7
%8 = bitcast [10 x i32]* %2 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %8
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%10 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 4
%11 = bitcast i32* %9 to <4 x i32>*
store <4 x i32> <i32 4, i32 5, i32 6, i32 7>, <4 x i32>* %11
%12 = bitcast i32* %10 to <4 x i32>*
store <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32>* %12
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
store i32 8, i32* %13
%14 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 8
store i32 1, i32* %14
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
store i32 9, i32* %15
%16 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 9
store i32 1, i32* %16
br label %17
17: ; preds = %0, %54
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stdin
%20 = call i32 @fgets(i8* %6, i32 10, i32 %19)
%21 = call i32 @strlen(i8* %6)
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %23
store i8 0, i8* %24
%25 = call i32 @check_node(i8* %6)
%26 = icmp eq i32 %25, -1
br i1 %26, label %68, label %27
27: ; preds = %17
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0))
%29 = load i32, i32* @stdin
%30 = call i32 @fgets(i8* %6, i32 10, i32 %29)
%31 = call i32 @strlen(i8* %6)
%32 = add nsw i32 %31, -1
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 @check_node(i8* %6)
%36 = icmp eq i32 %35, -1
br i1 %36, label %68, label %37
37: ; preds = %27, %37
%38 = phi i32 [ %41, %37 ], [ %25, %27 ]
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %38, %41
br i1 %42, label %43, label %37
43: ; preds = %37
%44 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %39
br label %45
45: ; preds = %43, %45
%46 = phi i32 [ %49, %45 ], [ %35, %43 ]
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %47
%49 = load i32, i32* %48
%50 = icmp eq i32 %46, %49
br i1 %50, label %51, label %45
51: ; preds = %45
%52 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 %47
%53 = icmp eq i32 %38, %46
br i1 %53, label %54, label %57
54: ; preds = %51, %65
%55 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), %65 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), %51 ]
%56 = call i32 @puts(i8* dereferenceable(1) %55)
br label %17
57: ; preds = %51
%58 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %39
%59 = load i32, i32* %58
%60 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %47
%61 = load i32, i32* %60
%62 = icmp slt i32 %59, %61
br i1 %62, label %63, label %64
63: ; preds = %57
store i32 %46, i32* %44
br label %65
64: ; preds = %57
store i32 %38, i32* %52
br label %65
65: ; preds = %64, %63
%66 = phi i32* [ %58, %64 ], [ %60, %63 ]
%67 = add nsw i32 %61, %59
store i32 %67, i32* %66
br label %54
68: ; preds = %27, %17
ret i32 0
}