; LLVM IR from Lakhankumawat/LearnCPP :: T-Tree/B-BinaryTree/LargestBSTinBT.ll (Z3BstP4Node)

; 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.bst = type <{ i8, [3 x i8], i32, i32, [4 x i8], ptr, i32, [4 x i8] }>
%class.Node = 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 void @_Z3BstP4Node(ptr dead_on_unwind noalias writable sret(%class.bst) align 8 %0, ptr noundef %1) #1 {
  %3 = alloca ptr, align 8
  %4 = alloca %class.bst, align 8
  %5 = alloca %class.bst, align 8
  store ptr %1, ptr %3, align 8, !tbaa !5
  %6 = load ptr, ptr %3, align 8, !tbaa !5
  %7 = icmp eq ptr %6, null
  br i1 %7, label %8, label %12

8:                                                ; preds = %2
  call void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28) %0) #3
  %9 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 0
  store i8 1, ptr %9, align 8, !tbaa !9
  %10 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 2
  store i32 -2147483648, ptr %10, align 4, !tbaa !13
  %11 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 3
  store i32 2147483647, ptr %11, align 8, !tbaa !14
  br label %100

12:                                               ; preds = %2
  call void @llvm.lifetime.start.p0(i64 32, ptr %4) #3
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %class.Node, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  call void @_Z3BstP4Node(ptr dead_on_unwind writable sret(%class.bst) align 8 %4, ptr noundef %15)
  call void @llvm.lifetime.start.p0(i64 32, ptr %5) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  %17 = getelementptr inbounds %class.Node, ptr %16, i32 0, i32 2
  %18 = load ptr, ptr %17, align 8, !tbaa !17
  call void @_Z3BstP4Node(ptr dead_on_unwind writable sret(%class.bst) align 8 %5, ptr noundef %18)
  call void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28) %0) #3
  %19 = load ptr, ptr %3, align 8, !tbaa !5
  %20 = getelementptr inbounds %class.Node, ptr %19, i32 0, i32 0
  %21 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 2
  %22 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 2
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %21, ptr noundef nonnull align 4 dereferenceable(4) %22)
  %24 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %23)
  %25 = load i32, ptr %24, align 4, !tbaa !18
  %26 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 2
  store i32 %25, ptr %26, align 4, !tbaa !13
  %27 = load ptr, ptr %3, align 8, !tbaa !5
  %28 = getelementptr inbounds %class.Node, ptr %27, i32 0, i32 0
  %29 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 3
  %30 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 3
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %29, ptr noundef nonnull align 4 dereferenceable(4) %30)
  %32 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %28, ptr noundef nonnull align 4 dereferenceable(4) %31)
  %33 = load i32, ptr %32, align 4, !tbaa !18
  %34 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 3
  store i32 %33, ptr %34, align 8, !tbaa !14
  %35 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 0
  %36 = load i8, ptr %35, align 8, !tbaa !9, !range !19, !noundef !20
  %37 = trunc i8 %36 to i1
  %38 = zext i1 %37 to i32
  %39 = icmp eq i32 %38, 1
  br i1 %39, label %40, label %62

40:                                               ; preds = %12
  %41 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 0
  %42 = load i8, ptr %41, align 8, !tbaa !9, !range !19, !noundef !20
  %43 = trunc i8 %42 to i1
  %44 = zext i1 %43 to i32
  %45 = icmp eq i32 %44, 1
  br i1 %45, label %46, label %62

46:                                               ; preds = %40
  %47 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 2
  %48 = load i32, ptr %47, align 4, !tbaa !13
  %49 = load ptr, ptr %3, align 8, !tbaa !5
  %50 = getelementptr inbounds %class.Node, ptr %49, i32 0, i32 0
  %51 = load i32, ptr %50, align 8, !tbaa !21
  %52 = icmp slt i32 %48, %51
  br i1 %52, label %53, label %62

53:                                               ; preds = %46
  %54 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 3
  %55 = load i32, ptr %54, align 8, !tbaa !14
  %56 = load ptr, ptr %3, align 8, !tbaa !5
  %57 = getelementptr inbounds %class.Node, ptr %56, i32 0, i32 0
  %58 = load i32, ptr %57, align 8, !tbaa !21
  %59 = icmp sgt i32 %55, %58
  br i1 %59, label %60, label %62

60:                                               ; preds = %53
  %61 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 0
  store i8 1, ptr %61, align 8, !tbaa !9
  br label %62

62:                                               ; preds = %60, %53, %46, %40, %12
  %63 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 0
  %64 = load i8, ptr %63, align 8, !tbaa !9, !range !19, !noundef !20
  %65 = trunc i8 %64 to i1
  %66 = zext i1 %65 to i32
  %67 = icmp eq i32 %66, 1
  br i1 %67, label %68, label %78

