; LLVM IR from ahampriyanshu/algo-ds-101 :: Data-Structures/Tree/23-Tree/23Tree.ll (Z6searchP8TreeNodei)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%struct.TreeNode = type { [3 x i32], ptr, ptr, ptr, ptr, ptr, i32 }

; Function Attrs: mustprogress uwtable
define dso_local noundef ptr @_Z6searchP8TreeNodei(ptr noundef %0, i32 noundef %1) #0 {
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store i32 %1, ptr %5, align 4, !tbaa !9
  %6 = load ptr, ptr %4, align 8, !tbaa !5
  %7 = icmp ne ptr %6, null
  br i1 %7, label %9, label %8

8:                                                ; preds = %2
  store ptr null, ptr %3, align 8
  br label %57

9:                                                ; preds = %2
  %10 = load i32, ptr %5, align 4, !tbaa !9
  %11 = load ptr, ptr %4, align 8, !tbaa !5
  %12 = getelementptr inbounds %struct.TreeNode, ptr %11, i32 0, i32 0
  %13 = getelementptr inbounds [3 x i32], ptr %12, i64 0, i64 0
  %14 = load i32, ptr %13, align 8, !tbaa !9
  %15 = icmp slt i32 %10, %14
  br i1 %15, label %16, label %22

16:                                               ; preds = %9
  %17 = load ptr, ptr %4, align 8, !tbaa !5
  %18 = getelementptr inbounds %struct.TreeNode, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !11
  %20 = load i32, ptr %5, align 4, !tbaa !9
  %21 = call noundef ptr @_Z6searchP8TreeNodei(ptr noundef %19, i32 noundef %20)
  store ptr %21, ptr %3, align 8
  br label %57

22:                                               ; preds = %9
  %23 = load i32, ptr %5, align 4, !tbaa !9
  %24 = load ptr, ptr %4, align 8, !tbaa !5
  %25 = getelementptr inbounds %struct.TreeNode, ptr %24, i32 0, i32 0
  %26 = getelementptr inbounds [3 x i32], ptr %25, i64 0, i64 0
  %27 = load i32, ptr %26, align 8, !tbaa !9
  %28 = icmp sgt i32 %23, %27
  br i1 %28, label %29, label %42

29:                                               ; preds = %22
  %30 = load i32, ptr %5, align 4, !tbaa !9
  %31 = load ptr, ptr %4, align 8, !tbaa !5
  %32 = getelementptr inbounds %struct.TreeNode, ptr %31, i32 0, i32 0
  %33 = getelementptr inbounds [3 x i32], ptr %32, i64 0, i64 1
  %34 = load i32, ptr %33, align 4, !tbaa !9
  %35 = icmp slt i32 %30, %34
  br i1 %35, label %36, label %42

36:                                               ; preds = %29
  %37 = load ptr, ptr %4, align 8, !tbaa !5
  %38 = getelementptr inbounds %struct.TreeNode, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !13
  %40 = load i32, ptr %5, align 4, !tbaa !9
  %41 = call noundef ptr @_Z6searchP8TreeNodei(ptr noundef %39, i32 noundef %40)
  store ptr %41, ptr %3, align 8
  br label %57

42:                                               ; preds = %29, %22
  %43 = load i32, ptr %5, align 4, !tbaa !9
  %44 = load ptr, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds %struct.TreeNode, ptr %44, i32 0, i32 0
  %46 = getelementptr inbounds [3 x i32], ptr %45, i64 0, i64 1
  %47 = load i32, ptr %46, align 4, !tbaa !9
  %48 = icmp sgt i32 %43, %47
  br i1 %48, label %49, label %55

49:                                               ; preds = %42
  %50 = load ptr, ptr %4, align 8, !tbaa !5
  %51 = getelementptr inbounds %struct.TreeNode, ptr %50, i32 0, i32 3
  %52 = load ptr, ptr %51, align 8, !tbaa !14
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = call noundef ptr @_Z6searchP8TreeNodei(ptr noundef %52, i32 noundef %53)
  store ptr %54, ptr %3, align 8
  br label %57

55:                                               ; preds = %42
  %56 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %56, ptr %3, align 8
  br label %57

57:                                               ; preds = %55, %49, %36, %16, %8
  %58 = load ptr, ptr %3, align 8
  ret ptr %58
}

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = !{!12, !6, i64 16}
!12 = !{!"_ZTS8TreeNode", !7, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!13 = !{!12, !6, i64 24}
!14 = !{!12, !6, i64 32}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef ptr @_Z6searchP8TreeNodei(ptr noundef readonly %0, i32 noundef %1) local_unnamed_addr #0 {
  %.not20 = icmp eq ptr %0, null
  br i1 %.not20, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %2, %tailrecurse.backedge
  %.tr21 = phi ptr [ %.tr.be, %tailrecurse.backedge ], [ %0, %2 ]
  %3 = load i32, ptr %.tr21, align 8, !tbaa !5
  %4 = icmp sgt i32 %3, %1
  br i1 %4, label %tailrecurse.backedge, label %6

tailrecurse.backedge:                             ; preds = %.lr.ph, %._crit_edge23, %6
  %.sink = phi i64 [ 24, %6 ], [ 32, %._crit_edge23 ], [ 16, %.lr.ph ]
  %5 = getelementptr inbounds i8, ptr %.tr21, i64 %.sink
  %.tr.be = load ptr, ptr %5, align 8, !tbaa !9
  %.not = icmp eq ptr %.tr.be, null
  br i1 %.not, label %._crit_edge, label %.lr.ph

6:                                                ; preds = %.lr.ph
  %7 = icmp slt i32 %3, %1
  %8 = getelementptr inbounds i8, ptr %.tr21, i64 4
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %10 = icmp sgt i32 %9, %1
  %or.cond = select i1 %7, i1 %10, i1 false
  br i1 %or.cond, label %tailrecurse.backedge, label %._crit_edge23

._crit_edge23:                                    ; preds = %6
  %11 = icmp slt i32 %9, %1
  br i1 %11, label %tailrecurse.backedge, label %._crit_edge

._crit_edge:                                      ; preds = %tailrecurse.backedge, %._crit_edge23, %2
  %.0 = phi ptr [ null, %2 ], [ %.tr21, %._crit_edge23 ], [ null, %tailrecurse.backedge ]
  ret ptr %.0
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,InstCombinePass,JumpThreadingPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass