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

; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%struct.TreeNode = type { [3 x i32], ptr, ptr, ptr, ptr, ptr, i32 }

@root = external dso_local global ptr, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z7newNodei(i32 noundef) #1

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z10isOverflowP8TreeNode(ptr noundef) #3

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11fixOverflowP8TreeNode(ptr noundef) #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6inserti(i32 noundef %0) #1 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca ptr, align 8
  store i32 %0, ptr %2, align 4, !tbaa !5
  %5 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.3)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  store ptr null, ptr %3, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %6 = load ptr, ptr @root, align 8, !tbaa !9
  store ptr %6, ptr %4, align 8, !tbaa !9
  br label %7

7:                                                ; preds = %36, %1
  %8 = load ptr, ptr %4, align 8, !tbaa !9
  %9 = icmp ne ptr %8, null
  br i1 %9, label %10, label %37

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

18:                                               ; preds = %10
  %19 = load ptr, ptr %4, align 8, !tbaa !9
  %20 = getelementptr inbounds %struct.TreeNode, ptr %19, i32 0, i32 1
  %21 = load ptr, ptr %20, align 8, !tbaa !11
  store ptr %21, ptr %4, align 8, !tbaa !9
  br label %36

22:                                               ; preds = %10
  %23 = load ptr, ptr %4, align 8, !tbaa !9
  %24 = getelementptr inbounds %struct.TreeNode, ptr %23, i32 0, i32 6
  %25 = load i32, ptr %24, align 8, !tbaa !13
  %26 = icmp eq i32 %25, 1
  br i1 %26, label %27, label %31

27:                                               ; preds = %22
  %28 = load ptr, ptr %4, align 8, !tbaa !9
  %29 = getelementptr inbounds %struct.TreeNode, ptr %28, i32 0, i32 2
  %30 = load ptr, ptr %29, align 8, !tbaa !14
  store ptr %30, ptr %4, align 8, !tbaa !9
  br label %35

31:                                               ; preds = %22
  %32 = load ptr, ptr %4, align 8, !tbaa !9
  %33 = getelementptr inbounds %struct.TreeNode, ptr %32, i32 0, i32 3
  %34 = load ptr, ptr %33, align 8, !tbaa !15
  store ptr %34, ptr %4, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %31, %27
  br label %36

36:                                               ; preds = %35, %18
  br label %7, !llvm.loop !16

37:                                               ; preds = %7
  %38 = load ptr, ptr %3, align 8, !tbaa !9
  %39 = icmp ne ptr %38, null
  br i1 %39, label %44, label %40

40:                                               ; preds = %37
  %41 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.4)
  %42 = load i32, ptr %2, align 4, !tbaa !5
  %43 = call noundef ptr @_Z7newNodei(i32 noundef %42)
  store ptr %43, ptr @root, align 8, !tbaa !9
  br label %112

44:                                               ; preds = %37
  %45 = load i32, ptr %2, align 4, !tbaa !5
  %46 = load ptr, ptr %3, align 8, !tbaa !9
  %47 = getelementptr inbounds %struct.TreeNode, ptr %46, i32 0, i32 0
  %48 = getelementptr inbounds [3 x i32], ptr %47, i64 0, i64 0
  %49 = load i32, ptr %48, align 8, !tbaa !5
  %50 = icmp slt i32 %45, %49
  br i1 %50, label %51, label %70

51:                                               ; preds = %44
  %52 = load ptr, ptr %3, align 8, !tbaa !9
  %53 = getelementptr inbounds %struct.TreeNode, ptr %52, i32 0, i32 0
  %54 = getelementptr inbounds [3 x i32], ptr %53, i64 0, i64 1
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = load ptr, ptr %3, align 8, !tbaa !9
  %57 = getelementptr inbounds %struct.TreeNode, ptr %56, i32 0, i32 0
  %58 = getelementptr inbounds [3 x i32], ptr %57, i64 0, i64 2
  store i32 %55, ptr %58, align 8, !tbaa !5
  %59 = load ptr, ptr %3, align 8, !tbaa !9
  %60 = getelementptr inbounds %struct.TreeNode, ptr %59, i32 0, i32 0
  %61 = getelementptr inbounds [3 x i32], ptr %60, i64 0, i64 0
  %62 = load i32, ptr %61, align 8, !tbaa !5
  %63 = load ptr, ptr %3, align 8, !tbaa !9
  %64 = getelementptr inbounds %struct.TreeNode, ptr %63, i32 0, i32 0
  %65 = getelementptr inbounds [3 x i32], ptr %64, i64 0, i64 1
  store i32 %62, ptr %65, align 4, !tbaa !5
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = load ptr, ptr %3, align 8, !tbaa !9
  %68 = getelementptr inbounds %struct.TreeNode, ptr %67, i32 0, i32 0
  %69 = getelementptr inbounds [3 x i32], ptr %68, i64 0, i64 0
  store i32 %66, ptr %69, align 8, !tbaa !5
  br label %102

