; LLVM IR from hanzohasashi33/Competetive_programming :: Geeks4Geeks/BST/Sum_Of_Leaf_Nodes.ll (Z14sumOfLeafNodesP4Node)

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

%struct.Node = type { i32, ptr, ptr }

; Function Attrs: mustprogress uwtable
define dso_local noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  store ptr %0, ptr %3, align 8, !tbaa !5
  %4 = load ptr, ptr %3, align 8, !tbaa !5
  %5 = icmp ne ptr %4, null
  br i1 %5, label %7, label %6

6:                                                ; preds = %1
  store i32 0, ptr %2, align 4
  br label %31

7:                                                ; preds = %1
  %8 = load ptr, ptr %3, align 8, !tbaa !5
  %9 = getelementptr inbounds %struct.Node, ptr %8, i32 0, i32 2
  %10 = load ptr, ptr %9, align 8, !tbaa !9
  %11 = icmp ne ptr %10, null
  br i1 %11, label %21, label %12

12:                                               ; preds = %7
  %13 = load ptr, ptr %3, align 8, !tbaa !5
  %14 = getelementptr inbounds %struct.Node, ptr %13, i32 0, i32 1
  %15 = load ptr, ptr %14, align 8, !tbaa !12
  %16 = icmp ne ptr %15, null
  br i1 %16, label %21, label %17

17:                                               ; preds = %12
  %18 = load ptr, ptr %3, align 8, !tbaa !5
  %19 = getelementptr inbounds %struct.Node, ptr %18, i32 0, i32 0
  %20 = load i32, ptr %19, align 8, !tbaa !13
  store i32 %20, ptr %2, align 4
  br label %31

21:                                               ; preds = %12, %7
  %22 = load ptr, ptr %3, align 8, !tbaa !5
  %23 = getelementptr inbounds %struct.Node, ptr %22, i32 0, i32 1
  %24 = load ptr, ptr %23, align 8, !tbaa !12
  %25 = call noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef %24)
  %26 = load ptr, ptr %3, align 8, !tbaa !5
  %27 = getelementptr inbounds %struct.Node, ptr %26, i32 0, i32 2
  %28 = load ptr, ptr %27, align 8, !tbaa !9
  %29 = call noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef %28)
  %30 = add nsw i32 %25, %29
  store i32 %30, ptr %2, align 4
  br label %31

31:                                               ; preds = %21, %17, %6
  %32 = load i32, ptr %2, align 4
  ret i32 %32
}

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

!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, !6, i64 16}
!10 = !{!"_ZTS4Node", !11, i64 0, !6, i64 8, !6, i64 16}
!11 = !{!"int", !7, i64 0}
!12 = !{!10, !6, i64 8}
!13 = !{!10, !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"

; Function Attrs: mustprogress nofree nosync nounwind willreturn memory(read, inaccessiblemem: none) uwtable
define dso_local noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef readonly %0) local_unnamed_addr #0 {
  %.not12 = icmp eq ptr %0, null
  br i1 %.not12, label %.loopexit, label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %1
  %2 = getelementptr inbounds i8, ptr %0, i64 16
  %3 = load ptr, ptr %2, align 8, !tbaa !5
  %.not717 = icmp eq ptr %3, null
  br i1 %.not717, label %.lr.ph._crit_edge, label %tailrecurse

.lr.ph._crit_edge:                                ; preds = %tailrecurse, %.lr.ph.preheader
  %.tr14.lcssa = phi ptr [ %0, %.lr.ph.preheader ], [ %8, %tailrecurse ]
  %accumulator.tr13.lcssa = phi i32 [ 0, %.lr.ph.preheader ], [ %10, %tailrecurse ]
  %4 = getelementptr inbounds i8, ptr %.tr14.lcssa, i64 8
  %5 = load ptr, ptr %4, align 8, !tbaa !11
  %.not8 = icmp eq ptr %5, null
  br i1 %.not8, label %6, label %.loopexit.loopexit

6:                                                ; preds = %.lr.ph._crit_edge
  %7 = load i32, ptr %.tr14.lcssa, align 8, !tbaa !12
  br label %.loopexit

tailrecurse:                                      ; preds = %.lr.ph.preheader, %tailrecurse
  %8 = phi ptr [ %12, %tailrecurse ], [ %3, %.lr.ph.preheader ]
  %accumulator.tr1319 = phi i32 [ %10, %tailrecurse ], [ 0, %.lr.ph.preheader ]
  %.tr1418 = phi ptr [ %8, %tailrecurse ], [ %0, %.lr.ph.preheader ]
  %.phi.trans.insert = getelementptr inbounds i8, ptr %.tr1418, i64 8
  %.pre = load ptr, ptr %.phi.trans.insert, align 8, !tbaa !11
  %9 = tail call noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef %.pre)
  %10 = add nsw i32 %9, %accumulator.tr1319
  %11 = getelementptr inbounds i8, ptr %8, i64 16
  %12 = load ptr, ptr %11, align 8, !tbaa !5
  %.not7 = icmp eq ptr %12, null
  br i1 %.not7, label %.lr.ph._crit_edge, label %tailrecurse

.loopexit.loopexit:                               ; preds = %.lr.ph._crit_edge
  %13 = tail call noundef i32 @_Z14sumOfLeafNodesP4Node(ptr noundef nonnull %5)
  %14 = add nsw i32 %13, %accumulator.tr13.lcssa
  br label %.loopexit

.loopexit:                                        ; preds = %.loopexit.loopexit, %1, %6
  %accumulator.tr11 = phi i32 [ %accumulator.tr13.lcssa, %6 ], [ 0, %1 ], [ %14, %.loopexit.loopexit ]
  %.0 = phi i32 [ %7, %6 ], [ 0, %1 ], [ 0, %.loopexit.loopexit ]
  %accumulator.ret.tr = add nsw i32 %.0, %accumulator.tr11
  ret i32 %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, !10, i64 16}
!6 = !{!"_ZTS4Node", !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, !7, i64 0}


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