#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*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ findRoot(int);
int /*<<< orphan*/ isvalid(int);
int /*<<< orphan*/ printf(char *);
int connected(int p, int q) {
  if (!isvalid(p) || !isvalid(q)) {
    printf("Program was provided with errornous values, shutting down.\n");
    exit(EXIT_FAILURE);
  }
  return findRoot(p) == findRoot(q);
}


x86 assembly (clang, -O0):
<connected>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <isvalid@plt>
cmp    $0x0,%eax
je     1170 <connected+0x30>
mov    -0x8(%rbp),%edi
call   1030 <isvalid@plt>
cmp    $0x0,%eax
jne    118a <connected+0x4a>
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    -0x4(%rbp),%edi
call   1040 <findRoot@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <findRoot@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connected>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
call   1030 <isvalid@plt>
test   %eax,%eax
je     117d <connected+0x3d>
mov    %ebx,%edi
call   1030 <isvalid@plt>
test   %eax,%eax
je     117d <connected+0x3d>
mov    %ebp,%edi
call   1050 <findRoot@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1050 <findRoot@plt>
xor    %ecx,%ecx
cmp    %rax,%rbp
sete   %cl
mov    %ecx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe7c(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [60 x i8] c"Program was provided with errornous values, shutting down.\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @connected(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%5 = load i32, i32* %3
%6 = call i32 @isvalid(i32 %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* %4
%10 = call i32 @isvalid(i32 %9)
%11 = icmp ne i32 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %8, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %8
%17 = load i32, i32* %3
%18 = call i64 @findRoot(i32 %17)
%19 = load i32, i32* %4
%20 = call i64 @findRoot(i32 %19)
%21 = icmp eq i64 %18, %20
%22 = zext i1 %21 to i32
ret i32 %22
}

LLVM IR (-O2):
@EXIT_FAILURE = global i32 0
@str = [59 x i8] c"Program was provided with errornous values, shutting down.\00"
define i32 @connected(i32 %0, i32 %1) {
%3 = tail call i32 @isvalid(i32 %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = tail call i32 @isvalid(i32 %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %5, %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %5
%13 = tail call i64 @findRoot(i32 %0)
%14 = tail call i64 @findRoot(i32 %1)
%15 = icmp eq i64 %13, %14
%16 = zext i1 %15 to i32
ret i32 %16
}