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

; 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.isBSTReturn = type { i8, i32, i32 }
%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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

; Function Attrs: mustprogress uwtable
define dso_local { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr noundef %0) #2 {
  %2 = alloca %class.isBSTReturn, align 4
  %3 = alloca ptr, align 8
  %4 = alloca %class.isBSTReturn, align 4
  %5 = alloca { i64, i32 }, align 8
  %6 = alloca %class.isBSTReturn, align 4
  %7 = alloca { i64, i32 }, align 8
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i8, align 1
  %11 = alloca { i64, i32 }, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  store ptr null, ptr %3, align 8, !tbaa !5
  br i1 false, label %12, label %16

12:                                               ; preds = %1
  %13 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 0
  store i8 1, ptr %13, align 4, !tbaa !9
  %14 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 1
  store i32 2147483647, ptr %14, align 4, !tbaa !13
  %15 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 2
  store i32 -2147483648, ptr %15, align 4, !tbaa !14
  br label %71

16:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 12, ptr %4) #4
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.BinaryTreeNode, ptr %17, i32 0, i32 1
  %19 = load ptr, ptr %18, align 8, !tbaa !15
  %20 = call { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr noundef %19)
  store { i64, i32 } %20, ptr %5, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %4, ptr align 8 %5, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 12, ptr %6) #4
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = getelementptr inbounds %class.BinaryTreeNode, ptr %21, i32 0, i32 2
  %23 = load ptr, ptr %22, align 8, !tbaa !17
  %24 = call { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr noundef %23)
  store { i64, i32 } %24, ptr %7, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %6, ptr align 8 %7, i64 12, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %25 = load ptr, ptr %3, align 8, !tbaa !5
  %26 = getelementptr inbounds %class.BinaryTreeNode, ptr %25, i32 0, i32 0
  %27 = getelementptr inbounds %class.isBSTReturn, ptr %4, i32 0, i32 1
  %28 = getelementptr inbounds %class.isBSTReturn, ptr %6, i32 0, i32 1
  %29 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %27, ptr noundef nonnull align 4 dereferenceable(4) %28)
  %30 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %26, ptr noundef nonnull align 4 dereferenceable(4) %29)
  %31 = load i32, ptr %30, align 4, !tbaa !18
  store i32 %31, ptr %8, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %32 = load ptr, ptr %3, align 8, !tbaa !5
  %33 = getelementptr inbounds %class.BinaryTreeNode, ptr %32, i32 0, i32 0
  %34 = getelementptr inbounds %class.isBSTReturn, ptr %4, i32 0, i32 2
  %35 = getelementptr inbounds %class.isBSTReturn, ptr %6, i32 0, i32 2
  %36 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %34, ptr noundef nonnull align 4 dereferenceable(4) %35)
  %37 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %33, ptr noundef nonnull align 4 dereferenceable(4) %36)
  %38 = load i32, ptr %37, align 4, !tbaa !18
  store i32 %38, ptr %9, align 4, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 1, ptr %10) #4
  %39 = load ptr, ptr %3, align 8, !tbaa !5
  %40 = getelementptr inbounds %class.BinaryTreeNode, ptr %39, i32 0, i32 0
  %41 = load i32, ptr %40, align 8, !tbaa !19
  %42 = getelementptr inbounds %class.isBSTReturn, ptr %4, i32 0, i32 2
  %43 = load i32, ptr %42, align 4, !tbaa !14
  %44 = icmp sgt i32 %41, %43
  br i1 %44, label %45, label %60

45:                                               ; preds = %16
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.BinaryTreeNode, ptr %46, i32 0, i32 0
  %48 = load i32, ptr %47, align 8, !tbaa !19
  %49 = getelementptr inbounds %class.isBSTReturn, ptr %6, i32 0, i32 1
  %50 = load i32, ptr %49, align 4, !tbaa !13
  %51 = icmp slt i32 %48, %50
  br i1 %51, label %52, label %60

52:                                               ; preds = %45
  %53 = getelementptr inbounds %class.isBSTReturn, ptr %4, i32 0, i32 0
  %54 = load i8, ptr %53, align 4, !tbaa !9, !range !20, !noundef !21
  %55 = trunc i8 %54 to i1
  br i1 %55, label %56, label %60

56:                                               ; preds = %52
  %57 = getelementptr inbounds %class.isBSTReturn, ptr %6, i32 0, i32 0
  %58 = load i8, ptr %57, align 4, !tbaa !9, !range !20, !noundef !21
  %59 = trunc i8 %58 to i1
  br label %60

