#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 */
size_t find_optimal(int, int *);
void union_sets(int x, int y, int parent[]) {
  if (parent[x] == parent[y])
    return;
  else if (find_optimal(y, parent) != y) {
    parent[find_optimal(x, parent)] = find_optimal(y, parent);
  } else {
    parent[find_optimal(y, parent)] = find_optimal(x, parent);
  }
}


x86 assembly (clang, -O0):
<union_sets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x10(%rbp),%rcx
movslq -0x8(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jne    1143 <union_sets+0x33>
jmp    11c6 <union_sets+0xb6>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <find_optimal@plt>
movslq -0x8(%rbp),%rcx
cmp    %rcx,%rax
je     1191 <union_sets+0x81>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <find_optimal@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <find_optimal@plt>
mov    -0x1c(%rbp),%edx
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
jmp    11c1 <union_sets+0xb1>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <find_optimal@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <find_optimal@plt>
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
mov    %edx,(%rax,%rcx,4)
jmp    11c6 <union_sets+0xb6>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<union_sets>:
push   %rbp
push   %r14
push   %rbx
movslq %edi,%rax
mov    (%rdx,%rax,4),%eax
movslq %esi,%rbp
cmp    (%rdx,%rbp,4),%eax
je     1158 <union_sets+0x48>
mov    %rdx,%rbx
mov    %edi,%r14d
mov    %ebp,%edi
mov    %rdx,%rsi
call   1030 <find_optimal@plt>
cmp    %rbp,%rax
mov    %ebp,%edi
cmove  %r14d,%edi
cmove  %ebp,%r14d
mov    %rbx,%rsi
call   1030 <find_optimal@plt>
mov    %rax,%rbp
mov    %r14d,%edi
mov    %rbx,%rsi
call   1030 <find_optimal@plt>
mov    %ebp,(%rbx,%rax,4)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @union_sets(i32 %0, i32 %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%7 = load i32*, i32** %6
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds i32, i32* %7, i64 %9
%11 = load i32, i32* %10
%12 = load i32*, i32** %6
%13 = load i32, i32* %5
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i32, i32* %12, i64 %14
%16 = load i32, i32* %15
%17 = icmp eq i32 %11, %16
br i1 %17, label %18, label %19
18: ; preds = %3
br label %47
19: ; preds = %3
%20 = load i32, i32* %5
%21 = load i32*, i32** %6
%22 = call i64 @find_optimal(i32 %20, i32* %21)
%23 = load i32, i32* %5
%24 = sext i32 %23 to i64
%25 = icmp ne i64 %22, %24
br i1 %25, label %26, label %36
26: ; preds = %19
%27 = load i32, i32* %5
%28 = load i32*, i32** %6
%29 = call i64 @find_optimal(i32 %27, i32* %28)
%30 = trunc i64 %29 to i32
%31 = load i32*, i32** %6
%32 = load i32, i32* %4
%33 = load i32*, i32** %6
%34 = call i64 @find_optimal(i32 %32, i32* %33)
%35 = getelementptr inbounds i32, i32* %31, i64 %34
store i32 %30, i32* %35
br label %46
36: ; preds = %19
%37 = load i32, i32* %4
%38 = load i32*, i32** %6
%39 = call i64 @find_optimal(i32 %37, i32* %38)
%40 = trunc i64 %39 to i32
%41 = load i32*, i32** %6
%42 = load i32, i32* %5
%43 = load i32*, i32** %6
%44 = call i64 @find_optimal(i32 %42, i32* %43)
%45 = getelementptr inbounds i32, i32* %41, i64 %44
store i32 %40, i32* %45
br label %46
46: ; preds = %36, %26
br label %47
47: ; preds = %18, %46
ret void
}

LLVM IR (-O2):
define void @union_sets(i32 %0, i32 %1, i32* %2) {
%4 = sext i32 %0 to i64
%5 = getelementptr inbounds i32, i32* %2, i64 %4
%6 = load i32, i32* %5
%7 = sext i32 %1 to i64
%8 = getelementptr inbounds i32, i32* %2, i64 %7
%9 = load i32, i32* %8
%10 = icmp eq i32 %6, %9
br i1 %10, label %20, label %11
11: ; preds = %3
%12 = tail call i64 @find_optimal(i32 %1, i32* %2)
%13 = icmp eq i64 %12, %7
%14 = select i1 %13, i32 %0, i32 %1
%15 = select i1 %13, i32 %1, i32 %0
%16 = tail call i64 @find_optimal(i32 %14, i32* %2)
%17 = trunc i64 %16 to i32
%18 = tail call i64 @find_optimal(i32 %15, i32* %2)
%19 = getelementptr inbounds i32, i32* %2, i64 %18
store i32 %17, i32* %19
br label %20
20: ; preds = %11, %3
ret void
}