void quick_union_element(int *p_array, int size, int p, int q) {
  if (!p_array) {
    printf("function:%s line: %d p_array is NULL\n", __FUNCTION__, 215);
    return;
  }
  if (p > (size - 1) || q > (size - 1)) {
    printf("index 'p' 'q' are bigger than the max size of array\n");
    printf("p: %3d q: %3d", p, q);
    return;
  }
  int root_p_union = 0;
  if ((root_p_union = quick_root_element(p_array, size, p)) < 0) {
    return;
  }
  int root_q_union = 0;
  if ((root_q_union = quick_root_element(p_array, size, q)) < 0) {
    return;
  }
  p_array[root_q_union] = root_p_union;
}


x86 assembly (clang, -O0):
<quick_union_element>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    115f <quick_union_element+0x3f>
lea    0xeb9(%rip),%rdi
lea    0xed8(%rip),%rsi
mov    $0xd7,%edx
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1208 <quick_union_element+0xe8>
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     1181 <quick_union_element+0x61>
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jle    11a8 <quick_union_element+0x88>
lea    0xeb2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
lea    0xed3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1208 <quick_union_element+0xe8>
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
mov    $0x0,%al
call   1040 <quick_root_element@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11d1 <quick_union_element+0xb1>
jmp    1208 <quick_union_element+0xe8>
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    $0x0,%al
call   1040 <quick_root_element@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    11fa <quick_union_element+0xda>
jmp    1208 <quick_union_element+0xe8>
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<quick_union_element>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1184 <quick_union_element+0x54>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %esi,%ebp
cmp    %edx,%esi
jle    11a8 <quick_union_element+0x78>
cmp    %r14d,%ebp
jle    11a8 <quick_union_element+0x78>
mov    %rdi,%r15
mov    %ebp,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1050 <quick_root_element@plt>
test   %eax,%eax
js     1179 <quick_union_element+0x49>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <quick_root_element@plt>
test   %eax,%eax
js     1179 <quick_union_element+0x49>
mov    %eax,%eax
mov    %ebx,(%r15,%rax,4)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe75(%rip),%rdi
lea    0xe94(%rip),%rsi
mov    $0xd7,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xe7f(%rip),%rdi
mov    %ebx,%esi
mov    %r14d,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [38 x i8] c"function:%s line: %d p_array is NULL\0A\00"
@__FUNCTION__.quick_union_element = [20 x i8] c"quick_union_element\00"
@.str.1 = [53 x i8] c"index 'p' 'q' are bigger than the max size of array\0A\00"
@.str.2 = [14 x i8] c"p: %3d q: %3d\00"
define void @quick_union_element(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32* %0, i32** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32*, i32** %5
%12 = icmp ne i32* %11, null
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__FUNCTION__.quick_union_element, i64 0, i64 0), i32 215)
br label %50
15: ; preds = %4
%16 = load i32, i32* %7
%17 = load i32, i32* %6
%18 = sub nsw i32 %17, 1
%19 = icmp sgt i32 %16, %18
br i1 %19, label %25, label %20
20: ; preds = %15
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = sub nsw i32 %22, 1
%24 = icmp sgt i32 %21, %23
br i1 %24, label %25, label %30
25: ; preds = %20, %15
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %7
%28 = load i32, i32* %8
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %28)
br label %50
30: ; preds = %20
store i32 0, i32* %9
%31 = load i32*, i32** %5
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @quick_root_element to i32 (i32*, i32, i32, ...)*)(i32* %31, i32 %32, i32 %33)
store i32 %34, i32* %9
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %30
br label %50
37: ; preds = %30
store i32 0, i32* %10
%38 = load i32*, i32** %5
%39 = load i32, i32* %6
%40 = load i32, i32* %8
%41 = call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @quick_root_element to i32 (i32*, i32, i32, ...)*)(i32* %38, i32 %39, i32 %40)
store i32 %41, i32* %10
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37
br label %50
44: ; preds = %37
%45 = load i32, i32* %9
%46 = load i32*, i32** %5
%47 = load i32, i32* %10
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %46, i64 %48
store i32 %45, i32* %49
br label %50
50: ; preds = %44, %43, %36, %25, %13
ret void
}

LLVM IR (-O2):
@.str = [38 x i8] c"function:%s line: %d p_array is NULL\0A\00"
@__FUNCTION__.quick_union_element = [20 x i8] c"quick_union_element\00"
@.str.2 = [14 x i8] c"p: %3d q: %3d\00"
@str = [52 x i8] c"index 'p' 'q' are bigger than the max size of array\00"
define void @quick_union_element(i32* %0, i32 %1, i32 %2, i32 %3) {
%5 = icmp eq i32* %0, null
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([20 x i8], [20 x i8]* @__FUNCTION__.quick_union_element, i64 0, i64 0), i32 215)
br label %24
8: ; preds = %4
%9 = icmp sgt i32 %1, %2
%10 = icmp sgt i32 %1, %3
%11 = and i1 %9, %10
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %2, i32 %3)
br label %24
15: ; preds = %8
%16 = tail call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @quick_root_element to i32 (i32*, i32, i32, ...)*)(i32* %0, i32 %1, i32 %2)
%17 = icmp slt i32 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = tail call i32 (i32*, i32, i32, ...) bitcast (i32 (...)* @quick_root_element to i32 (i32*, i32, i32, ...)*)(i32* %0, i32 %1, i32 %3)
%20 = icmp slt i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %18
%22 = zext i32 %19 to i64
%23 = getelementptr inbounds i32, i32* %0, i64 %22
store i32 %16, i32* %23
br label %24
24: ; preds = %15, %18, %21, %6, %12
ret void
}