68:                                               ; preds = %62
  %69 = load ptr, ptr %3, align 8, !tbaa !5
  %70 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 5
  store ptr %69, ptr %70, align 8, !tbaa !22
  %71 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 6
  %72 = load i32, ptr %71, align 8, !tbaa !23
  %73 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 6
  %74 = load i32, ptr %73, align 8, !tbaa !23
  %75 = add nsw i32 %72, %74
  %76 = add nsw i32 %75, 1
  %77 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 6
  store i32 %76, ptr %77, align 8, !tbaa !23
  br label %99

78:                                               ; preds = %62
  %79 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 6
  %80 = load i32, ptr %79, align 8, !tbaa !23
  %81 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 6
  %82 = load i32, ptr %81, align 8, !tbaa !23
  %83 = icmp sgt i32 %80, %82
  br i1 %83, label %84, label %91

84:                                               ; preds = %78
  %85 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 5
  %86 = load ptr, ptr %85, align 8, !tbaa !22
  %87 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 5
  store ptr %86, ptr %87, align 8, !tbaa !22
  %88 = getelementptr inbounds %class.bst, ptr %4, i32 0, i32 6
  %89 = load i32, ptr %88, align 8, !tbaa !23
  %90 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 6
  store i32 %89, ptr %90, align 8, !tbaa !23
  br label %98

91:                                               ; preds = %78
  %92 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 5
  %93 = load ptr, ptr %92, align 8, !tbaa !22
  %94 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 5
  store ptr %93, ptr %94, align 8, !tbaa !22
  %95 = getelementptr inbounds %class.bst, ptr %5, i32 0, i32 6
  %96 = load i32, ptr %95, align 8, !tbaa !23
  %97 = getelementptr inbounds %class.bst, ptr %0, i32 0, i32 6
  store i32 %96, ptr %97, align 8, !tbaa !23
  br label %98

98:                                               ; preds = %91, %84
  br label %99

99:                                               ; preds = %98, %68
  call void @llvm.lifetime.end.p0(i64 32, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr %4) #3
  br label %100

100:                                              ; preds = %99, %8
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28)) unnamed_addr #2 align 2

; 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)) #2

; 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)) #2

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 = { 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 #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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !11, i64 0}
!10 = !{!"_ZTS3bst", !11, i64 0, !12, i64 4, !12, i64 8, !6, i64 16, !12, i64 24}
!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 = !{!"_ZTS4Node", !12, i64 0, !6, i64 8, !6, i64 16}
!17 = !{!16, !6, i64 16}
!18 = !{!12, !12, i64 0}
!19 = !{i8 0, i8 2}
!20 = !{}
!21 = !{!16, !12, i64 0}
!22 = !{!10, !6, i64 16}
!23 = !{!10, !12, i64 24}


; 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.bst = type <{ i8, [3 x i8], i32, i32, [4 x i8], ptr, i32, [4 x i8] }>

; 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: mustprogress nounwind uwtable
define dso_local void @_Z3BstP4Node(ptr dead_on_unwind noalias writable sret(%class.bst) align 8 %0, ptr noundef %1) local_unnamed_addr #1 {
  %3 = alloca %class.bst, align 8
  %4 = alloca %class.bst, align 8
  %5 = icmp eq ptr %1, null
  br i1 %5, label %6, label %9

6:                                                ; preds = %2
  tail call void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28) %0) #3
  store i8 1, ptr %0, align 8, !tbaa !5
  %7 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 -2147483648, ptr %7, align 4, !tbaa !12
  %8 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 2147483647, ptr %8, align 8, !tbaa !13
  br label %65

9:                                                ; preds = %2
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %3) #3
  %10 = getelementptr inbounds i8, ptr %1, i64 8
  %11 = load ptr, ptr %10, align 8, !tbaa !14
  call void @_Z3BstP4Node(ptr dead_on_unwind nonnull writable sret(%class.bst) align 8 %3, ptr noundef %11)
  call void @llvm.lifetime.start.p0(i64 32, ptr nonnull %4) #3
  %12 = getelementptr inbounds i8, ptr %1, i64 16
  %13 = load ptr, ptr %12, align 8, !tbaa !16
  call void @_Z3BstP4Node(ptr dead_on_unwind nonnull writable sret(%class.bst) align 8 %4, ptr noundef %13)
  call void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28) %0) #3
  %14 = getelementptr inbounds i8, ptr %3, i64 4
  %15 = getelementptr inbounds i8, ptr %4, i64 4
  %16 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %14, ptr noundef nonnull align 4 dereferenceable(4) %15)
  %17 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %16)
  %18 = load i32, ptr %17, align 4, !tbaa !17
  %19 = getelementptr inbounds i8, ptr %0, i64 4
  store i32 %18, ptr %19, align 4, !tbaa !12
  %20 = getelementptr inbounds i8, ptr %3, i64 8
  %21 = getelementptr inbounds i8, ptr %4, i64 8
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(4) %21)
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %22)
  %24 = load i32, ptr %23, align 4, !tbaa !17
  %25 = getelementptr inbounds i8, ptr %0, i64 8
  store i32 %24, ptr %25, align 8, !tbaa !13
  %26 = load i8, ptr %3, align 8, !tbaa !5, !range !18, !noundef !19
  %27 = trunc nuw i8 %26 to i1
  br i1 %27, label %28, label %38