70:                                               ; preds = %44
  %71 = load i32, ptr %2, align 4, !tbaa !5
  %72 = load ptr, ptr %3, align 8, !tbaa !9
  %73 = getelementptr inbounds %struct.TreeNode, ptr %72, i32 0, i32 0
  %74 = getelementptr inbounds [3 x i32], ptr %73, i64 0, i64 0
  %75 = load i32, ptr %74, align 8, !tbaa !5
  %76 = icmp sgt i32 %71, %75
  br i1 %76, label %77, label %96

77:                                               ; preds = %70
  %78 = load i32, ptr %2, align 4, !tbaa !5
  %79 = load ptr, ptr %3, align 8, !tbaa !9
  %80 = getelementptr inbounds %struct.TreeNode, ptr %79, i32 0, i32 0
  %81 = getelementptr inbounds [3 x i32], ptr %80, i64 0, i64 1
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = icmp slt i32 %78, %82
  br i1 %83, label %84, label %96

84:                                               ; preds = %77
  %85 = load ptr, ptr %3, align 8, !tbaa !9
  %86 = getelementptr inbounds %struct.TreeNode, ptr %85, i32 0, i32 0
  %87 = getelementptr inbounds [3 x i32], ptr %86, i64 0, i64 1
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = load ptr, ptr %3, align 8, !tbaa !9
  %90 = getelementptr inbounds %struct.TreeNode, ptr %89, i32 0, i32 0
  %91 = getelementptr inbounds [3 x i32], ptr %90, i64 0, i64 2
  store i32 %88, ptr %91, align 8, !tbaa !5
  %92 = load i32, ptr %2, align 4, !tbaa !5
  %93 = load ptr, ptr %3, align 8, !tbaa !9
  %94 = getelementptr inbounds %struct.TreeNode, ptr %93, i32 0, i32 0
  %95 = getelementptr inbounds [3 x i32], ptr %94, i64 0, i64 1
  store i32 %92, ptr %95, align 4, !tbaa !5
  br label %101

96:                                               ; preds = %77, %70
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = load ptr, ptr %3, align 8, !tbaa !9
  %99 = getelementptr inbounds %struct.TreeNode, ptr %98, i32 0, i32 0
  %100 = getelementptr inbounds [3 x i32], ptr %99, i64 0, i64 2
  store i32 %97, ptr %100, align 8, !tbaa !5
  br label %101

101:                                              ; preds = %96, %84
  br label %102

102:                                              ; preds = %101, %51
  %103 = load ptr, ptr %3, align 8, !tbaa !9
  %104 = getelementptr inbounds %struct.TreeNode, ptr %103, i32 0, i32 6
  %105 = load i32, ptr %104, align 8, !tbaa !13
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %104, align 8, !tbaa !13
  %107 = load ptr, ptr %3, align 8, !tbaa !9
  %108 = call noundef zeroext i1 @_Z10isOverflowP8TreeNode(ptr noundef %107)
  br i1 %108, label %109, label %111

109:                                              ; preds = %102
  %110 = load ptr, ptr %3, align 8, !tbaa !9
  call void @_Z11fixOverflowP8TreeNode(ptr noundef %110)
  br label %111

111:                                              ; preds = %109, %102
  br label %112

112:                                              ; preds = %111, %40
  %113 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.5)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  ret void
}

attributes #0 = { inlinehint 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 #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #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 = !{!"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}
!11 = !{!12, !10, i64 16}
!12 = !{!"_ZTS8TreeNode", !7, i64 0, !10, i64 16, !10, i64 24, !10, i64 32, !10, i64 40, !10, i64 48, !6, i64 56}
!13 = !{!12, !6, i64 56}
!14 = !{!12, !10, i64 24}
!15 = !{!12, !10, i64 32}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}