60:                                               ; preds = %56, %52, %45, %16
  %61 = phi i1 [ false, %52 ], [ false, %45 ], [ false, %16 ], [ %59, %56 ]
  %62 = zext i1 %61 to i8
  store i8 %62, ptr %10, align 1, !tbaa !22
  %63 = load i32, ptr %8, align 4, !tbaa !18
  %64 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 1
  store i32 %63, ptr %64, align 4, !tbaa !13
  %65 = load i32, ptr %9, align 4, !tbaa !18
  %66 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 2
  store i32 %65, ptr %66, align 4, !tbaa !14
  %67 = load i8, ptr %10, align 1, !tbaa !22, !range !20, !noundef !21
  %68 = trunc i8 %67 to i1
  %69 = getelementptr inbounds %class.isBSTReturn, ptr %2, i32 0, i32 0
  %70 = zext i1 %68 to i8
  store i8 %70, ptr %69, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 1, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 12, ptr %4) #4
  br label %71

71:                                               ; preds = %60, %12
  call void @llvm.memcpy.p0.p0.i64(ptr align 8 %11, ptr align 4 %2, i64 12, i1 false)
  %72 = load { i64, i32 }, ptr %11, align 8
  ret { i64, i32 } %72
}

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #1

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress nounwind 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 = { 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 #3 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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, !11, i64 0}
!10 = !{!"_ZTS11isBSTReturn", !11, i64 0, !12, i64 4, !12, i64 8}
!11 = !{!"bool", !7, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!10, !12, i64 4}
!14 = !{!10, !12, i64 8}
!15 = !{!16, !6, i64 8}
!16 = !{!"_ZTS14BinaryTreeNodeIiE", !12, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 16}
!18 = !{!12, !12, i64 0}
!19 = !{!16, !12, i64 0}
!20 = !{i8 0, i8 2}
!21 = !{}
!22 = !{!11, !11, i64 0}


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

%class.isBSTReturn = type { i8, i32, i32 }

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
define dso_local { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr nocapture readnone %0) local_unnamed_addr #2 {
  %2 = alloca %class.isBSTReturn, align 8
  %3 = alloca %class.isBSTReturn, align 8
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %2) #3
  %4 = tail call { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr poison)
  %.fca.0.extract5 = extractvalue { i64, i32 } %4, 0
  %.fca.1.extract6 = extractvalue { i64, i32 } %4, 1
  store i64 %.fca.0.extract5, ptr %2, align 8
  %.sroa.28.0..sroa_idx = getelementptr inbounds i8, ptr %2, i64 8
  store i32 %.fca.1.extract6, ptr %.sroa.28.0..sroa_idx, align 8
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %3) #3
  %5 = tail call { i64, i32 } @_Z5isBSTP14BinaryTreeNodeIiE(ptr poison)
  %.fca.0.extract = extractvalue { i64, i32 } %5, 0
  %.fca.1.extract = extractvalue { i64, i32 } %5, 1
  store i64 %.fca.0.extract, ptr %3, align 8
  %.sroa.24.0..sroa_idx = getelementptr inbounds i8, ptr %3, i64 8
  store i32 %.fca.1.extract, ptr %.sroa.24.0..sroa_idx, align 8
  %6 = getelementptr inbounds i8, ptr %2, i64 4
  %7 = getelementptr inbounds i8, ptr %3, i64 4
  %8 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %9 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) null, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %.sroa.28.0..sroa_idx, ptr noundef nonnull align 4 dereferenceable(4) %.sroa.24.0..sroa_idx)
  %12 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) null, ptr noundef nonnull align 4 dereferenceable(4) %11)
  %13 = load i32, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %3) #3
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %2) #3
  %.sroa.216.0.insert.ext = zext i32 %10 to i64
  %.sroa.216.0.insert.shift = shl nuw i64 %.sroa.216.0.insert.ext, 32
  %.fca.0.insert = insertvalue { i64, i32 } poison, i64 %.sroa.216.0.insert.shift, 0
  %.fca.1.insert = insertvalue { i64, i32 } %.fca.0.insert, i32 %13, 1
  ret { i64, i32 } %.fca.1.insert
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { inlinehint mustprogress nounwind 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 = { mustprogress nounwind 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 #3 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}


; Effective O3 passes: DeadArgumentEliminationPass,EarlyCSEPass,GlobalOptPass,IPSCCPPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,PostOrderFunctionAttrsPass,SROAPass,SimplifyCFGPass,TailCallElimPass