#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 EXIT_SUCCESS;
int findgroup(int, int *);
int /*<<< orphan*/ join(int, int, int *, int *);
int joingroup(int p, int q, int *parent, int *treesize) {
  int p_parent, q_parent;
  if (p != q) {
    p_parent = findgroup(p, parent);
    q_parent = findgroup(q, parent);
    if (p_parent != q_parent) {
      if (treesize[p_parent] >= treesize[q_parent]) {
        join(p_parent, q_parent, parent, treesize);
      } else {
        join(q_parent, p_parent, parent, treesize);
      }
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<joingroup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
je     11bd <joingroup+0x9d>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <findgroup@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <findgroup@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x20(%rbp),%eax
je     11b8 <joingroup+0x98>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x18(%rbp),%rcx
movslq -0x20(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jl     11a0 <joingroup+0x80>
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <join@plt>
jmp    11b3 <joingroup+0x93>
mov    -0x20(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
call   1040 <join@plt>
jmp    11b8 <joingroup+0x98>
jmp    11bd <joingroup+0x9d>
mov    0x2e1c(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<joingroup>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    %esi,%edi
je     1174 <joingroup+0x54>
mov    %rcx,%r14
mov    %rdx,%rbx
mov    %esi,%ebp
mov    %rdx,%rsi
call   1030 <findgroup@plt>
mov    %eax,%r15d
mov    %ebp,%edi
mov    %rbx,%rsi
call   1030 <findgroup@plt>
cmp    %eax,%r15d
je     1174 <joingroup+0x54>
movslq %r15d,%rcx
mov    (%r14,%rcx,4),%ecx
movslq %eax,%rdx
cmp    (%r14,%rdx,4),%ecx
jge    1164 <joingroup+0x44>
mov    %eax,%edi
mov    %r15d,%esi
jmp    1169 <joingroup+0x49>
mov    %r15d,%edi
mov    %eax,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1040 <join@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EXIT_SUCCESS = global i32 0
define i32 @joingroup(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 = load i32, i32* %6
%13 = icmp ne i32 %11, %12
br i1 %13, label %14, label %50
14: ; preds = %4
%15 = load i32, i32* %5
%16 = load i32*, i32** %7
%17 = call i32 @findgroup(i32 %15, i32* %16)
store i32 %17, i32* %9
%18 = load i32, i32* %6
%19 = load i32*, i32** %7
%20 = call i32 @findgroup(i32 %18, i32* %19)
store i32 %20, i32* %10
%21 = load i32, i32* %9
%22 = load i32, i32* %10
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %49
24: ; preds = %14
%25 = load i32*, i32** %8
%26 = load i32, i32* %9
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = load i32*, i32** %8
%31 = load i32, i32* %10
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = load i32, i32* %33
%35 = icmp sge i32 %29, %34
br i1 %35, label %36, label %42
36: ; preds = %24
%37 = load i32, i32* %9
%38 = load i32, i32* %10
%39 = load i32*, i32** %7
%40 = load i32*, i32** %8
%41 = call i32 @join(i32 %37, i32 %38, i32* %39, i32* %40)
br label %48
42: ; preds = %24
%43 = load i32, i32* %10
%44 = load i32, i32* %9
%45 = load i32*, i32** %7
%46 = load i32*, i32** %8
%47 = call i32 @join(i32 %43, i32 %44, i32* %45, i32* %46)
br label %48
48: ; preds = %42, %36
br label %49
49: ; preds = %48, %14
br label %50
50: ; preds = %49, %4
%51 = load i32, i32* @EXIT_SUCCESS
ret i32 %51
}

LLVM IR (-O2):
@EXIT_SUCCESS = global i32 0
define i32 @joingroup(i32 %0, i32 %1, i32* %2, i32* %3) {
%5 = icmp eq i32 %0, %1
br i1 %5, label %22, label %6
6: ; preds = %4
%7 = tail call i32 @findgroup(i32 %0, i32* %2)
%8 = tail call i32 @findgroup(i32 %1, i32* %2)
%9 = icmp eq i32 %7, %8
br i1 %9, label %22, label %10
10: ; preds = %6
%11 = sext i32 %7 to i64
%12 = getelementptr inbounds i32, i32* %3, i64 %11
%13 = load i32, i32* %12
%14 = sext i32 %8 to i64
%15 = getelementptr inbounds i32, i32* %3, i64 %14
%16 = load i32, i32* %15
%17 = icmp slt i32 %13, %16
br i1 %17, label %20, label %18
18: ; preds = %10
%19 = tail call i32 @join(i32 %7, i32 %8, i32* %2, i32* %3)
br label %22
20: ; preds = %10
%21 = tail call i32 @join(i32 %8, i32 %7, i32* %2, i32* %3)
br label %22
22: ; preds = %6, %20, %18, %4
%23 = load i32, i32* @EXIT_SUCCESS
ret i32 %23
}