#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 */
struct binTree {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ searchAndToArray(struct binTree *, struct binTree **, int *,
                                    struct binTree **, int, int *);
int commonAncestor(struct binTree *root, int a, int b) {
  int array1[100] = {0};
  int array2[100] = {0};
  int old;
  int found = 0;
  struct binTree *parent;
  struct binTree *node;
  printf("\n Ancestors for the node\n");
  searchAndToArray(root, &parent, &found, &node, a, array1);
  printf("\n");
  searchAndToArray(root, &parent, &found, &node, b, array2);
  int i = 0;
  for (i = 0; i < 100;) {
    if (array1[i] == array2[i]) {
      old = array1[i];
      i++;
    } else
      break;
  }
  return old;
}


x86 assembly (clang, -O0):
<commonAncestor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x350,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x1a0(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1040 <memset@plt>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0x190,%edx
call   1040 <memset@plt>
movl   $0x0,-0x338(%rbp)
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%r8d
lea    -0x1a0(%rbp),%r9
lea    -0x340(%rbp),%rsi
lea    -0x338(%rbp),%rdx
lea    -0x348(%rbp),%rcx
call   1050 <searchAndToArray@plt>
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%r8d
lea    -0x330(%rbp),%r9
lea    -0x340(%rbp),%rsi
lea    -0x338(%rbp),%rdx
lea    -0x348(%rbp),%rcx
call   1050 <searchAndToArray@plt>
movl   $0x0,-0x34c(%rbp)
movl   $0x0,-0x34c(%rbp)
cmpl   $0x64,-0x34c(%rbp)
jge    1254 <commonAncestor+0x124>
movslq -0x34c(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
movslq -0x34c(%rbp),%rcx
cmp    -0x330(%rbp,%rcx,4),%eax
jne    124a <commonAncestor+0x11a>
movslq -0x34c(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
mov    %eax,-0x334(%rbp)
mov    -0x34c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34c(%rbp)
jmp    124f <commonAncestor+0x11f>
jmp    1254 <commonAncestor+0x124>
jmp    11f3 <commonAncestor+0xc3>
mov    -0x334(%rbp),%eax
add    $0x350,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<commonAncestor>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x348,%rsp
mov    %edx,%r15d
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x1b0(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1050 <memset@plt>
lea    0x20(%rsp),%rdi
mov    $0x190,%edx
xor    %esi,%esi
call   1050 <memset@plt>
movl   $0x0,0xc(%rsp)
lea    0xe73(%rip),%rdi
call   1040 <puts@plt>
lea    0x18(%rsp),%r13
lea    0xc(%rsp),%r14
lea    0x10(%rsp),%r12
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
lea    0x1b0(%rsp),%r9
call   1060 <searchAndToArray@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %r15d,%r8d
lea    0x20(%rsp),%r9
call   1060 <searchAndToArray@plt>
mov    0x1b0(%rsp),%edx
cmp    0x20(%rsp),%edx
jne    125c <commonAncestor+0x11c>
mov    $0x5,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x1a0(%rsp,%rcx,4),%esi
mov    %edx,%eax
cmp    0x10(%rsp,%rcx,4),%esi
jne    125c <commonAncestor+0x11c>
mov    0x1a4(%rsp,%rcx,4),%edx
mov    %esi,%eax
cmp    0x14(%rsp,%rcx,4),%edx
jne    125c <commonAncestor+0x11c>
mov    0x1a8(%rsp,%rcx,4),%edi
mov    %edx,%eax
cmp    0x18(%rsp,%rcx,4),%edi
jne    125c <commonAncestor+0x11c>
mov    0x1ac(%rsp,%rcx,4),%esi
mov    %edi,%eax
cmp    0x1c(%rsp,%rcx,4),%esi
jne    125c <commonAncestor+0x11c>
cmp    $0x64,%rcx
je     125a <commonAncestor+0x11a>
mov    0x1b0(%rsp,%rcx,4),%edx
lea    0x5(%rcx),%rdi
mov    %esi,%eax
cmp    0x20(%rsp,%rcx,4),%edx
mov    %rdi,%rcx
je     1200 <commonAncestor+0xc0>
jmp    125c <commonAncestor+0x11c>
mov    %esi,%eax
add    $0x348,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.binTree = type { i32 }
@.str = [26 x i8] c"\0A Ancestors for the node\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
define i32 @commonAncestor(%struct.binTree* %0, i32 %1, i32 %2) {
%4 = alloca %struct.binTree*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [100 x i32]
%8 = alloca [100 x i32]
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.binTree*
%12 = alloca %struct.binTree*
%13 = alloca i32
store %struct.binTree* %0, %struct.binTree** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%14 = bitcast [100 x i32]* %7 to i8*
%15 = bitcast [100 x i32]* %8 to i8*
store i32 0, i32* %10
%16 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%17 = load %struct.binTree*, %struct.binTree** %4
%18 = load i32, i32* %5
%19 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 0
%20 = call i32 @searchAndToArray(%struct.binTree* %17, %struct.binTree** %11, i32* %10, %struct.binTree** %12, i32 %18, i32* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = load %struct.binTree*, %struct.binTree** %4
%23 = load i32, i32* %6
%24 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 0
%25 = call i32 @searchAndToArray(%struct.binTree* %22, %struct.binTree** %11, i32* %10, %struct.binTree** %12, i32 %23, i32* %24)
store i32 0, i32* %13
store i32 0, i32* %13
br label %26
26: ; preds = %47, %3
%27 = load i32, i32* %13
%28 = icmp slt i32 %27, 100
br i1 %28, label %29, label %48
29: ; preds = %26
%30 = load i32, i32* %13
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = load i32, i32* %13
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %8, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = icmp eq i32 %33, %37
br i1 %38, label %39, label %46
39: ; preds = %29
%40 = load i32, i32* %13
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %7, i64 0, i64 %41
%43 = load i32, i32* %42
store i32 %43, i32* %9
%44 = load i32, i32* %13
%45 = add nsw i32 %44, 1
store i32 %45, i32* %13
br label %47
46: ; preds = %29
br label %48
47: ; preds = %39
br label %26
48: ; preds = %46, %26
%49 = load i32, i32* %9
ret i32 %49
}

LLVM IR (-O2):
%struct.binTree = type { i32 }
@str = [25 x i8] c"\0A Ancestors for the node\00"
define i32 @commonAncestor(%struct.binTree* %0, i32 %1, i32 %2) {
%4 = alloca [100 x i32]
%5 = alloca [100 x i32]
%6 = alloca i32
%7 = alloca %struct.binTree*
%8 = alloca %struct.binTree*
%9 = bitcast [100 x i32]* %4 to i8*
%10 = bitcast [100 x i32]* %5 to i8*
%11 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%12 = bitcast %struct.binTree** %7 to i8*
%13 = bitcast %struct.binTree** %8 to i8*
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%15 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 0
%16 = call i32 @searchAndToArray(%struct.binTree* %0, %struct.binTree** %7, i32* %6, %struct.binTree** %8, i32 %1, i32* %15)
%17 = call i32 @putchar(i32 10)
%18 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
%19 = call i32 @searchAndToArray(%struct.binTree* %0, %struct.binTree** %7, i32* %6, %struct.binTree** %8, i32 %2, i32* %18)
%20 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 0
%21 = load i32, i32* %20
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 0
%23 = load i32, i32* %22
%24 = icmp eq i32 %21, %23
br i1 %24, label %25, label %64
25: ; preds = %3, %58
%26 = phi i32 [ %60, %58 ], [ %21, %3 ]
%27 = phi i64 [ %56, %58 ], [ 0, %3 ]
%28 = add nuw nsw i64 %27, 1
%29 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %28
%32 = load i32, i32* %31
%33 = icmp eq i32 %30, %32
br i1 %33, label %34, label %64
34: ; preds = %25
%35 = add nuw nsw i64 %27, 2
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %35
%39 = load i32, i32* %38
%40 = icmp eq i32 %37, %39
br i1 %40, label %41, label %64
41: ; preds = %34
%42 = add nuw nsw i64 %27, 3
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %42
%46 = load i32, i32* %45
%47 = icmp eq i32 %44, %46
br i1 %47, label %48, label %64
48: ; preds = %41
%49 = add nuw nsw i64 %27, 4
%50 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %49
%51 = load i32, i32* %50
%52 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %49
%53 = load i32, i32* %52
%54 = icmp eq i32 %51, %53
br i1 %54, label %55, label %64
55: ; preds = %48
%56 = add nuw nsw i64 %27, 5
%57 = icmp eq i64 %56, 100
br i1 %57, label %64, label %58
58: ; preds = %55
%59 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %56
%60 = load i32, i32* %59
%61 = getelementptr inbounds [100 x i32], [100 x i32]* %5, i64 0, i64 %56
%62 = load i32, i32* %61
%63 = icmp eq i32 %60, %62
br i1 %63, label %25, label %64
64: ; preds = %25, %34, %41, %48, %55, %58, %3
%65 = phi i32 [ undef, %3 ], [ %26, %25 ], [ %30, %34 ], [ %37, %41 ], [ %44, %48 ], [ %51, %55 ], [ %51, %58 ]
ret i32 %65
}