28:                                               ; preds = %9
  %29 = load i8, ptr %4, align 8, !tbaa !5, !range !18, !noundef !19
  %30 = trunc nuw i8 %29 to i1
  br i1 %30, label %31, label %38

31:                                               ; preds = %28
  %32 = load i32, ptr %14, align 4, !tbaa !12
  %33 = load i32, ptr %1, align 8, !tbaa !20
  %34 = icmp slt i32 %32, %33
  %35 = load i32, ptr %21, align 8
  %36 = icmp sgt i32 %35, %33
  %or.cond = select i1 %34, i1 %36, i1 false
  br i1 %or.cond, label %37, label %38

37:                                               ; preds = %31
  store i8 1, ptr %0, align 8, !tbaa !5
  br label %38

38:                                               ; preds = %37, %31, %28, %9
  %39 = load i8, ptr %0, align 8, !tbaa !5, !range !18, !noundef !19
  %40 = trunc nuw i8 %39 to i1
  br i1 %40, label %41, label %50

41:                                               ; preds = %38
  %42 = getelementptr inbounds i8, ptr %0, i64 16
  store ptr %1, ptr %42, align 8, !tbaa !21
  %43 = getelementptr inbounds i8, ptr %3, i64 24
  %44 = load i32, ptr %43, align 8, !tbaa !22
  %45 = getelementptr inbounds i8, ptr %4, i64 24
  %46 = load i32, ptr %45, align 8, !tbaa !22
  %47 = add i32 %44, 1
  %48 = add i32 %47, %46
  %49 = getelementptr inbounds i8, ptr %0, i64 24
  store i32 %48, ptr %49, align 8, !tbaa !22
  br label %64

50:                                               ; preds = %38
  %51 = getelementptr inbounds i8, ptr %3, i64 24
  %52 = load i32, ptr %51, align 8, !tbaa !22
  %53 = getelementptr inbounds i8, ptr %4, i64 24
  %54 = load i32, ptr %53, align 8, !tbaa !22
  %55 = icmp sgt i32 %52, %54
  %56 = getelementptr inbounds i8, ptr %0, i64 16
  %57 = getelementptr inbounds i8, ptr %0, i64 24
  br i1 %55, label %58, label %61

58:                                               ; preds = %50
  %59 = getelementptr inbounds i8, ptr %3, i64 16
  %60 = load ptr, ptr %59, align 8, !tbaa !21
  store ptr %60, ptr %56, align 8, !tbaa !21
  store i32 %52, ptr %57, align 8, !tbaa !22
  br label %64

61:                                               ; preds = %50
  %62 = getelementptr inbounds i8, ptr %4, i64 16
  %63 = load ptr, ptr %62, align 8, !tbaa !21
  store ptr %63, ptr %56, align 8, !tbaa !21
  store i32 %54, ptr %57, align 8, !tbaa !22
  br label %64

64:                                               ; preds = %58, %61, %41
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %4) #3
  call void @llvm.lifetime.end.p0(i64 32, ptr nonnull %3) #3
  br label %65

65:                                               ; preds = %64, %6
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_ZN3bstC2Ev(ptr noundef nonnull align 8 dereferenceable(28)) unnamed_addr #2 align 2

; 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 #2

; 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 #2

attributes #0 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 = { 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 #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, !7, i64 0}
!6 = !{!"_ZTS3bst", !7, i64 0, !10, i64 4, !10, i64 8, !11, i64 16, !10, i64 24}
!7 = !{!"bool", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"int", !8, i64 0}
!11 = !{!"any pointer", !8, i64 0}
!12 = !{!6, !10, i64 4}
!13 = !{!6, !10, i64 8}
!14 = !{!15, !11, i64 8}
!15 = !{!"_ZTS4Node", !10, i64 0, !11, i64 8, !11, i64 16}
!16 = !{!15, !11, i64 16}
!17 = !{!10, !10, i64 0}
!18 = !{i8 0, i8 2}
!19 = !{}
!20 = !{!15, !10, i64 0}
!21 = !{!6, !11, i64 16}
!22 = !{!6, !10, i64 24}


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