#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 */
typedef size_t int32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
__attribute__((visibility("hidden"))) int32_t dset_find(int32_t x, int32_t *S) {
  if (x == 0) {
    printf("Oh dear, you tried to find zero in your "
           "disjoint set, and it is not there!\n");
    return 0;
  }
  if (S[x] != x) {
    S[x] = dset_find(S[x], S);
  }
  return S[x];
}


x86 assembly (clang, -O0):
<dset_find>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1144 <dset_find+0x34>
lea    0xece(%rip),%rdi
call   1030 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    118e <dset_find+0x7e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x10(%rbp),%rax
je     117e <dset_find+0x6e>
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
call   1110 <dset_find>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dset_find>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1139 <dset_find+0x29>
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi,%rdi,8),%rdi
cmp    %rbx,%rdi
je     1147 <dset_find+0x37>
mov    %r14,%rsi
call   1110 <dset_find>
mov    %rax,(%r14,%rbx,8)
mov    %rax,%rbx
jmp    1147 <dset_find+0x37>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [76 x i8] c"Oh dear, you tried to find zero in your disjoint set, and it is not there!\0A\00"
define hidden i64 @dset_find(i64 %0, i64* %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64*
store i64 %0, i64* %4
store i64* %1, i64** %5
%6 = load i64, i64* %4
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @printf(i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
store i64 0, i64* %3
br label %32
10: ; preds = %2
%11 = load i64*, i64** %5
%12 = load i64, i64* %4
%13 = getelementptr inbounds i64, i64* %11, i64 %12
%14 = load i64, i64* %13
%15 = load i64, i64* %4
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %27
17: ; preds = %10
%18 = load i64*, i64** %5
%19 = load i64, i64* %4
%20 = getelementptr inbounds i64, i64* %18, i64 %19
%21 = load i64, i64* %20
%22 = load i64*, i64** %5
%23 = call i64 @dset_find(i64 %21, i64* %22)
%24 = load i64*, i64** %5
%25 = load i64, i64* %4
%26 = getelementptr inbounds i64, i64* %24, i64 %25
store i64 %23, i64* %26
br label %27
27: ; preds = %17, %10
%28 = load i64*, i64** %5
%29 = load i64, i64* %4
%30 = getelementptr inbounds i64, i64* %28, i64 %29
%31 = load i64, i64* %30
store i64 %31, i64* %3
br label %32
32: ; preds = %27, %8
%33 = load i64, i64* %3
ret i64 %33
}

LLVM IR (-O2):
@str = [75 x i8] c"Oh dear, you tried to find zero in your disjoint set, and it is not there!\00"
define hidden i64 @dset_find(i64 %0, i64* nocapture %1) {
%3 = icmp eq i64 %0, 0
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([75 x i8], [75 x i8]* @str, i64 0, i64 0))
br label %12
6: ; preds = %2
%7 = getelementptr inbounds i64, i64* %1, i64 %0
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, %0
br i1 %9, label %12, label %10
10: ; preds = %6
%11 = tail call i64 @dset_find(i64 %8, i64* %1)
store i64 %11, i64* %7
br label %12
12: ; preds = %6, %10, %4
%13 = phi i64 [ 0, %4 ], [ %11, %10 ], [ %0, %6 ]
ret i64 %13
}