#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*/ free(int *);
int /*<<< orphan*/ getchar();
scalar_t__ init_element(int *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ print_union(int *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ quick_union_element(int *, int, int, int);
int /*<<< orphan*/ scanf(char *, 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);
  if (init_element(all_element, num) < 0) {
    return 0;
  }
  if (num < 10) {
    return 0;
  }
  quick_union_element(all_element, num, 2, 9);
  quick_union_element(all_element, num, 4, 3);
  quick_union_element(all_element, num, 2, 4);
  quick_union_element(all_element, num, 5, 6);
  printf("Before union(6,9)\n");
  print_union(all_element, num);
  printf("After union(6,9)\n");
  quick_union_element(all_element, num, 6, 9);
  print_union(all_element, num);
  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   1040 <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   1070 <getchar@plt>
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
jmp    11b1 <main+0x31>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1050 <init_element@plt>
cmp    $0x0,%rax
jge    1223 <main+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    12ef <main+0x16f>
cmpl   $0xa,-0x8(%rbp)
jge    1239 <main+0xb9>
movl   $0x0,-0x4(%rbp)
jmp    12ef <main+0x16f>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
mov    $0x9,%ecx
call   1090 <quick_union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x4,%edx
mov    $0x3,%ecx
call   1090 <quick_union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x2,%edx
mov    $0x4,%ecx
call   1090 <quick_union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x5,%edx
mov    $0x6,%ecx
call   1090 <quick_union_element@plt>
lea    0xdbe(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <print_union@plt>
lea    0xdb9(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    $0x6,%edx
mov    $0x9,%ecx
call   1090 <quick_union_element@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1060 <print_union@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%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   1040 <puts@plt>
lea    0xe5c(%rip),%rdi
lea    0xc(%rsp),%rsi
call   10a0 <scanf@plt>
test   %eax,%eax
jne    11ee <main+0x6e>
lea    0xe9e(%rip),%r14
lea    0xe40(%rip),%r15
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1070 <getchar@plt>
mov    %r14,%rdi
call   1040 <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   1080 <malloc@plt>
mov    %rax,%rbx
mov    0xc(%rsp),%esi
mov    %rax,%rdi
call   1050 <init_element@plt>
test   %rax,%rax
js     12c1 <main+0x141>
mov    0xc(%rsp),%esi
cmp    $0xa,%esi
jl     12c1 <main+0x141>
mov    %rbx,%rdi
mov    $0x2,%edx
mov    $0x9,%ecx
call   1090 <quick_union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x4,%edx
mov    $0x3,%ecx
call   1090 <quick_union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x2,%edx
mov    $0x4,%ecx
call   1090 <quick_union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x5,%edx
mov    $0x6,%ecx
call   1090 <quick_union_element@plt>
lea    0xdba(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <print_union@plt>
lea    0xdb4(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    $0x6,%edx
mov    $0x9,%ecx
call   1090 <quick_union_element@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1060 <print_union@plt>
mov    %rbx,%rdi
call   1030 <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 = [19 x i8] c"Before union(6,9)\0A\00"
@.str.4 = [18 x i8] c"After union(6,9)\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 i64 @init_element(i32* %20, i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %13
store i32 0, i32* %1
br label %55
25: ; preds = %13
%26 = load i32, i32* %2
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %29
28: ; preds = %25
store i32 0, i32* %1
br label %55
29: ; preds = %25
%30 = load i32*, i32** %4
%31 = load i32, i32* %2
%32 = call i32 @quick_union_element(i32* %30, i32 %31, i32 2, i32 9)
%33 = load i32*, i32** %4
%34 = load i32, i32* %2
%35 = call i32 @quick_union_element(i32* %33, i32 %34, i32 4, i32 3)
%36 = load i32*, i32** %4
%37 = load i32, i32* %2
%38 = call i32 @quick_union_element(i32* %36, i32 %37, i32 2, i32 4)
%39 = load i32*, i32** %4
%40 = load i32, i32* %2
%41 = call i32 @quick_union_element(i32* %39, i32 %40, i32 5, i32 6)
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32*, i32** %4
%44 = load i32, i32* %2
%45 = call i32 @print_union(i32* %43, i32 %44)
%46 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32*, i32** %4
%48 = load i32, i32* %2
%49 = call i32 @quick_union_element(i32* %47, i32 %48, i32 6, i32 9)
%50 = load i32*, i32** %4
%51 = load i32, i32* %2
%52 = call i32 @print_union(i32* %50, i32 %51)
%53 = load i32*, i32** %4
%54 = call i32 @free(i32* %53)
store i32* null, i32** %4
store i32 0, i32* %1
br label %55
55: ; preds = %29, %28, %24
%56 = load i32, i32* %1
ret i32 %56
}

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.5 = [18 x i8] c"Before union(6,9)\00"
@str.6 = [17 x i8] c"After union(6,9)\00"
@str.7 = [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.7, 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 i64 @init_element(i32* %15, i32 %16)
%18 = icmp slt i64 %17, 0
br i1 %18, label %39, label %19
19: ; preds = %11
%20 = load i32, i32* %1
%21 = icmp slt i32 %20, 10
br i1 %21, label %39, label %22
22: ; preds = %19
%23 = call i32 @quick_union_element(i32* %15, i32 %20, i32 2, i32 9)
%24 = load i32, i32* %1
%25 = call i32 @quick_union_element(i32* %15, i32 %24, i32 4, i32 3)
%26 = load i32, i32* %1
%27 = call i32 @quick_union_element(i32* %15, i32 %26, i32 2, i32 4)
%28 = load i32, i32* %1
%29 = call i32 @quick_union_element(i32* %15, i32 %28, i32 5, i32 6)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
%31 = load i32, i32* %1
%32 = call i32 @print_union(i32* %15, i32 %31)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.6, i64 0, i64 0))
%34 = load i32, i32* %1
%35 = call i32 @quick_union_element(i32* %15, i32 %34, i32 6, i32 9)
%36 = load i32, i32* %1
%37 = call i32 @print_union(i32* %15, i32 %36)
%38 = call i32 @free(i32* %15)
br label %39
39: ; preds = %19, %11, %22
ret i32 0
}