; LLVM IR from edualgo/dsa-code-store :: Generic-Tree/Generic-Tree-master/TreeSource/main.ll (Z10maxSumNodeP8TreeNodeIiE)

; 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.TreeNode = type { i32, %"class.std::vector" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<TreeNode<int> *, std::allocator<TreeNode<int> *>>::_Vector_impl" }
%"struct.std::_Vector_base<TreeNode<int> *, std::allocator<TreeNode<int> *>>::_Vector_impl" = type { %"struct.std::_Vector_base<TreeNode<int> *, std::allocator<TreeNode<int> *>>::_Vector_impl_data" }
%"struct.std::_Vector_base<TreeNode<int> *, std::allocator<TreeNode<int> *>>::_Vector_impl_data" = type { ptr, 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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #1 align 2

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

14:                                               ; preds = %1
  store ptr null, ptr %2, align 8
  br label %97

15:                                               ; preds = %1
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #3
  %16 = load ptr, ptr %3, align 8, !tbaa !5
  store ptr %16, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #3
  %17 = load ptr, ptr %3, align 8, !tbaa !5
  %18 = getelementptr inbounds %class.TreeNode, ptr %17, i32 0, i32 0
  %19 = load i32, ptr %18, align 8, !tbaa !9
  store i32 %19, ptr %5, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  store i32 0, ptr %6, align 4, !tbaa !16
  br label %20

20:                                               ; preds = %39, %15
  %21 = load i32, ptr %6, align 4, !tbaa !16
  %22 = sext i32 %21 to i64
  %23 = load ptr, ptr %3, align 8, !tbaa !5
  %24 = getelementptr inbounds %class.TreeNode, ptr %23, i32 0, i32 1
  %25 = call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %24) #3
  %26 = icmp ult i64 %22, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %20
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  br label %42

28:                                               ; preds = %20
  %29 = load ptr, ptr %3, align 8, !tbaa !5
  %30 = getelementptr inbounds %class.TreeNode, ptr %29, i32 0, i32 1
  %31 = load i32, ptr %6, align 4, !tbaa !16
  %32 = sext i32 %31 to i64
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %30, i64 noundef %32) #3
  %34 = load ptr, ptr %33, align 8, !tbaa !5
  %35 = getelementptr inbounds %class.TreeNode, ptr %34, i32 0, i32 0
  %36 = load i32, ptr %35, align 8, !tbaa !9
  %37 = load i32, ptr %5, align 4, !tbaa !16
  %38 = add nsw i32 %37, %36
  store i32 %38, ptr %5, align 4, !tbaa !16
  br label %39

39:                                               ; preds = %28
  %40 = load i32, ptr %6, align 4, !tbaa !16
  %41 = add nsw i32 %40, 1
  store i32 %41, ptr %6, align 4, !tbaa !16
  br label %20, !llvm.loop !17

42:                                               ; preds = %27
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 0, ptr %7, align 4, !tbaa !16
  br label %43

43:                                               ; preds = %92, %42
  %44 = load i32, ptr %7, align 4, !tbaa !16
  %45 = sext i32 %44 to i64
  %46 = load ptr, ptr %3, align 8, !tbaa !5
  %47 = getelementptr inbounds %class.TreeNode, ptr %46, i32 0, i32 1
  %48 = call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %47) #3
  %49 = icmp ult i64 %45, %48
  br i1 %49, label %51, label %50

50:                                               ; preds = %43
  store i32 5, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  br label %95

51:                                               ; preds = %43
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #3
  %52 = load ptr, ptr %3, align 8, !tbaa !5
  %53 = getelementptr inbounds %class.TreeNode, ptr %52, i32 0, i32 1
  %54 = load i32, ptr %7, align 4, !tbaa !16
  %55 = sext i32 %54 to i64
  %56 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %53, i64 noundef %55) #3
  %57 = load ptr, ptr %56, align 8, !tbaa !5
  %58 = call noundef ptr @_Z10maxSumNodeP8TreeNodeIiE(ptr noundef %57)
  store ptr %58, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #3
  %59 = load ptr, ptr %9, align 8, !tbaa !5
  %60 = getelementptr inbounds %class.TreeNode, ptr %59, i32 0, i32 0
  %61 = load i32, ptr %60, align 8, !tbaa !9
  store i32 %61, ptr %10, align 4, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #3
  store i32 0, ptr %11, align 4, !tbaa !16
  br label %62

62:                                               ; preds = %81, %51
  %63 = load i32, ptr %11, align 4, !tbaa !16
  %64 = sext i32 %63 to i64
  %65 = load ptr, ptr %9, align 8, !tbaa !5
  %66 = getelementptr inbounds %class.TreeNode, ptr %65, i32 0, i32 1
  %67 = call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %66) #3
  %68 = icmp ult i64 %64, %67
  br i1 %68, label %70, label %69

69:                                               ; preds = %62
  store i32 8, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #3
  br label %84

70:                                               ; preds = %62
  %71 = load ptr, ptr %9, align 8, !tbaa !5
  %72 = getelementptr inbounds %class.TreeNode, ptr %71, i32 0, i32 1
  %73 = load i32, ptr %11, align 4, !tbaa !16
  %74 = sext i32 %73 to i64
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %72, i64 noundef %74) #3
  %76 = load ptr, ptr %75, align 8, !tbaa !5
  %77 = getelementptr inbounds %class.TreeNode, ptr %76, i32 0, i32 0
  %78 = load i32, ptr %77, align 8, !tbaa !9
  %79 = load i32, ptr %10, align 4, !tbaa !16
  %80 = add nsw i32 %79, %78
  store i32 %80, ptr %10, align 4, !tbaa !16
  br label %81

81:                                               ; preds = %70
  %82 = load i32, ptr %11, align 4, !tbaa !16
  %83 = add nsw i32 %82, 1
  store i32 %83, ptr %11, align 4, !tbaa !16
  br label %62, !llvm.loop !19

84:                                               ; preds = %69
  %85 = load i32, ptr %10, align 4, !tbaa !16
  %86 = load i32, ptr %5, align 4, !tbaa !16
  %87 = icmp sgt i32 %85, %86
  br i1 %87, label %88, label %91

88:                                               ; preds = %84
  %89 = load i32, ptr %10, align 4, !tbaa !16
  store i32 %89, ptr %5, align 4, !tbaa !16
  %90 = load ptr, ptr %9, align 8, !tbaa !5
  store ptr %90, ptr %4, align 8, !tbaa !5
  br label %91

91:                                               ; preds = %88, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #3
  br label %92

92:                                               ; preds = %91
  %93 = load i32, ptr %7, align 4, !tbaa !16
  %94 = add nsw i32 %93, 1
  store i32 %94, ptr %7, align 4, !tbaa !16
  br label %43, !llvm.loop !20

95:                                               ; preds = %50
  %96 = load ptr, ptr %4, align 8, !tbaa !5
  store ptr %96, ptr %2, align 8
  store i32 1, ptr %8, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #3
  br label %97

97:                                               ; preds = %95, %14
  %98 = load ptr, ptr %2, align 8
  ret ptr %98
}

attributes #0 = { 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 = { 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 = { 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 = !{!"_ZTS8TreeNodeIiE", !11, i64 0, !12, i64 8}
!11 = !{!"int", !7, i64 0}
!12 = !{!"_ZTSSt6vectorIP8TreeNodeIiESaIS2_EE", !13, i64 0}
!13 = !{!"_ZTSSt12_Vector_baseIP8TreeNodeIiESaIS2_EE", !14, i64 0}
!14 = !{!"_ZTSNSt12_Vector_baseIP8TreeNodeIiESaIS2_EE12_Vector_implE", !15, i64 0}
!15 = !{!"_ZTSNSt12_Vector_baseIP8TreeNodeIiESaIS2_EE17_Vector_impl_dataE", !6, i64 0, !6, i64 8, !6, i64 16}
!16 = !{!11, !11, i64 0}
!17 = distinct !{!17, !18}
!18 = !{!"llvm.loop.mustprogress"}
!19 = distinct !{!19, !18}
!20 = distinct !{!20, !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 nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
define dso_local noundef ptr @_Z10maxSumNodeP8TreeNodeIiE(ptr noundef %0) local_unnamed_addr #0 {
  %2 = icmp eq ptr %0, null
  br i1 %2, label %.loopexit, label %3

3:                                                ; preds = %1
  %4 = load i32, ptr %0, align 8, !tbaa !5
  %5 = getelementptr inbounds i8, ptr %0, i64 8
  %6 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %.not = icmp eq i64 %6, 0
  br i1 %.not, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %3
  %.030.lcssa = phi i32 [ %4, %3 ], [ %11, %.lr.ph ]
  %7 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %.not50 = icmp eq i64 %7, 0
  br i1 %.not50, label %.loopexit, label %.lr.ph48

.lr.ph:                                           ; preds = %3, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %3 ]
  %.03038 = phi i32 [ %11, %.lr.ph ], [ %4, %3 ]
  %8 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv) #2
  %9 = load ptr, ptr %8, align 8, !tbaa !15
  %10 = load i32, ptr %9, align 8, !tbaa !5
  %11 = add nsw i32 %10, %.03038
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %13 = icmp ugt i64 %12, %indvars.iv.next
  br i1 %13, label %.lr.ph, label %.preheader, !llvm.loop !16

.lr.ph48:                                         ; preds = %.preheader, %._crit_edge
  %indvars.iv57 = phi i64 [ %indvars.iv.next58, %._crit_edge ], [ 0, %.preheader ]
  %.146 = phi i32 [ %spec.select37, %._crit_edge ], [ %.030.lcssa, %.preheader ]
  %.03145 = phi ptr [ %spec.select, %._crit_edge ], [ %0, %.preheader ]
  %14 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %5, i64 noundef %indvars.iv57) #2
  %15 = load ptr, ptr %14, align 8, !tbaa !15
  %16 = tail call noundef ptr @_Z10maxSumNodeP8TreeNodeIiE(ptr noundef %15)
  %17 = load i32, ptr %16, align 8, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %16, i64 8
  %19 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #2
  %.not51 = icmp eq i64 %19, 0
  br i1 %.not51, label %._crit_edge, label %.lr.ph43

._crit_edge:                                      ; preds = %.lr.ph43, %.lr.ph48
  %.026.lcssa = phi i32 [ %17, %.lr.ph48 ], [ %26, %.lr.ph43 ]
  %20 = icmp sgt i32 %.026.lcssa, %.146
  %spec.select = select i1 %20, ptr %16, ptr %.03145
  %spec.select37 = tail call i32 @llvm.smax.i32(i32 %.026.lcssa, i32 %.146)
  %indvars.iv.next58 = add nuw nsw i64 %indvars.iv57, 1
  %21 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %5) #2
  %22 = icmp ugt i64 %21, %indvars.iv.next58
  br i1 %22, label %.lr.ph48, label %.loopexit, !llvm.loop !18

.lr.ph43:                                         ; preds = %.lr.ph48, %.lr.ph43
  %indvars.iv54 = phi i64 [ %indvars.iv.next55, %.lr.ph43 ], [ 0, %.lr.ph48 ]
  %.02641 = phi i32 [ %26, %.lr.ph43 ], [ %17, %.lr.ph48 ]
  %23 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSt6vectorIP8TreeNodeIiESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %18, i64 noundef %indvars.iv54) #2
  %24 = load ptr, ptr %23, align 8, !tbaa !15
  %25 = load i32, ptr %24, align 8, !tbaa !5
  %26 = add nsw i32 %25, %.02641
  %indvars.iv.next55 = add nuw nsw i64 %indvars.iv54, 1
  %27 = tail call noundef i64 @_ZNKSt6vectorIP8TreeNodeIiESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %18) #2
  %28 = icmp ugt i64 %27, %indvars.iv.next55
  br i1 %28, label %.lr.ph43, label %._crit_edge, !llvm.loop !19

.loopexit:                                        ; preds = %._crit_edge, %.preheader, %1
  %.027 = phi ptr [ null, %1 ], [ %0, %.preheader ], [ %spec.select, %._crit_edge ]
  ret ptr %.027
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #1

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !7, i64 0}
!6 = !{!"_ZTS8TreeNodeIiE", !7, i64 0, !10, i64 8}
!7 = !{!"int", !8, i64 0}
!8 = !{!"omnipotent char", !9, i64 0}
!9 = !{!"Simple C++ TBAA"}
!10 = !{!"_ZTSSt6vectorIP8TreeNodeIiESaIS2_EE", !11, i64 0}
!11 = !{!"_ZTSSt12_Vector_baseIP8TreeNodeIiESaIS2_EE", !12, i64 0}
!12 = !{!"_ZTSNSt12_Vector_baseIP8TreeNodeIiESaIS2_EE12_Vector_implE", !13, i64 0}
!13 = !{!"_ZTSNSt12_Vector_baseIP8TreeNodeIiESaIS2_EE17_Vector_impl_dataE", !14, i64 0, !14, i64 8, !14, i64 16}
!14 = !{!"any pointer", !8, i64 0}
!15 = !{!14, !14, i64 0}
!16 = distinct !{!16, !17}
!17 = !{!"llvm.loop.mustprogress"}
!18 = distinct !{!18, !17}
!19 = distinct !{!19, !17}


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