#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*/ assert(int *);
int dsf_canonify(int *, int);
int /*<<< orphan*/ dsf_merge(int *, int, int);
int *rhofree(int *, int);
void merge(int *dsf, int *connected, int a, int b) {
  int c;
  assert(dsf);
  assert(connected);
  assert(rhofree(connected, a));
  assert(rhofree(connected, b));
  a = dsf_canonify(dsf, a);
  b = dsf_canonify(dsf, b);
  if (a == b)
    return;
  dsf_merge(dsf, a, b);
  c = connected[a];
  connected[a] = connected[b];
  connected[b] = c;
  assert(rhofree(connected, a));
  assert(rhofree(connected, b));
}


x86 assembly (clang, -O0):
<merge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <dsf_canonify@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <dsf_canonify@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    11bf <merge+0x7f>
jmp    1228 <merge+0xe8>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1060 <dsf_merge@plt>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<merge>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%r15d
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <assert@plt>
mov    %rbx,%rdi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <dsf_canonify@plt>
mov    %eax,%ebp
mov    %r14,%rdi
mov    %r15d,%esi
call   1030 <dsf_canonify@plt>
cmp    %eax,%ebp
jne    11aa <merge+0x6a>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r15d
mov    %r14,%rdi
mov    %ebp,%esi
mov    %eax,%edx
call   1060 <dsf_merge@plt>
movslq %ebp,%rax
mov    (%rbx,%rax,4),%ecx
movslq %r15d,%rdx
mov    (%rbx,%rdx,4),%esi
mov    %esi,(%rbx,%rax,4)
mov    %ecx,(%rbx,%rdx,4)
mov    %rbx,%rdi
mov    %ebp,%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
call   1040 <assert@plt>
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <rhofree@plt>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <assert@plt>

LLVM IR (-O0):
define void @merge(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32* %0, i32** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32*, i32** %5
%11 = call i32 @assert(i32* %10)
%12 = load i32*, i32** %6
%13 = call i32 @assert(i32* %12)
%14 = load i32*, i32** %6
%15 = load i32, i32* %7
%16 = call i32* @rhofree(i32* %14, i32 %15)
%17 = call i32 @assert(i32* %16)
%18 = load i32*, i32** %6
%19 = load i32, i32* %8
%20 = call i32* @rhofree(i32* %18, i32 %19)
%21 = call i32 @assert(i32* %20)
%22 = load i32*, i32** %5
%23 = load i32, i32* %7
%24 = call i32 @dsf_canonify(i32* %22, i32 %23)
store i32 %24, i32* %7
%25 = load i32*, i32** %5
%26 = load i32, i32* %8
%27 = call i32 @dsf_canonify(i32* %25, i32 %26)
store i32 %27, i32* %8
%28 = load i32, i32* %7
%29 = load i32, i32* %8
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %4
br label %64
32: ; preds = %4
%33 = load i32*, i32** %5
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 @dsf_merge(i32* %33, i32 %34, i32 %35)
%37 = load i32*, i32** %6
%38 = load i32, i32* %7
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
store i32 %41, i32* %9
%42 = load i32*, i32** %6
%43 = load i32, i32* %8
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = load i32*, i32** %6
%48 = load i32, i32* %7
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i32, i32* %47, i64 %49
store i32 %46, i32* %50
%51 = load i32, i32* %9
%52 = load i32*, i32** %6
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %52, i64 %54
store i32 %51, i32* %55
%56 = load i32*, i32** %6
%57 = load i32, i32* %7
%58 = call i32* @rhofree(i32* %56, i32 %57)
%59 = call i32 @assert(i32* %58)
%60 = load i32*, i32** %6
%61 = load i32, i32* %8
%62 = call i32* @rhofree(i32* %60, i32 %61)
%63 = call i32 @assert(i32* %62)
br label %64
64: ; preds = %32, %31
ret void
}

LLVM IR (-O2):
define void @merge(i32* %0, i32* %1, i32 %2, i32 %3) {
%5 = tail call i32 @assert(i32* %0)
%6 = tail call i32 @assert(i32* %1)
%7 = tail call i32* @rhofree(i32* %1, i32 %2)
%8 = tail call i32 @assert(i32* %7)
%9 = tail call i32* @rhofree(i32* %1, i32 %3)
%10 = tail call i32 @assert(i32* %9)
%11 = tail call i32 @dsf_canonify(i32* %0, i32 %2)
%12 = tail call i32 @dsf_canonify(i32* %0, i32 %3)
%13 = icmp eq i32 %11, %12
br i1 %13, label %26, label %14
14: ; preds = %4
%15 = tail call i32 @dsf_merge(i32* %0, i32 %11, i32 %12)
%16 = sext i32 %11 to i64
%17 = getelementptr inbounds i32, i32* %1, i64 %16
%18 = load i32, i32* %17
%19 = sext i32 %12 to i64
%20 = getelementptr inbounds i32, i32* %1, i64 %19
%21 = load i32, i32* %20
store i32 %21, i32* %17
store i32 %18, i32* %20
%22 = tail call i32* @rhofree(i32* %1, i32 %11)
%23 = tail call i32 @assert(i32* %22)
%24 = tail call i32* @rhofree(i32* %1, i32 %12)
%25 = tail call i32 @assert(i32* %24)
br label %26
26: ; preds = %4, %14
ret void
}