; 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.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }

@root = external dso_local local_unnamed_addr global ptr, align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8
@.str.3 = external hidden unnamed_addr constant [14 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [4 x i8], align 1
@.str.5 = external hidden unnamed_addr constant [12 x i8], align 1

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress uwtable
declare dso_local noundef ptr @_Z7newNodei(i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z10isOverflowP8TreeNode(ptr noundef) local_unnamed_addr #2

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z11fixOverflowP8TreeNode(ptr noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
define dso_local void @_Z6inserti(i32 noundef %0) local_unnamed_addr #1 {
  %2 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.3)
  %.036 = load ptr, ptr @root, align 8, !tbaa !5
  %.not37 = icmp eq ptr %.036, null
  br i1 %.not37, label %11, label %.lr.ph

.lr.ph:                                           ; preds = %1, %9
  %.038 = phi ptr [ %.0, %9 ], [ %.036, %1 ]
  %3 = load i32, ptr %.038, align 8, !tbaa !9
  %4 = icmp sgt i32 %3, %0
  br i1 %4, label %9, label %5

5:                                                ; preds = %.lr.ph
  %6 = getelementptr inbounds i8, ptr %.038, i64 56
  %7 = load i32, ptr %6, align 8, !tbaa !11
  %8 = icmp eq i32 %7, 1
  %. = select i1 %8, i64 24, i64 32
  br label %9

9:                                                ; preds = %5, %.lr.ph
  %.sink = phi i64 [ 16, %.lr.ph ], [ %., %5 ]
  %10 = getelementptr inbounds i8, ptr %.038, i64 %.sink
  %.0 = load ptr, ptr %10, align 8, !tbaa !5
  %.not = icmp eq ptr %.0, null
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

11:                                               ; preds = %1
  %12 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.4)
  %13 = tail call noundef ptr @_Z7newNodei(i32 noundef %0)
  store ptr %13, ptr @root, align 8, !tbaa !5
  br label %36

._crit_edge:                                      ; preds = %9
  %14 = load i32, ptr %.038, align 8, !tbaa !9
  %15 = icmp sgt i32 %14, %0
  br i1 %15, label %16, label %20

16:                                               ; preds = %._crit_edge
  %17 = getelementptr inbounds i8, ptr %.038, i64 4
  %18 = load i32, ptr %17, align 4, !tbaa !9
  %19 = getelementptr inbounds i8, ptr %.038, i64 8
  store i32 %18, ptr %19, align 8, !tbaa !9
  store i32 %14, ptr %17, align 4, !tbaa !9
  store i32 %0, ptr %.038, align 8, !tbaa !9
  br label %30

20:                                               ; preds = %._crit_edge
  %21 = icmp slt i32 %14, %0
  br i1 %21, label %22, label %28

22:                                               ; preds = %20
  %23 = getelementptr inbounds i8, ptr %.038, i64 4
  %24 = load i32, ptr %23, align 4, !tbaa !9
  %25 = icmp sgt i32 %24, %0
  br i1 %25, label %26, label %28

26:                                               ; preds = %22
  %27 = getelementptr inbounds i8, ptr %.038, i64 8
  store i32 %24, ptr %27, align 8, !tbaa !9
  store i32 %0, ptr %23, align 4, !tbaa !9
  br label %30

28:                                               ; preds = %22, %20
  %29 = getelementptr inbounds i8, ptr %.038, i64 8
  store i32 %0, ptr %29, align 8, !tbaa !9
  br label %30

30:                                               ; preds = %26, %28, %16
  %31 = getelementptr inbounds i8, ptr %.038, i64 56
  %32 = load i32, ptr %31, align 8, !tbaa !11
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 8, !tbaa !11
  %34 = tail call noundef zeroext i1 @_Z10isOverflowP8TreeNode(ptr noundef nonnull %.038)
  br i1 %34, label %35, label %36

35:                                               ; preds = %30
  tail call void @_Z11fixOverflowP8TreeNode(ptr noundef nonnull %.038)
  br label %36

36:                                               ; preds = %30, %35, %11
  %37 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.5)
  ret void
}

attributes #0 = { inlinehint 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 #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 = { 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" }

!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 56}
!12 = !{!"_ZTS8TreeNode", !7, i64 0, !6, i64 16, !6, i64 24, !6, i64 32, !6, i64 40, !6, i64 48, !10, i64 56}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass