; LLVM IR from div-bargali/Data-Structures-and-Algorithms :: C++/Data-Structures/BST/check_bst.ll (Z4helpP14BinaryTreeNodeIiEii)

; 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"

%class.BinaryTreeNode = type { i32, ptr, ptr }

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: mustprogress uwtable
define dso_local noundef zeroext i1 @_Z4helpP14BinaryTreeNodeIiEii(ptr noundef %0, i32 noundef %1, i32 noundef %2) #1 {
  %4 = alloca i1, align 1
  %5 = alloca ptr, align 8
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i8, align 1
  %9 = alloca i8, align 1
  %10 = alloca i32, align 4
  store ptr %0, ptr %5, align 8, !tbaa !5
  store i32 %1, ptr %6, align 4, !tbaa !9
  store i32 %2, ptr %7, align 4, !tbaa !9
  %11 = load ptr, ptr %5, align 8, !tbaa !5
  %12 = icmp eq ptr %11, null
  br i1 %12, label %13, label %14

13:                                               ; preds = %3
  store i1 true, ptr %4, align 1
  br label %55

14:                                               ; preds = %3
  %15 = load ptr, ptr %5, align 8, !tbaa !5
  %16 = getelementptr inbounds %class.BinaryTreeNode, ptr %15, i32 0, i32 0
  %17 = load i32, ptr %16, align 8, !tbaa !11
  %18 = load i32, ptr %6, align 4, !tbaa !9
  %19 = icmp sge i32 %17, %18
  br i1 %19, label %20, label %54

20:                                               ; preds = %14
  %21 = load ptr, ptr %5, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.BinaryTreeNode, ptr %21, i32 0, i32 0
  %23 = load i32, ptr %22, align 8, !tbaa !11
  %24 = load i32, ptr %7, align 4, !tbaa !9
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %26, label %54

26:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 1, ptr %8) #2
  %27 = load ptr, ptr %5, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.BinaryTreeNode, ptr %27, i32 0, i32 1
  %29 = load ptr, ptr %28, align 8, !tbaa !13
  %30 = load i32, ptr %6, align 4, !tbaa !9
  %31 = load ptr, ptr %5, align 8, !tbaa !5
  %32 = getelementptr inbounds %class.BinaryTreeNode, ptr %31, i32 0, i32 0
  %33 = load i32, ptr %32, align 8, !tbaa !11
  %34 = sub nsw i32 %33, 1
  %35 = call noundef zeroext i1 @_Z4helpP14BinaryTreeNodeIiEii(ptr noundef %29, i32 noundef %30, i32 noundef %34)
  %36 = zext i1 %35 to i8
  store i8 %36, ptr %8, align 1, !tbaa !14
  call void @llvm.lifetime.start.p0(i64 1, ptr %9) #2
  %37 = load ptr, ptr %5, align 8, !tbaa !5
  %38 = getelementptr inbounds %class.BinaryTreeNode, ptr %37, i32 0, i32 2
  %39 = load ptr, ptr %38, align 8, !tbaa !16
  %40 = load ptr, ptr %5, align 8, !tbaa !5
  %41 = getelementptr inbounds %class.BinaryTreeNode, ptr %40, i32 0, i32 0
  %42 = load i32, ptr %41, align 8, !tbaa !11
  %43 = load i32, ptr %7, align 4, !tbaa !9
  %44 = call noundef zeroext i1 @_Z4helpP14BinaryTreeNodeIiEii(ptr noundef %39, i32 noundef %42, i32 noundef %43)
  %45 = zext i1 %44 to i8
  store i8 %45, ptr %9, align 1, !tbaa !14
  %46 = load i8, ptr %8, align 1, !tbaa !14, !range !17, !noundef !18
  %47 = trunc i8 %46 to i1
  br i1 %47, label %48, label %52

48:                                               ; preds = %26
  %49 = load i8, ptr %9, align 1, !tbaa !14, !range !17, !noundef !18
  %50 = trunc i8 %49 to i1
  br i1 %50, label %51, label %52

51:                                               ; preds = %48
  store i1 true, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %53

52:                                               ; preds = %48, %26
  store i1 false, ptr %4, align 1
  store i32 1, ptr %10, align 4
  br label %53

53:                                               ; preds = %52, %51
  call void @llvm.lifetime.end.p0(i64 1, ptr %9) #2
  call void @llvm.lifetime.end.p0(i64 1, ptr %8) #2
  br label %55

54:                                               ; preds = %20, %14
  store i1 false, ptr %4, align 1
  br label %55

55:                                               ; preds = %54, %53, %13
  %56 = load i1, ptr %4, align 1
  ret i1 %56
}

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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" }
attributes #2 = { nounwind }

!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, !10, i64 0}
!12 = !{!"_ZTS14BinaryTreeNodeIiE", !10, i64 0, !6, i64 8, !6, i64 16}
!13 = !{!12, !6, i64 8}
!14 = !{!15, !15, i64 0}
!15 = !{!"bool", !7, i64 0}
!16 = !{!12, !6, i64 16}
!17 = !{i8 0, i8 2}
!18 = !{}


; 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 nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef zeroext i1 @_Z4helpP14BinaryTreeNodeIiEii(ptr noundef readonly %0, i32 noundef %1, i32 noundef %2) local_unnamed_addr #0 {
  %4 = icmp eq ptr %0, null
  br i1 %4, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3, %tailrecurse
  %.tr2024 = phi i32 [ %5, %tailrecurse ], [ %1, %3 ]
  %.tr23 = phi ptr [ %11, %tailrecurse ], [ %0, %3 ]
  %accumulator.tr22 = phi i1 [ %brmerge.demorgan, %tailrecurse ], [ true, %3 ]
  %5 = load i32, ptr %.tr23, align 8, !tbaa !5
  %.not = icmp sge i32 %5, %.tr2024
  %.not17 = icmp sle i32 %5, %2
  %or.cond.not = and i1 %.not, %.not17
  br i1 %or.cond.not, label %tailrecurse, label %._crit_edge.loopexit

tailrecurse:                                      ; preds = %.lr.ph
  %6 = getelementptr inbounds i8, ptr %.tr23, i64 8
  %7 = load ptr, ptr %6, align 8, !tbaa !11
  %8 = add nsw i32 %5, -1
  %9 = tail call noundef zeroext i1 @_Z4helpP14BinaryTreeNodeIiEii(ptr noundef %7, i32 noundef %.tr2024, i32 noundef %8)
  %10 = getelementptr inbounds i8, ptr %.tr23, i64 16
  %11 = load ptr, ptr %10, align 8, !tbaa !12
  %brmerge.demorgan = and i1 %accumulator.tr22, %9
  %12 = icmp eq ptr %11, null
  br i1 %12, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph, %tailrecurse
  %accumulator.tr.lcssa.ph = phi i1 [ %brmerge.demorgan, %tailrecurse ], [ %accumulator.tr22, %.lr.ph ]
  %13 = and i1 %accumulator.tr.lcssa.ph, %or.cond.not
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %3
  %accumulator.ret.tr = phi i1 [ true, %3 ], [ %13, %._crit_edge.loopexit ]
  ret i1 %accumulator.ret.tr
}

attributes #0 = { mustprogress nofree 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, !7, i64 0}
!6 = !{!"_ZTS14BinaryTreeNodeIiE", !7, i64 0, !10, i64 8, !10, i64 16}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"any pointer", !8, i64 0}
!11 = !{!6, !10, i64 8}
!12 = !{!6, !10, i64 16}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass