#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 connect_element(int *, int, int, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ init_element(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ union_element(int *, int, int, int);
int main() {
  int num = 0;
  int ret = 0;
  int *all_element = NULL;
  printf("Please input how many number in your union group\n");
  while (!scanf("%d", &num)) {
    getchar();
    printf("scanf error, please input again\n");
  }
  all_element = (int *)malloc(sizeof(int) * num);
  init_element(all_element, num);
  union_element(all_element, num, 4, 3);
  union_element(all_element, num, 3, 8);
  union_element(all_element, num, 6, 5);
  union_element(all_element, num, 9, 4);
  union_element(all_element, num, 2, 1);
  ret = connect_element(all_element, num, 0, 7);
  if (ret == 1) {
    printf("Y Connected!\n");
  } else if (ret == 0) {
    printf("X Unconnected!\n");
  }
  ret = connect_element(all_element, num, 8, 9);
  if (ret == 1) {
    printf("Y Connected!\n");
  } else if (ret == 0) {
    printf("X Unconnected!\n");
  }
  free(all_element);
  all_element = NULL;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe54(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7a(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   10a0 <scanf@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11d6 <main+0x56>
jmp    11ee <main+0x6e>
mov    $0x0,%al
call   1080 <getchar@plt>
lea    0xe51(%rip),%rdi
call   1050 <printf@plt>
jmp    11b1 <main+0x31>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <init_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x4,%edx
mov    $0x3,%ecx
call   1070 <union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x3,%edx
mov    $0x8,%ecx
call   1070 <union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x6,%edx
mov    $0x5,%ecx
call   1070 <union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x9,%edx
mov    $0x4,%ecx
call   1070 <union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1070 <union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
xor    %edx,%edx
mov    $0x7,%ecx
call   1030 <connect_element@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    12ac <main+0x12c>
lea    0xdb4(%rip),%rdi
call   1050 <printf@plt>
jmp    12c7 <main+0x147>
cmpl   $0x0,-0xc(%rbp)
jne    12c2 <main+0x142>
lea    0xda7(%rip),%rdi
call   1050 <printf@plt>
jmp    12c7 <main+0x147>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x8,%edx
mov    $0x9,%ecx
call   1030 <connect_element@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    12fb <main+0x17b>
lea    0xd65(%rip),%rdi
call   1050 <printf@plt>
jmp    1316 <main+0x196>
cmpl   $0x0,-0xc(%rbp)
jne    1311 <main+0x191>
lea    0xd58(%rip),%rdi
call   1050 <printf@plt>
jmp    1316 <main+0x196>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movq   $0x0,-0x18(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
lea    0xe6b(%rip),%rdi
call   1050 <puts@plt>
lea    0xe5c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
test   %eax,%eax
jne    11ee <main+0x6e>
lea    0xe97(%rip),%r14
lea    0xe40(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
test   %eax,%eax
je     11d0 <main+0x50>
mov    0xc(%rsp),%edi
shl    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1060 <init_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x4,%edx
mov    $0x3,%ecx
call   1070 <union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x3,%edx
mov    $0x8,%ecx
call   1070 <union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x6,%edx
mov    $0x5,%ecx
call   1070 <union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x9,%edx
mov    $0x4,%ecx
call   1070 <union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x2,%edx
mov    $0x1,%ecx
call   1070 <union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
xor    %edx,%edx
mov    $0x7,%ecx
call   1030 <connect_element@plt>
cmp    $0x1,%eax
je     129c <main+0x11c>
test   %eax,%eax
jne    12a8 <main+0x128>
lea    0xd9a(%rip),%rdi
jmp    12a3 <main+0x123>
lea    0xda0(%rip),%rdi
call   1050 <puts@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x8,%edx
mov    $0x9,%ecx
call   1030 <connect_element@plt>
cmp    $0x1,%eax
je     12d0 <main+0x150>
test   %eax,%eax
jne    12dc <main+0x15c>
lea    0xd66(%rip),%rdi
jmp    12d7 <main+0x157>
lea    0xd6c(%rip),%rdi
call   1050 <puts@plt>
mov    %rbx,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [50 x i8] c"Please input how many number in your union group\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"scanf error, please input again\0A\00"
@.str.3 = [14 x i8] c"Y Connected!\0A\00"
@.str.4 = [16 x i8] c"X Unconnected!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32*
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
store i32* null, i32** %4
%5 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %10, %0
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = call i32 (...) @getchar()
%12 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %6
13: ; preds = %6
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %4
%20 = load i32*, i32** %4
%21 = load i32, i32* %2
%22 = call i32 @init_element(i32* %20, i32 %21)
%23 = load i32*, i32** %4
%24 = load i32, i32* %2
%25 = call i32 @union_element(i32* %23, i32 %24, i32 4, i32 3)
%26 = load i32*, i32** %4
%27 = load i32, i32* %2
%28 = call i32 @union_element(i32* %26, i32 %27, i32 3, i32 8)
%29 = load i32*, i32** %4
%30 = load i32, i32* %2
%31 = call i32 @union_element(i32* %29, i32 %30, i32 6, i32 5)
%32 = load i32*, i32** %4
%33 = load i32, i32* %2
%34 = call i32 @union_element(i32* %32, i32 %33, i32 9, i32 4)
%35 = load i32*, i32** %4
%36 = load i32, i32* %2
%37 = call i32 @union_element(i32* %35, i32 %36, i32 2, i32 1)
%38 = load i32*, i32** %4
%39 = load i32, i32* %2
%40 = call i32 @connect_element(i32* %38, i32 %39, i32 0, i32 7)
store i32 %40, i32* %3
%41 = load i32, i32* %3
%42 = icmp eq i32 %41, 1
br i1 %42, label %43, label %45
43: ; preds = %13
%44 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %51
45: ; preds = %13
%46 = load i32, i32* %3
%47 = icmp eq i32 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %48, %45
br label %51
51: ; preds = %50, %43
%52 = load i32*, i32** %4
%53 = load i32, i32* %2
%54 = call i32 @connect_element(i32* %52, i32 %53, i32 8, i32 9)
store i32 %54, i32* %3
%55 = load i32, i32* %3
%56 = icmp eq i32 %55, 1
br i1 %56, label %57, label %59
57: ; preds = %51
%58 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %65
59: ; preds = %51
%60 = load i32, i32* %3
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %59
%63 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %62, %59
br label %65
65: ; preds = %64, %57
%66 = load i32*, i32** %4
%67 = call i32 @free(i32* %66)
store i32* null, i32** %4
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%d\00"
@str = [49 x i8] c"Please input how many number in your union group\00"
@str.7 = [15 x i8] c"X Unconnected!\00"
@str.8 = [13 x i8] c"Y Connected!\00"
@str.9 = [32 x i8] c"scanf error, please input again\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%4 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %0, %6
%7 = call i32 (...) @getchar()
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.9, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %6, label %11
11: ; preds = %6, %0
%12 = load i32, i32* %1
%13 = shl i32 %12, 2
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i32*
%16 = load i32, i32* %1
%17 = call i32 @init_element(i32* %15, i32 %16)
%18 = load i32, i32* %1
%19 = call i32 @union_element(i32* %15, i32 %18, i32 4, i32 3)
%20 = load i32, i32* %1
%21 = call i32 @union_element(i32* %15, i32 %20, i32 3, i32 8)
%22 = load i32, i32* %1
%23 = call i32 @union_element(i32* %15, i32 %22, i32 6, i32 5)
%24 = load i32, i32* %1
%25 = call i32 @union_element(i32* %15, i32 %24, i32 9, i32 4)
%26 = load i32, i32* %1
%27 = call i32 @union_element(i32* %15, i32 %26, i32 2, i32 1)
%28 = load i32, i32* %1
%29 = call i32 @connect_element(i32* %15, i32 %28, i32 0, i32 7)
switch i32 %29, label %34 [
i32 1, label %31
i32 0, label %30
]
30: ; preds = %11
br label %31
31: ; preds = %11, %30
%32 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0), %30 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0), %11 ]
%33 = call i32 @puts(i8* dereferenceable(1) %32)
br label %34
34: ; preds = %31, %11
%35 = load i32, i32* %1
%36 = call i32 @connect_element(i32* %15, i32 %35, i32 8, i32 9)
switch i32 %36, label %41 [
i32 1, label %38
i32 0, label %37
]
37: ; preds = %34
br label %38
38: ; preds = %34, %37
%39 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @str.7, i64 0, i64 0), %37 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0), %34 ]
%40 = call i32 @puts(i8* dereferenceable(1) %39)
br label %41
41: ; preds = %38, %34
%42 = call i32 @free(i32* %15)
ret i32 0
}